From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 259943857018; Thu, 21 Apr 2022 16:58:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 259943857018 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/105337] [12 Regression] wrong code at -Os and above on x86_64-linux-gnu Date: Thu, 21 Apr 2022 16:58:52 +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: jakub 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: cc 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: Thu, 21 Apr 2022 16:58:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105337 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rguenth at gcc dot gnu.org --- Comment #6 from Jakub Jelinek --- I'd say that ivopts is at fault here. Before that we have: [local count: 312727306]: [local count: 805306369]: # b_14 =3D PHI # c_15 =3D PHI # ivtmp_3 =3D PHI a.0_1 =3D a; if (a.0_1 =3D=3D 0) goto ; [5.50%] else goto ; [94.50%] ... [local count: 44291850]: # b_4 =3D PHI [local count: 312727306]: # b_10 =3D PHI return b_10; as the path actually taken at runtime, yes, we use uninitialized c in the P= HI, but that doesn't correspond to UB at runtime. But ivopts changes that to: [local count: 312727306]: _19 =3D (unsigned int) c_5(D); _20 =3D _19 + 4294967293; _21 =3D (int) _20; [local count: 805306369]: # c_15 =3D PHI _13 =3D (unsigned int) c_5(D); _12 =3D (unsigned int) c_15; _11 =3D -_12; _18 =3D _11 + _13; b_14 =3D (int) _18; a.0_1 =3D a; if (a.0_1 =3D=3D 0) goto ; [5.50%] else goto ; [94.50%] ... [local count: 44291850]: # b_4 =3D PHI [local count: 312727306]: # b_10 =3D PHI return b_10; and now it uses the uninitialized value in arithmetics in the actually exec= uted code. And, even the return value which gets a copy of b_14 now depends on = that uninitialized value. I think we had some other PR about this... Then comes ccp4 and figures out that many values are UNDEFINED and optimize= s it into return 3;=