From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 581883858C3A; Mon, 24 Jan 2022 00:37:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 581883858C3A From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104196] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu Date: Mon, 24 Jan 2022 00:37:45 +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: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned 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: Mon, 24 Jan 2022 00:37:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104196 --- Comment #2 from Andrew Pinski --- Here is one which shows the issue just in case fold gets in the way: int a =3D 6; int main() { for (;;) { int c =3D 111; if (a < 0) c =3D -__INT_MAX__ - a; int b =3D a; if (a >=3D 0 || c > 0) b =3D 0; if (b !=3D 4096 - __INT_MAX__) { if (a < 6) __builtin_abort (); return 0; } } } The main point is the undefined behavior of -__INT_MAX__ - a when a is not = less than 0 which is not true here as a is always 6. Also for some reason using the C++ front-end also works around the issue ... (but I don't see how though).=