From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 305E8385801C; Tue, 18 Jan 2022 04:02:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 305E8385801C From: "law at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103721] [12 regression] wrong code generated for loop with conditional since r12-4790-g4b3a325f07acebf4 Date: Tue, 18 Jan 2022 04:02:45 +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: law 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: Tue, 18 Jan 2022 04:02:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103721 Jeffrey A. Law changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |law at gcc dot gnu.org --- Comment #4 from Jeffrey A. Law --- But what doesn't make any sense here is the folding in this block: [local count: 1073741824]: # searchVolume_5 =3D PHI # currentVolume_6 =3D PHI _2 =3D searchVolume_5 !=3D currentVolume_6; _3 =3D searchVolume_5 !=3D 0; _4 =3D _2 & _3; if (_4 !=3D 0) goto ; [89.00%] else goto ; [11.00%] In fold_using_range::range_of_range_op we have: (gdb) p debug_tree (op1) unit-size align:32 warn_if_not_align:0 symtab:0 alias-set 1 canonical-type 0x7ffff780e5e8 precision:32 min max pointer_to_this > visited var def_stmt searchVolume_5 =3D PHI version:5> $113 =3D void (gdb) p debug_tree (op2) unit-size align:32 warn_if_not_align:0 symtab:0 alias-set 1 canonical-type 0x7ffff780e5e8 precision:32 min max pointer_to_this > visited var def_stmt currentVolume_6 =3D PHI version:6> $114 =3D void (gdb) p rel $115 =3D EQ_EXPR If I'm reading the code correctly I think that means that the ranger has determined that _5 and _6 are equal. But I don't see how it can possibly m= ake that determination with this CFG: int f (int world) { int currentVolume; int searchVolume; int ipos.0_1; _Bool _2; _Bool _3; _Bool _4; ;; basic block 2, loop depth 0 ;; pred: ENTRY goto ; [100.00%] ;; succ: 9 ;; basic block 3, loop depth 1 ;; pred: 9 ipos.0_1 =3D ipos; if (ipos.0_1 !=3D 0) goto ; [50.00%] else goto ; [50.00%] ;; succ: 8 ;; 4 ;; basic block 4, loop depth 1 ;; pred: 3 ;; succ: 8 ;; basic block 8, loop depth 1 ;; pred: 4 ;; 3 # searchVolume_11 =3D PHI <1(4), 0(3)> # currentVolume_8 =3D PHI ;; succ: 9 ;; basic block 9, loop depth 1 ;; pred: 8 ;; 2 # searchVolume_5 =3D PHI # currentVolume_6 =3D PHI _2 =3D searchVolume_5 !=3D currentVolume_6; _3 =3D searchVolume_5 !=3D 0; _4 =3D _2 & _3; if (_4 !=3D 0) goto ; [89.00%] else goto ; [11.00%] ;; succ: 3 ;; 7 ;; basic block 7, loop depth 0 ;; pred: 9 return currentVolume_6; ;; succ: EXIT } This feels like it's got to be a problem in the equivalence handling -- it's largely outside the threader. My recollection of equivalences in loops is that they're exceedingly hard to get correct once you follow the backedge -- particularly since you have to invalidate some equivalences once you traverse that backedge. Finding the = set that needed to be invalidated was expensive and the book keeping turned out= to be too hard to do reliably so I ripped it all out. How does equivalence handling in the Ranger world work once you traverse the backedge of a loop?=