Balaram Makam via llvm-dev
2017-Jun-30 14:46 UTC
[llvm-dev] LoopSimplify pass prevents loop unrolling
Hi All, In the attached test case there, is an unnested loop with 2 iterations. The loop latch block is terminated by an unconditional branch, so simplifycfg folds the almost empty latch block into its predecessor which is the loop header. This results in an additional backedge in the CFG, so when LoopRotate pass is called it canonicalizes the loop into a nested loop. However, now the loop trip count is unpredictable as the BackedgeTakenCount for the outer loop is not loop invariant. As a result the loop cannot be unrolled. Is this the intended canonicalization for this loop or is the loopsimplify canonicalizing incorrectly? Should simplifycfg skip folding the latch block into the loop header if this results in additional backedges and let the empty blocks be folded during CGP? More details in https://bugs.llvm.org/show_bug.cgi?id=33605. FWIW, this prevents unrolling of a hot loop in spec2017/gcc and also prevents loop-interleave of a loop in spec2017/perlbench. Appreciate any suggestions on how to fix this. Attached testcase: $cat test.c void foo(); bool test(int a, int b, int *c) { bool changed = false; for (unsigned int i = 2; i--;) { int r = a | b; if ( r != c[i]) { c[i] = r; foo(); changed = true; } } return changed; } Thanks, Balaram -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170630/513f1f20/attachment.html>
Balaram Makam via llvm-dev
2017-Jun-30 14:48 UTC
[llvm-dev] LoopSimplify pass prevents loop unrolling
Edit. Predecessor -> successor. From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Balaram Makam via llvm-dev Sent: Friday, June 30, 2017 10:47 AM To: llvm-dev at lists.llvm.org Subject: [llvm-dev] LoopSimplify pass prevents loop unrolling Hi All, In the attached test case there, is an unnested loop with 2 iterations. The loop latch block is terminated by an unconditional branch, so simplifycfg folds the almost empty latch block into its successor which is the loop header. This results in an additional backedge in the CFG, so when LoopRotate pass is called it canonicalizes the loop into a nested loop. However, now the loop trip count is unpredictable as the BackedgeTakenCount for the outer loop is not loop invariant. As a result the loop cannot be unrolled. Is this the intended canonicalization for this loop or is the loopsimplify canonicalizing incorrectly? Should simplifycfg skip folding the latch block into the loop header if this results in additional backedges and let the empty blocks be folded during CGP? More details in https://bugs.llvm.org/show_bug.cgi?id=33605. FWIW, this prevents unrolling of a hot loop in spec2017/gcc and also prevents loop-interleave of a loop in spec2017/perlbench. Appreciate any suggestions on how to fix this. Attached testcase: $cat test.c void foo(); bool test(int a, int b, int *c) { bool changed = false; for (unsigned int i = 2; i--;) { int r = a | b; if ( r != c[i]) { c[i] = r; foo(); changed = true; } } return changed; } Thanks, Balaram -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170630/0275d044/attachment.html>
Friedman, Eli via llvm-dev
2017-Jun-30 17:59 UTC
[llvm-dev] LoopSimplify pass prevents loop unrolling
On 6/30/2017 7:48 AM, Balaram Makam via llvm-dev wrote:> > Edit. Predecessor -> successor. > > *From:* llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] *On Behalf > Of *Balaram Makam via llvm-dev > *Sent:* Friday, June 30, 2017 10:47 AM > *To:* llvm-dev at lists.llvm.org > *Subject:* [llvm-dev] LoopSimplify pass prevents loop unrolling > > Hi All, > > In the attached test case there, is an unnested loop with 2 > iterations. The loop latch block is terminated by an unconditional > branch, so simplifycfg folds the almost empty latch block into its > *successor* which is the loop header. This results in an additional > backedge in the CFG, so when LoopRotate pass is called it > canonicalizes the loop into a nested loop. However, now the loop trip > count is unpredictable as the BackedgeTakenCount for the outer loop is > not loop invariant. As a result the loop cannot be unrolled. Is this > the intended canonicalization for this loop or is the loopsimplify > canonicalizing incorrectly? Should simplifycfg skip folding the latch > block into the loop header if this results in additional backedges and > let the empty blocks be folded during CGP? More details in > https://bugs.llvm.org/show_bug.cgi?id=33605. >We have code that's supposed to prevent this from happening; see https://reviews.llvm.org/rL264697 . Maybe it also needs to check whether the destination of the branch is a loop header? -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170630/d9a33d10/attachment.html>
Maybe Matching Threads
- LoopSimplify pass prevents loop unrolling
- LoopSimplify pass prevents loop unrolling
- LoopSimplify pass prevents loop unrolling
- [LLVMdev] LICM promoting memory to scalar
- [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable