[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 12 10:11:38 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

LoopStrengthReduce.cpp updated: 1.56 -> 1.57
---
Log message:

Fix a regression from last night, which caused this pass to create invalid
code for IV uses outside of loops that are not dominated by the latch block.
We should only convert these uses to use the post-inc value if they ARE
dominated by the latch block.

Also use a new LoopInfo method to simplify some code.

This fixes Transforms/LoopStrengthReduce/2005-09-12-UsesOutOutsideOfLoop.ll


---
Diffs of the changes:  (+6 -8)

 LoopStrengthReduce.cpp |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.56 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.57
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.56	Mon Sep 12 01:04:47 2005
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp	Mon Sep 12 12:11:27 2005
@@ -353,7 +353,11 @@
       // Okay, we found a user that we cannot reduce.  Analyze the instruction
       // and decide what to do with it.  If we are a use inside of the loop, use
       // the value before incrementation, otherwise use it after incrementation.
-      if (L->contains(User->getParent())) {
+      if (L->contains(User->getParent()) ||
+          // Alternatively, if we are a use outside of the loop, but is not
+          // dominated by the latch block, we have to use the preincremented
+          // value.
+          !DS->dominates(L->getLoopLatch(), User->getParent())) {
         IVUsesByStride[Stride].addUser(Start, User, I);
       } else {
         // The value used will be incremented by the stride more than we are
@@ -784,13 +788,7 @@
   Instruction *PreInsertPt = Preheader->getTerminator();
   Instruction *PhiInsertBefore = L->getHeader()->begin();
   
-  assert(isa<PHINode>(PhiInsertBefore) &&
-         "How could this loop have IV's without any phis?");
-  PHINode *SomeLoopPHI = cast<PHINode>(PhiInsertBefore);
-  assert(SomeLoopPHI->getNumIncomingValues() == 2 &&
-         "This loop isn't canonicalized right");
-  BasicBlock *LatchBlock =
-   SomeLoopPHI->getIncomingBlock(SomeLoopPHI->getIncomingBlock(0) == Preheader);
+  BasicBlock *LatchBlock = L->getLoopLatch();
   
   // Create a new Phi for this base, and stick it in the loop header.
   const Type *ReplacedTy = CommonExprs->getType();






More information about the llvm-commits mailing list