public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.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: Thu, 06 Jan 2022 20:13:56 +0000 [thread overview] Message-ID: <bug-103721-4-AyUb0cuILF@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-103721-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103721 Andrew Macleod <amacleod at redhat dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jeffreyalaw at gmail dot com --- Comment #3 from Andrew Macleod <amacleod at redhat dot com> --- After the initial loop tweaking, the IL that the threader sees in v.c.111t.threadfull1 is: ;; basic block 2, loop depth 0 goto <bb 10>; [100.00%] ;; basic block 3, loop depth 1 ipos.0_2 = ipos; if (ipos.0_2 != 0) goto <bb 6>; [50.00%] else goto <bb 4>; [50.00%] ;; basic block 4, loop depth 1 ;; basic block 6, loop depth 1 # searchVolume_11 = PHI <1(4), 0(3)> # currentVolume_10 = PHI <searchVolume_5(4), searchVolume_5(3)> ;; basic block 10, loop depth 1 # searchVolume_5 = PHI <searchVolume_11(6), 1111(2)> # currentVolume_6 = PHI <currentVolume_10(6), 0(2)> _7 = searchVolume_5 != currentVolume_6; _8 = searchVolume_5 != 0; _9 = _7 & _8; if (_9 != 0) goto <bb 3>; [89.00%] else goto <bb 7>; [11.00%] It looks to me like it decides to thread 2->10, which means it turns bb2 into something like: # searchVolume_5 = 1111 # currentVolume_6 = 0 _7 = searchVolume_5 != currentVolume_6; // folds to 1 _8 = searchVolume_5 != 0; // folds to 1 _9 = _7 & _8; //folds to 1 if (_9 != 0) // folds to goto bb3 goto <bb 3>; [89.00%] else goto <bb 7>; [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 = PHI <searchVolume_11(6)> # currentVolume_6 = PHI <currentVolume_10(6)> _7 = searchVolume_5 != currentVolume_6; _8 = searchVolume_5 != 0; _9 = _7 & _8; if (_9 != 0) goto <bb 3>; [89.00%] else goto <bb 7>; [11.00%] The problem would seem to be that when we thread 2->10, we are actually peeling off an iteration of the loop. the PHIs in BB6: ;; basic block 6, loop depth 1 # searchVolume_11 = PHI <1(4), 0(3)> # currentVolume_10 = PHI <searchVolume_5(4), searchVolume_5(3)> 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. Threading is out of my wheel house, but Its not clear to me how you could even update the PHI nodes properly if you try to thread that path... And its starting to give me a headache thinking about it :-) It seem that needs to be a new phi inserted in BB3 which sets searchvolume_5 = PHI <1111(2), searchVolume_11(10)> Or something to that efffect. something is missing anyway.
next prev parent reply other threads:[~2022-01-06 20:13 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-14 22:19 [Bug tree-optimization/103721] New: [12 regression] wrong code generated for loop with conditional (jump threading?) sss@li-snyder.org 2021-12-14 22:21 ` [Bug tree-optimization/103721] " pinskia at gcc dot gnu.org 2021-12-14 23:03 ` pinskia at gcc dot gnu.org 2021-12-15 11:27 ` [Bug tree-optimization/103721] [12 regression] wrong code generated for loop with conditional since r12-4790-g4b3a325f07acebf4 marxin at gcc dot gnu.org 2022-01-04 11:16 ` rguenth at gcc dot gnu.org 2022-01-06 20:13 ` amacleod at redhat dot com [this message] 2022-01-18 4:02 ` law at gcc dot gnu.org 2022-01-18 18:49 ` amacleod at redhat dot com 2022-01-19 12:44 ` aldyh at gcc dot gnu.org 2022-01-19 16:40 ` aldyh at gcc dot gnu.org 2022-01-19 16:58 ` amacleod at redhat dot com 2022-01-19 22:51 ` law at gcc dot gnu.org 2022-01-20 0:10 ` amacleod at redhat dot com 2022-01-20 11:13 ` aldyh at gcc dot gnu.org 2022-01-20 11:14 ` aldyh at gcc dot gnu.org 2022-01-20 13:28 ` aldyh at gcc dot gnu.org 2022-01-20 14:12 ` amacleod at redhat dot com 2022-01-21 10:19 ` cvs-commit at gcc dot gnu.org 2022-01-21 10:30 ` aldyh at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-103721-4-AyUb0cuILF@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).