From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B16DB385DC05; Fri, 30 Jun 2023 09:33:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B16DB385DC05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688117589; bh=j3dTg65CvkjDXXPy7t65fRHH66/xl1ukcNA1k0uGRYs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ccpse1I9rSGZkyY/s+Svojmdu3PO/a8lT/5jokgE50u868Gn2KRpne1sYUmhrPCOb DOaVQyaiMZIK89oygGnhjF1YlIuiem/Mt/RtkRnGRVFyc7E2h/ZrlPFLts147SYrad zobMm7G+9vz9LXGeEyEox1bw3y6G+l9dRyWDHmrI= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/110495] fre introduces signed wrap for vector Date: Fri, 30 Jun 2023 09:33:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc bug_status keywords everconfirmed cf_reconfirmed_on component Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110495 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rguenth at gcc dot gnu.org, | |rsandifo at gcc dot gnu.org Status|UNCONFIRMED |NEW Keywords| |wrong-code Ever confirmed|0 |1 Last reconfirmed| |2023-06-30 Component|tree-optimization |middle-end --- Comment #1 from Richard Biener --- Applying pattern match.pd:3029, gimple-match-2.cc:1090 Applying pattern match.pd:3029, gimple-match-2.cc:1090 but that specifically checks for (if (cst && !TREE_OVERFLOW (cst)) (inner_op @0 { cst; } ) ah, but we are dealing with vectors here and the VECTOR_CST doesn't inherit TREE_OVERFLOW here. I don't think we ever actually set TREE_OVERFLOW on VECTOR_CSTs even though that's documented to be a thing. We are relying on TREE_OVERFLOW in some more patterns that are also applying to VECTOR_CST. _Complex int is probably similarly affected. diff --git a/gcc/tree-vector-builder.cc b/gcc/tree-vector-builder.cc index 0e51bcefa4f..78688ef4331 100644 --- a/gcc/tree-vector-builder.cc +++ b/gcc/tree-vector-builder.cc @@ -43,6 +43,12 @@ tree_vector_builder::build () gcc_assert (pow2p_hwi (npatterns ())); tree v =3D make_vector (exact_log2 (npatterns ()), nelts_per_pattern ()); TREE_TYPE (v) =3D m_type; + bool ovf =3D false; + for (tree elt : *this) + if (TREE_OVERFLOW (elt)) + ovf =3D true; + if (ovf) + TREE_OVERFLOW (v) =3D true; memcpy (VECTOR_CST_ENCODED_ELTS (v), address (), encoded_nelts () * sizeof (tree)); return v; fixes this and results in : _1 =3D *x_6(D); _2 =3D _1 + { 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647 }; *x_6(D) =3D _2; _9 =3D VIEW_CONVERT_EXPR(_1); _10 =3D _9 + { 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294 }; _4 =3D VIEW_CONVERT_EXPR(_10); *x_6(D) =3D _4; return; there are some more VECTOR_CST builders that would need adjustment for consistency. Maybe not relying on TREE_OVERFLOW would be a better idea here, but while for plain integers we have wide_int for vectors or complex there's no such thing ...=