[PATCH] D46162: [PowerPC] Don't transform to CTR loop if the decrement branch instr. would end up in a different loop

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 30 12:41:01 PDT 2018


efriedma added inline comments.


================
Comment at: lib/Target/PowerPC/PPCCTRLoops.cpp:578
+    // end up messing up the value in the CTR.
+    if (LI->getLoopFor(*I) != L || !DT->dominates(L->getHeader(), *I))
+      continue;
----------------
mkazantsev wrote:
> mkazantsev wrote:
> > nemanjai wrote:
> > > mkazantsev wrote:
> > > > By definition, loop header dominates all blocks of this loop. So once you've checked that `LI->getLoop(*I)` is `L`, it will automatically give you the second part of the check. I think you can assert that `DT->dominates(L->getHeader(), *I))` if the first part is true.
> > > Ah, OK. That makes sense. So clearly my condition isn't sufficient to address Eli's comment. If either you or Eli can suggest how I might modify this condition to also address irreducible loops completely nested in the outer loop, I would really appreciate it.
> > I don't think that SCEV will be able to calculate iteration count for a loop with irreducible control flow. Do you have a test when you really need to support it?
> Unless there is a reason why you need it, I would suggest just to limit this transform to the loops that have a single backedge since it's the canonical form.
SCEV can compute the trip count for a loop which contains irreducible control flow. For example:

```
define void @foo(i1 %z) {
entry:
  br label %loophead

loophead:
  %i = phi i32 [ 0, %entry ], [ %inc, %irr_exit ]
  br i1 %z, label %irr_head1, label %irr_head2

irr_head1:
  br label %exiting

irr_head2:
  br label %exiting

exiting:
  %inc = add nuw nsw i32 %i, 1
  %exitcond = icmp eq i32 %inc, 100000
  br i1 %exitcond, label %exit, label %irr_cont

irr_cont:
  br i1 %z, label %irr_cont2, label %irr_exit

irr_cont2:
  br i1 %z, label %irr_head1, label %irr_head2

irr_exit:
  br label %loophead

exit:
  ret void
}
```


Repository:
  rL LLVM

https://reviews.llvm.org/D46162





More information about the llvm-commits mailing list