From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 525333853807; Wed, 23 Feb 2022 15:25:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 525333853807 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103037] [11/12 Regression] Wrong code with -O2 since r11-6100-gd41b097350d3c5d0 Date: Wed, 23 Feb 2022 15:25:36 +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: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.3 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: Wed, 23 Feb 2022 15:25:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103037 --- Comment #8 from Richard Biener --- More reduced testcase - the min() obfuscation is to avoid recognizing a MIN_EXPR before jump threading gets the chance to disrupt it. A GIMPLE unit testcase for PRE is difficult since we are not supporting SSA annotations (ranges) at the moment. static inline const unsigned short * min(unsigned short *d, const unsigned short *e) { return *e < *d ? e : d; } unsigned short __attribute__((noipa)) test(unsigned short arr, unsigned short val) { unsigned short tem =3D 1; unsigned short tem2 =3D *min(&arr, &tem); return tem2 / (arr ? arr : val); } int main() { if (test (2, 2) !=3D 0) __builtin_abort(); return 0; } The IL for the reduced testcase before PRE is [local count: 1073741824]: if (arr_6(D) > 1) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: # RANGE [0, 1] NONZERO 1 _1 =3D (int) arr_6(D); // (A) if (arr_6(D) !=3D 0) goto ; [20.00%] else goto ; [80.00%] [local count: 536870913]: # RANGE [0, 1] NONZERO 1 # _17 =3D PHI <_1(3), 1(2)> # RANGE [1, 65535] NONZERO 65535 iftmp.0_9 =3D (int) arr_6(D); // (B)=20 goto ; [100.00%] [local count: 536870913]: # RANGE [0, 65535] NONZERO 65535 iftmp.0_8 =3D (int) val_7(D); [local count: 1073741824]: # RANGE [0, 65535] NONZERO 65535 # iftmp.0_3 =3D PHI # RANGE [0, 1] NONZERO 1 # _18 =3D PHI <_17(4), 0(5)> # RANGE [0, 1] NONZERO 1 _2 =3D _18 / iftmp.0_3; # RANGE [0, 1] NONZERO 1 _10 =3D (short unsigned int) _2; return _10; and the problematic value-numbering is iftmp.0_9 =3D _1 (0001) at (A) and (B). By design we may only use _available_ expressions during simplification but _1 is not available on the 4 -> 6 edge. That's working OK for the translation from 4 -> 6 but then we record a valueized expression into the ANTIC set of 4 which when further translated and simplified has the wrong representative inside.=