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

Chris Lattner lattner at cs.uiuc.edu
Sat Apr 17 18:36:43 PDT 2004


Changes in directory llvm/lib/Transforms/Scalar:

IndVarSimplify.cpp updated: 1.57 -> 1.58

---
Log message:

If the loop executes a constant number of times, try a bit harder to replace
exit values.


---
Diffs of the changes:  (+5 -2)

Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.57 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.58
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.57	Sat Apr 17 13:08:33 2004
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp	Sat Apr 17 13:44:09 2004
@@ -276,6 +276,8 @@
   BasicBlock::iterator InsertPt = BlockToInsertInto->begin();
   while (isa<PHINode>(InsertPt)) ++InsertPt;
 
+  bool HasConstantItCount = isa<SCEVConstant>(SE->getIterationCount(L));
+
   std::set<Instruction*> InstructionsToDelete;
   
   for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
@@ -284,7 +286,8 @@
       for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
         if (I->getType()->isInteger()) {      // Is an integer instruction
           SCEVHandle SH = SE->getSCEV(I);
-          if (SH->hasComputableLoopEvolution(L)) {   // Varies predictably
+          if (SH->hasComputableLoopEvolution(L) ||    // Varies predictably
+              HasConstantItCount) {
             // Find out if this predictably varying value is actually used
             // outside of the loop.  "extra" as opposed to "intra".
             std::vector<User*> ExtraLoopUsers;
@@ -296,7 +299,7 @@
               // Okay, this instruction has a user outside of the current loop
               // and varies predictably in this loop.  Evaluate the value it
               // contains when the loop exits, and insert code for it.
-              SCEVHandle ExitValue = SE->getSCEVAtScope(I,L->getParentLoop());
+              SCEVHandle ExitValue = SE->getSCEVAtScope(I, L->getParentLoop());
               if (!isa<SCEVCouldNotCompute>(ExitValue)) {
                 Changed = true;
                 ++NumReplaced;





More information about the llvm-commits mailing list