From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 13C813858406; Mon, 24 Jan 2022 02:00:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13C813858406 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 02:00:43 +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 02:00:44 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104196 --- Comment #4 from Andrew Pinski --- The problem looks like a latent bug in reassoc1. Before: if (a.0_1 < 0) goto ; [41.00%] else goto ; [59.00%] [local count: 440234144]: # RANGE [-2147483646, 1] c_6 =3D -2147483647 - a.0_1; _9 =3D a.0_1 !=3D -2147479551; _4 =3D c_6 =3D=3D 1; _3 =3D _4 | _9; if (_3 !=3D 0) goto ; [60.23%] else goto ; [39.77%] [local count: 118111600]: if (a.0_1 <=3D 5) goto ; [0.00%] else goto ; [100.00%] Which is correct and the overflow only happens in bb 4 which is never reach= ed here as a =3D=3D 6. After reassoc1 we have: c_6 =3D -2147483647 - a.0_1; _10 =3D a.0_1 !=3D -2147479551; _9 =3D a.0_1 !=3D -2147479551; _4 =3D c_6 =3D=3D 1; _12 =3D _4 | _10; if (_12 !=3D 0) goto ; [60.23%] else goto ; [39.77%] [local count: 118111600]: if (a.0_1 <=3D 5) goto ; [0.00%] else goto ; [100.00%] Which is totally bogus and I suspect it is because we had that range on c_6 assignment. >>From -fdump-tree-reassoc1-all: Matching expression match.pd:2080, generic-match.cc:693 Matching expression match.pd:2083, generic-match.cc:753 Matching expression match.pd:2090, generic-match.cc:776 Optimizing range tests a.0_1 +[-2147479551, -2147479551] and -[0, ] into a.0_1 =3D=3D -2147479551 Matching expression match.pd:2080, gimple-match.cc:819 Matching expression match.pd:2083, gimple-match.cc:892 Matching expression match.pd:2090, gimple-match.cc:952=