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

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 27 05:34:47 PDT 2018


hfinkel added inline comments.


================
Comment at: lib/Target/PowerPC/PPCCTRLoops.cpp:579
+    if (LI->getLoopFor(*I) != L)
+      continue;
+
----------------
nemanjai wrote:
> efriedma wrote:
> > The actual condition you need to check is whether the branch executes exactly once per iteration.
> > 
> > For most code, this check is equivalent, but it's possible to have an irreducible "loop" which is not an LLVM Loop.
> Sorry if this is a naive question, but would adding a check that this loop's header dominates the exit block suffice for such a case?
> 
> I don't really know what an irreducible loop looks like, but with this question, I'm making the assumption that for such a loop, there would have to be a path to the exit block that doesn't go through the header. Of course, if this assumption is wrong, please correct me.
We have a utility for this. ShrinkWrapping uses it:

  if (containsIrreducibleCFG<MachineBasicBlock *>(RPOT, *MLI)) {

as does the loop vectorizer:

  if (!containsIrreducibleCFG<const BasicBlock *>(RPOT, *LI)) {

I think that you want to do something here very similar to what the loop vectorizer does:

static void collectSupportedLoops(Loop &L, LoopInfo *LI,
                                  OptimizationRemarkEmitter *ORE,
                                  SmallVectorImpl<Loop *> &V) {
  // Collect inner loops and outer loops without irreducible control flow. For
  // now, only collect outer loops that have explicit vectorization hints.
  if (L.empty() || (EnableVPlanNativePath && isExplicitVecOuterLoop(&L, ORE))) {
    LoopBlocksRPO RPOT(&L);
    RPOT.perform(LI);
    if (!containsIrreducibleCFG<const BasicBlock *>(RPOT, *LI)) {
      V.push_back(&L);
      // TODO: Collect inner loops inside marked outer loops in case
      // vectorization fails for the outer loop. Do not invoke
      // 'containsIrreducibleCFG' again for inner loops when the outer loop is
      // already known to be reducible. We can use an inherited attribute for
      // that.
      return;
    }
  }
  for (Loop *InnerL : L)
    collectSupportedLoops(*InnerL, LI, ORE, V);
}



Repository:
  rL LLVM

https://reviews.llvm.org/D46162





More information about the llvm-commits mailing list