[llvm-commits] CVS: llvm/lib/Analysis/ScalarEvolution.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Apr 26 11:34:20 PDT 2006



Changes in directory llvm/lib/Analysis:

ScalarEvolution.cpp updated: 1.47 -> 1.48
---
Log message:

Implement Transforms/IndVarsSimplify/complex-scev.ll, a case where we didn't
recognize some simple affine IV's.


---
Diffs of the changes:  (+25 -0)

 ScalarEvolution.cpp |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+)


Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.47 llvm/lib/Analysis/ScalarEvolution.cpp:1.48
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.47	Tue Apr  4 01:11:42 2006
+++ llvm/lib/Analysis/ScalarEvolution.cpp	Wed Apr 26 13:34:07 2006
@@ -1304,6 +1304,31 @@
               return PHISCEV;
             }
           }
+        } else if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(BEValue)) {
+          // Otherwise, this could be a loop like this:
+          //     i = 0;  for (j = 1; ..; ++j) { ....  i = j; }
+          // In this case, j = {1,+,1}  and BEValue is j.
+          // Because the other in-value of i (0) fits the evolution of BEValue
+          // i really is an addrec evolution.
+          if (AddRec->getLoop() == L && AddRec->isAffine()) {
+            SCEVHandle StartVal = getSCEV(PN->getIncomingValue(IncomingEdge));
+
+            // If StartVal = j.start - j.stride, we can use StartVal as the
+            // initial step of the addrec evolution.
+            if (StartVal == SCEV::getMinusSCEV(AddRec->getOperand(0),
+                                               AddRec->getOperand(1))) {
+              SCEVHandle PHISCEV = 
+                 SCEVAddRecExpr::get(StartVal, AddRec->getOperand(1), L);
+
+              // Okay, for the entire analysis of this edge we assumed the PHI
+              // to be symbolic.  We now need to go back and update all of the
+              // entries for the scalars that use the PHI (except for the PHI
+              // itself) to use the new analyzed value instead of the "symbolic"
+              // value.
+              ReplaceSymbolicValueWithConcrete(PN, SymbolicName, PHISCEV);
+              return PHISCEV;
+            }
+          }
         }
 
         return SymbolicName;






More information about the llvm-commits mailing list