From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 807373858036; Fri, 5 Nov 2021 20:20:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 807373858036 From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102650] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) Date: Fri, 05 Nov 2021 20:20:18 +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: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com 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: 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: Fri, 05 Nov 2021 20:20:18 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102650 --- Comment #3 from Andrew Macleod --- I figured running ranger as VRP2 would fix this... but alas, there is some interference :-) After fre5: [local count: 118111600]: # prephitmp_24 =3D PHI <1(3), 4(2)> d.5_16 =3D d; if (d.5_16 <=3D 0) goto ; [89.00%] else goto ; [11.00%] [local count: 955630225]: d =3D 1; [local count: 118111600]: # e_4 =3D PHI if (e_4 =3D=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 38976828]: foo (); We know prephitmp_24 is [1,1] [4,4], and e_17 is undefined on 4->6, so rang= er will evaluate that PHI as [1,1], [4,4] and fold the condition as never true. Unfortuntely, the next opass is threasd2 and its decides to thread this, producing: [local count: 118111600]: # prephitmp_24 =3D PHI <1(3), 4(2)> d.5_16 =3D d; if (d.5_16 <=3D 0) goto ; [89.00%] else goto ; [11.00%] [local count: 105119324]: d =3D 1; goto ; [100.00%] [local count: 12992276]: # e_4 =3D PHI if (e_4 =3D=3D 0) goto ; [66.33%] else goto ; [33.67%] [local count: 38976828]: foo (); [local count: 118111600]: return 0; now we have a condition if (e_4 =3D=3D 0) and e_4 is UNDEFINED, and so rang= er leaves it alone. Is there any pass that examines branches using undefined values and decides which way to fold it is most profitable? probably not.=20=20 Running this with --param=3Dvrp1-mode=3Dranger resolves the problem because= we don't introduce this situation before it's taken care of,a nd we fold the condition based on the PHI.=