From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1F9D23854838; Sun, 27 Jun 2021 15:30:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F9D23854838 From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101186] predictable comparison of integer variables not folded Date: Sun, 27 Jun 2021 15:30:22 +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: enhancement X-Bugzilla-Who: aldyh 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: 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: Sun, 27 Jun 2021 15:30:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101186 Aldy Hernandez changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |aldyh at gcc dot gnu.org, | |jeffreyalaw at gmail dot c= om --- Comment #4 from Aldy Hernandez --- To give a little more context, the IL at thread1 looks like this: [local count: 59055800]: goto ; [100.00%] [local count: 955630225]: if (a_5(D) !=3D 0) goto ; [67.00%] else goto ; [33.00%] [local count: 640272253]: if (x_8(D) < c_12) goto ; [33.00%] else goto ; [67.00%] [local count: 211289842]: unreachable (); goto ; [100.00%] [local count: 315357972]: blah (); [local count: 955630227]: b_11 =3D b_1 + 1; goto ; [100.00%] [local count: 118111600]: # c_12 =3D PHI [local count: 1073741824]: # b_1 =3D PHI if (b_1 <=3D 999) goto ; [89.00%] else goto ; [11.00%] The path from 3->9->10->4->5 could *theoretically* resolve the conditional = in BB5. If this were a permissible jump threading path, the threader would replace the conditional in BB5 into a jump to BB8, thus eliding the unreachable. However, BB9->BB10 would cross loop boundaries which is not permitted in the backwards threader. Specifically, the threading candidate conditional is B= B5, which is in a loop: ;; Loop 1 ;; header 10, latch 8 ;; depth 1, outer 0 ;; nodes: 10 8 6 7 5 4 (<-- note BB5 & BB10 in here) And BB9 is outside said loop. See path_crosses_loops in tree-ssa-threadbackward.c as well as handle_phi() where we specifically skip PHI edges pointing outside the current loop. Note that even though my upcoming rewrite of the backward threader does not= use the relational oracle, Andrew says it would be trivial to do so. In which case, we *could* resolve the above path, but would still fail to thread it because it crosses a loop boundary. Perhaps Jeff can opine on whether the path duplicator in the threader back-= end, could be taught to thread through loops.=