[PATCH] D44287: [LICM] Ignore exits provably not taken on first iteration when computing must execute

Anna Thomas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 9 09:15:21 PST 2018


anna added inline comments.


================
Comment at: lib/Transforms/Utils/LoopUtils.cpp:1535
+  // todo: this would be a lot more powerful if we used scev, but all the
+  // plumbing is currently missing
+  auto *ICI = dyn_cast<ICmpInst>(BI->getCondition());
----------------
I think we do have SCEV logic to handle this case, but it maybe much weaker than InstSimplify. What we need is something along these lines but `getMin` instead of `getExact` for a given exiting block.
```
 /// Return the number of times this loop exit may fall through to the back
    /// edge, or SCEVCouldNotCompute. The loop is guaranteed not to exit via
    /// this block before this number of iterations, but may exit via another
    /// block.
    const SCEV *getExact(BasicBlock *ExitingBlock, ScalarEvolution *SE) const;
```
For every ExitBlock that `Inst` does not dominate, get the exiting block which is its single Predecessor (bail out if more than one). Then we just call this SCEV routine. Right now, since it only returns the "exact" count, we maybe usually returning `CouldNotCompute`.



================
Comment at: lib/Transforms/Utils/LoopUtils.cpp:1544
+    return false;
+  auto DL = ExitBlock->getParent()->getParent()->getDataLayout();
+  auto *IVStart = LHS->getIncomingValueForBlock(CurLoop->getLoopPreheader());
----------------
ExitBlock->getModule()


================
Comment at: lib/Transforms/Utils/LoopUtils.cpp:1548
+                                           IVStart, RHS,
+                                           {DL, nullptr, DT, nullptr, BI});
+  auto *SimpleCst = dyn_cast_or_null<Constant>(SimpleValOrNull);
----------------
Could you pls add what these nullptrs are? These are args that make up `SimplifyQuery`.


================
Comment at: lib/Transforms/Utils/LoopUtils.cpp:1585
+  // exit.  We do not prove *which* iteration the instruction must execute on.
+  // 2) If we can prove that the instruction dominates the latch and any exit
+  // which might be taken on the first iteration, we know the instruction must
----------------
dominates the latch and *all* exits that might be taken on first iteration.


Repository:
  rL LLVM

https://reviews.llvm.org/D44287





More information about the llvm-commits mailing list