From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 446373857808; Tue, 25 Aug 2020 08:42:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 446373857808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598344947; bh=OmGuFXc4xJn+gnQZTRX7+wPoyOnaP9MAcNN/fVoWEkw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=q8H85P+nBYAbNR52+I5mEi9X3q2Yo30GGki6/TlQ2LsWdCH0h/b8ilMKzqrBUsvlb 92haETLfCDAAkvhq09ZwJD0P3IYUaXBO8Lb1Evc0JsA4UEWhPSkrQwzRuHrmTyvecI FFzKWnOUSPLLGlAAhpWoaiVr40F1i6jRUuLFNd+0= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96572] Failure to optimize out branch when it always results in UB from dereferencing a pointer to an undefined value set in there Date: Tue, 25 Aug 2020 08:42:27 +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: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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: everconfirmed keywords cf_reconfirmed_on bug_status 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: Tue, 25 Aug 2020 08:42:27 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96572 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Keywords| |missed-optimization Last reconfirmed| |2020-08-25 Status|UNCONFIRMED |NEW CC| |msebor at gcc dot gnu.org, | |rguenth at gcc dot gnu.org --- Comment #1 from Richard Biener --- So phiprop sees [local count: 1073741824]: if (cond_4(D) !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870913]: [local count: 1073741824]: # q_3 =3D PHI <&i(2), p_5(D)(3)> _1 =3D *q_3; _2 =3D *p_5(D); _7 =3D _1 + _2; i =3D{v} {CLOBBER}; return _7; and if we extend it to handle the case of a single address PHI operand then we possibly would optimize this. After PRE we then have [local count: 1073741824]: pretmp_9 =3D *p_5(D); if (cond_3(D) !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: [local count: 1073741824]: # q_2 =3D PHI _8 =3D q_2 + pretmp_9; return _8; but then we're missing the optimistic copy propagation / value-numbering we do not perform because it defeats uninit warnings. So I'm not sure it is desirable to optimize this given the obvious fallout this will cause for diagnostics. After-phiprop proposed IL testcase we fail to optimize because of this: int f(int *p, _Bool cond) { int i; int q; if (cond) q =3D i; else q =3D *p; return q + *p; }=