From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A57683858C2C; Fri, 8 Oct 2021 06:04:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A57683858C2C From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903 Date: Fri, 08 Oct 2021 06:04:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: pinskia at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Oct 2021 06:04:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102622 --- Comment #15 from Andrew Pinski --- here is the C testcase: static inline const unsigned *max1(const unsigned *t, const unsigned *t1) { return *t > *t1 ? t : t1; } int var_20 =3D 0; int var_22 =3D 0; short arr_32 [13]; char arr_45 [69]; void test(int a, unsigned b, const long long *c) __attribute__((noipa)); void test(int a, unsigned b, const long long *c) { for (short d =3D 0; d < 13; d++) { for (int e =3D 0; e < a; e +=3D 3) var_20 =3D 0; unsigned t =3D (short)b; if (*max1(&b, &t)) { arr_32[d] =3D 0; var_22 =3D *c; } for (unsigned f =3D 0; f < 69; f +=3D 4) arr_45[f] =3D 0; } } int main() { long long t =3D 42; test(-1, 1, &t); if (var_22 !=3D 42) __builtin_abort(); return 0; } ---- CUT ----- Here is the patch which I tested and is working: diff --git a/gcc/match.pd b/gcc/match.pd index a9791ceb74a..4fd2a8c3ea9 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3950,10 +3950,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (integer_onep (@1)) (convert (convert:boolean_type_node @0))) /* a ? -1 : 0 -> -a. */ - (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)) + (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1) + && TYPE_PRECISION (type) !=3D 1) (negate (convert (convert:boolean_type_node @0)))) /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */ - (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1)) + (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1) + && TYPE_PRECISION (type) !=3D 1) (with { tree shift =3D build_int_cst (integer_type_node, tree_log2 (@1)); } @@ -3967,10 +3969,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (integer_onep (@2)) (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))) /* a ? -1 : 0 -> -(!a). */ - (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) + (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2) + && TYPE_PRECISION (type) !=3D 1) (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue;= } )))) /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ - (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)) + (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2) + && TYPE_PRECISION (type) !=3D 1) (with { tree shift =3D build_int_cst (integer_type_node, tree_log2 (@2)); }=