From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A3EA2385803D; Thu, 6 Jan 2022 20:13:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3EA2385803D From: "amacleod at redhat dot com" 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: Thu, 06 Jan 2022 20:13:56 +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: amacleod at redhat dot com 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, 06 Jan 2022 20:13:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103721 Andrew Macleod changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jeffreyalaw at gmail dot c= om --- Comment #3 from Andrew Macleod --- After the initial loop tweaking, the IL that the threader sees in=20 v.c.111t.threadfull1 is: ;; basic block 2, loop depth 0 goto ; [100.00%] ;; basic block 3, loop depth 1 ipos.0_2 =3D ipos; if (ipos.0_2 !=3D 0) goto ; [50.00%] else goto ; [50.00%] ;; basic block 4, loop depth 1 ;; basic block 6, loop depth 1 # searchVolume_11 =3D PHI <1(4), 0(3)> # currentVolume_10 =3D PHI ;; basic block 10, loop depth 1 # searchVolume_5 =3D PHI # currentVolume_6 =3D PHI _7 =3D searchVolume_5 !=3D currentVolume_6; _8 =3D searchVolume_5 !=3D 0; _9 =3D _7 & _8; if (_9 !=3D 0) goto ; [89.00%] else goto ; [11.00%] It looks to me like it decides to thread 2->10, which means it turns bb2 in= to something like: # searchVolume_5 =3D 1111 # currentVolume_6 =3D 0 _7 =3D searchVolume_5 !=3D currentVolume_6; // folds to 1 _8 =3D searchVolume_5 !=3D 0; // folds to 1 _9 =3D _7 & _8; //folds to 1 if (_9 !=3D 0) // folds to goto bb3=20 goto ; [89.00%] else goto ; [11.00%] And then it updates the PHIS in BB10 to not have an edge from bb2: (note= I am doing this by hand, not actually renaming any ssa_names.) ;; basic block 10, loop depth 1 # searchVolume_5 =3D PHI # currentVolume_6 =3D PHI _7 =3D searchVolume_5 !=3D currentVolume_6; _8 =3D searchVolume_5 !=3D 0; _9 =3D _7 & _8; if (_9 !=3D 0) goto ; [89.00%] else goto ; [11.00%] The problem would seem to be that when we thread 2->10, we are actually pee= ling off an iteration of the loop. the PHIs in BB6: ;; basic block 6, loop depth 1 # searchVolume_11 =3D PHI <1(4), 0(3)> # currentVolume_10 =3D PHI I think currentVolume_10 is picking up searchVolume_5 calulated from the threaded entry point, which is the constant 1111... and we are "losing" the information that it could also be the value of searchVolume_11 from the previous iteration.=20 Threading is out of my wheel house, but Its not clear to me how you could e= ven update the PHI nodes properly if you try to thread that path...=20 And its starting to give me a headache thinking about it :-)=20=20 It seem that needs to be a new phi inserted in BB3 which sets searchvolume_= 5 =3D PHI <1111(2), searchVolume_11(10)> Or something to that efffect. something is missing anyway.=