From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EBB163858403; Sat, 13 Nov 2021 11:07:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBB163858403 From: "hubicka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu Date: Sat, 13 Nov 2021 11:07:20 +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: hubicka 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: bug_status everconfirmed cc cf_reconfirmed_on 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: Sat, 13 Nov 2021 11:07:21 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103222 Jan Hubicka changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 CC| |aldyh at gcc dot gnu.org, | |hubicka at gcc dot gnu.org Last reconfirmed| |2021-11-13 --- Comment #1 from Jan Hubicka --- So with -O1 we get: int main () { int16_t a_lsm.11; int _2; unsigned short a.5_4; unsigned short _11; short int _12; [local count: 1073741835]: a_lsm.11_16 =3D a; a.5_4 =3D (unsigned short) a_lsm.11_16; _11 =3D a.5_4 + 2; _12 =3D (short int) _11; a =3D _12; _2 =3D (int) _12; printf ("%d\n", _2); return 0; } while with -O2 we get: int main () { int _2; short int a.3_8; unsigned short a.5_9; unsigned short _10; short int _11; [local count: 1073741824]: a.3_8 =3D a; a.5_9 =3D (unsigned short) a.3_8; _10 =3D a.5_9 + 1; _11 =3D (short int) _10; a =3D _11; _2 =3D (int) _11; printf ("%d\n", _2); return 0; } Adding always_inline to func_2 makes -O1 and -O2 to agree up to ccp2 110t.mergephi2 and then 111t.threadfull makes a difference: + FAIL: path through PHI in bb3 (incoming bb:2) crosses loop +path: 2->3->xx REJECTED +Checking profitability of path (backwards): bb:3 (3 insns) bb:5 (latch) + Control statement insns: 2 + Overall: 1 insns +Checking profitability of path (backwards): bb:3 (3 insns) bb:5 (latch) + Control statement insns: 2 + Overall: 1 insns + [1] Registering jump thread: (5, 3) incoming edge; (3, 4) nocopy;=20 +path: 5->3->4 SUCCESS +Jump threading proved probability of edge 3->4 too small (it is 11.0% (guessed) should be always (guessed)) int main () { - uint32_t p3; uint32_t p2; + uint32_t p3; short int a.0_1; int _2; short int a.3_8; @@ -13,28 +72,15 @@ short int _11; [local count: 1073741824]: - - [local count: 9761289362]: - # p3_7 =3D PHI <1(2), 0(5)> - # p2_17 =3D PHI <1(2), p3_7(5)> - if (p2_17 !=3D 0) - goto ; [89.00%] - else - goto ; [11.00%] - - [local count: 1073741824]: - a.0_1 =3D a; - _2 =3D (int) a.0_1; - printf ("%d\n", _2); - return 0; - - [local count: 8687547547]: a.3_8 =3D a; a.5_9 =3D (unsigned short) a.3_8; _10 =3D a.5_9 + 1; _11 =3D (short int) _10; a =3D _11; - goto ; [100.00%] + a.0_1 =3D a; + _2 =3D (int) a.0_1; + printf ("%d\n", _2); + return 0; } and --disable-tree-threadfull1 fixes the difference.=