[PATCH] D16570: [IndVarSimplify] Rewrite loop exit values with their initial values from loop preheader

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 21:26:20 PST 2016


sanjoy accepted this revision.
sanjoy added a comment.
This revision is now accepted and ready to land.

lgtm with minor nits inline


================
Comment at: lib/Transforms/Scalar/IndVarSimplify.cpp:719
@@ +718,3 @@
+    // values defined inside the loop are used on this path.
+    while (auto *PN = dyn_cast<PHINode>(begin++)) {
+      for (unsigned IncomingValIdx = 0, e = PN->getNumIncomingValues();
----------------
Nit: LLVM style is `BasicBlock::iterator BBI = ExitBB->begin();` or `BasicBlock::iterator Begin = ExitBB->begin();`

================
Comment at: lib/Transforms/Scalar/IndVarSimplify.cpp:745
@@ +744,3 @@
+        // All non-instructions are loop-invariant.
+        if (isa<Instruction>(Cond) && !L->isLoopInvariant(Cond))
+            continue;
----------------
I don't think you have to special case this -- `isLoopInvariant` takes a `Value *` and returns `true` for non instructions.

================
Comment at: lib/Transforms/Scalar/IndVarSimplify.cpp:764
@@ +763,3 @@
+          PN->setIncomingValue(IncomingValIdx,
+              ExitVal->getIncomingValueForBlock(LoopPreheader));
+        }
----------------
Since you're calling `getBasicBlockIndex`, why not save the index and re-use it here?


http://reviews.llvm.org/D16570





More information about the llvm-commits mailing list