[llvm-commits] [llvm] r70919 - in /llvm/trunk/lib: Analysis/ScalarEvolution.cpp Transforms/Scalar/LoopStrengthReduce.cpp

Dan Gohman gohman at apple.com
Mon May 4 15:02:23 PDT 2009


Author: djg
Date: Mon May  4 17:02:23 2009
New Revision: 70919

URL: http://llvm.org/viewvc/llvm-project?rev=70919&view=rev
Log:
Constify a bunch of SCEV-using code.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=70919&r1=70918&r2=70919&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon May  4 17:02:23 2009
@@ -650,25 +650,25 @@
          "This is not a conversion to a SCEVable type!");
   Ty = getEffectiveSCEVType(Ty);
 
-  if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
+  if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
     return getUnknown(
         ConstantExpr::getTrunc(SC->getValue(), Ty));
 
   // trunc(trunc(x)) --> trunc(x)
-  if (SCEVTruncateExpr *ST = dyn_cast<SCEVTruncateExpr>(Op))
+  if (const SCEVTruncateExpr *ST = dyn_cast<SCEVTruncateExpr>(Op))
     return getTruncateExpr(ST->getOperand(), Ty);
 
   // trunc(sext(x)) --> sext(x) if widening or trunc(x) if narrowing
-  if (SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
+  if (const SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
     return getTruncateOrSignExtend(SS->getOperand(), Ty);
 
   // trunc(zext(x)) --> zext(x) if widening or trunc(x) if narrowing
-  if (SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
+  if (const SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
     return getTruncateOrZeroExtend(SZ->getOperand(), Ty);
 
   // If the input value is a chrec scev made out of constants, truncate
   // all of the constants.
-  if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
+  if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
     std::vector<SCEVHandle> Operands;
     for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i)
       // FIXME: This should allow truncation of other expression types!
@@ -693,7 +693,7 @@
          "This is not a conversion to a SCEVable type!");
   Ty = getEffectiveSCEVType(Ty);
 
-  if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
+  if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
     const Type *IntTy = getEffectiveSCEVType(Ty);
     Constant *C = ConstantExpr::getZExt(SC->getValue(), IntTy);
     if (IntTy != Ty) C = ConstantExpr::getIntToPtr(C, Ty);
@@ -701,14 +701,14 @@
   }
 
   // zext(zext(x)) --> zext(x)
-  if (SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
+  if (const SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
     return getZeroExtendExpr(SZ->getOperand(), Ty);
 
   // If the input value is a chrec scev, and we can prove that the value
   // did not overflow the old, smaller, value, we can zero extend all of the
   // operands (often constants).  This allows analysis of something like
   // this:  for (unsigned char X = 0; X < 100; ++X) { int Y = X; }
-  if (SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
+  if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
     if (AR->isAffine()) {
       // Check whether the backedge-taken count is SCEVCouldNotCompute.
       // Note that this serves two purposes: It filters out loops that are
@@ -778,7 +778,7 @@
          "This is not a conversion to a SCEVable type!");
   Ty = getEffectiveSCEVType(Ty);
 
-  if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
+  if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
     const Type *IntTy = getEffectiveSCEVType(Ty);
     Constant *C = ConstantExpr::getSExt(SC->getValue(), IntTy);
     if (IntTy != Ty) C = ConstantExpr::getIntToPtr(C, Ty);
@@ -786,14 +786,14 @@
   }
 
   // sext(sext(x)) --> sext(x)
-  if (SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
+  if (const SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
     return getSignExtendExpr(SS->getOperand(), Ty);
 
   // If the input value is a chrec scev, and we can prove that the value
   // did not overflow the old, smaller, value, we can sign extend all of the
   // operands (often constants).  This allows analysis of something like
   // this:  for (signed char X = 0; X < 100; ++X) { int Y = X; }
-  if (SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
+  if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
     if (AR->isAffine()) {
       // Check whether the backedge-taken count is SCEVCouldNotCompute.
       // Note that this serves two purposes: It filters out loops that are
@@ -850,10 +850,10 @@
 
   // If there are any constants, fold them together.
   unsigned Idx = 0;
-  if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
+  if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
     ++Idx;
     assert(Idx < Ops.size());
-    while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
+    while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
       // We found two constants, fold them together!
       ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() + 
                                            RHSC->getValue()->getValue());
@@ -896,7 +896,7 @@
   // If there are add operands they would be next.
   if (Idx < Ops.size()) {
     bool DeletedAdd = false;
-    while (SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[Idx])) {
+    while (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[Idx])) {
       // If we have an add, expand the add operands onto the end of the operands
       // list.
       Ops.insert(Ops.end(), Add->op_begin(), Add->op_end());
@@ -1075,11 +1075,11 @@
 
   // If there are any constants, fold them together.
   unsigned Idx = 0;
-  if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
+  if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
 
     // C1*(C2+V) -> C1*C2 + C1*V
     if (Ops.size() == 2)
-      if (SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[1]))
+      if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[1]))
         if (Add->getNumOperands() == 2 &&
             isa<SCEVConstant>(Add->getOperand(0)))
           return getAddExpr(getMulExpr(LHSC, Add->getOperand(0)),
@@ -1087,7 +1087,7 @@
 
 
     ++Idx;
-    while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
+    while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
       // We found two constants, fold them together!
       ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() * 
                                            RHSC->getValue()->getValue());
@@ -1117,7 +1117,7 @@
   // If there are mul operands inline them all into this expression.
   if (Idx < Ops.size()) {
     bool DeletedMul = false;
-    while (SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(Ops[Idx])) {
+    while (const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(Ops[Idx])) {
       // If we have an mul, expand the mul operands onto the end of the operands
       // list.
       Ops.insert(Ops.end(), Mul->op_begin(), Mul->op_end());
@@ -1225,11 +1225,11 @@
 }
 
 SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS, const SCEVHandle &RHS) {
-  if (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS)) {
+  if (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS)) {
     if (RHSC->getValue()->equalsInt(1))
       return LHS;                            // X udiv 1 --> x
 
-    if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS)) {
+    if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS)) {
       Constant *LHSCV = LHSC->getValue();
       Constant *RHSCV = RHSC->getValue();
       return getUnknown(ConstantExpr::getUDiv(LHSCV, RHSCV));
@@ -1250,7 +1250,7 @@
                                const SCEVHandle &Step, const Loop *L) {
   std::vector<SCEVHandle> Operands;
   Operands.push_back(Start);
-  if (SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(Step))
+  if (const SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(Step))
     if (StepChrec->getLoop() == L) {
       Operands.insert(Operands.end(), StepChrec->op_begin(),
                       StepChrec->op_end());
@@ -1273,7 +1273,7 @@
   }
 
   // Canonicalize nested AddRecs in by nesting them in order of loop depth.
-  if (SCEVAddRecExpr *NestedAR = dyn_cast<SCEVAddRecExpr>(Operands[0])) {
+  if (const SCEVAddRecExpr *NestedAR = dyn_cast<SCEVAddRecExpr>(Operands[0])) {
     const Loop* NestedLoop = NestedAR->getLoop();
     if (L->getLoopDepth() < NestedLoop->getLoopDepth()) {
       std::vector<SCEVHandle> NestedOperands(NestedAR->op_begin(),
@@ -1309,10 +1309,10 @@
 
   // If there are any constants, fold them together.
   unsigned Idx = 0;
-  if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
+  if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
     ++Idx;
     assert(Idx < Ops.size());
-    while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
+    while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
       // We found two constants, fold them together!
       ConstantInt *Fold = ConstantInt::get(
                               APIntOps::smax(LHSC->getValue()->getValue(),
@@ -1340,7 +1340,7 @@
   // onto our operand list, and recurse to simplify.
   if (Idx < Ops.size()) {
     bool DeletedSMax = false;
-    while (SCEVSMaxExpr *SMax = dyn_cast<SCEVSMaxExpr>(Ops[Idx])) {
+    while (const SCEVSMaxExpr *SMax = dyn_cast<SCEVSMaxExpr>(Ops[Idx])) {
       Ops.insert(Ops.end(), SMax->op_begin(), SMax->op_end());
       Ops.erase(Ops.begin()+Idx);
       DeletedSMax = true;
@@ -1389,10 +1389,10 @@
 
   // If there are any constants, fold them together.
   unsigned Idx = 0;
-  if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
+  if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
     ++Idx;
     assert(Idx < Ops.size());
-    while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
+    while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
       // We found two constants, fold them together!
       ConstantInt *Fold = ConstantInt::get(
                               APIntOps::umax(LHSC->getValue()->getValue(),
@@ -1420,7 +1420,7 @@
   // onto our operand list, and recurse to simplify.
   if (Idx < Ops.size()) {
     bool DeletedUMax = false;
-    while (SCEVUMaxExpr *UMax = dyn_cast<SCEVUMaxExpr>(Ops[Idx])) {
+    while (const SCEVUMaxExpr *UMax = dyn_cast<SCEVUMaxExpr>(Ops[Idx])) {
       Ops.insert(Ops.end(), UMax->op_begin(), UMax->op_end());
       Ops.erase(Ops.begin()+Idx);
       DeletedUMax = true;
@@ -1580,7 +1580,7 @@
 /// getNegativeSCEV - Return a SCEV corresponding to -V = -1*V
 ///
 SCEVHandle ScalarEvolution::getNegativeSCEV(const SCEVHandle &V) {
-  if (SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
+  if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
     return getUnknown(ConstantExpr::getNeg(VC->getValue()));
 
   const Type *Ty = V->getType();
@@ -1590,7 +1590,7 @@
 
 /// getNotSCEV - Return a SCEV corresponding to ~V = -1-V
 SCEVHandle ScalarEvolution::getNotSCEV(const SCEVHandle &V) {
-  if (SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
+  if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
     return getUnknown(ConstantExpr::getNot(VC->getValue()));
 
   const Type *Ty = V->getType();
@@ -1690,7 +1690,7 @@
 
         // If the value coming around the backedge is an add with the symbolic
         // value we just inserted, then we found a simple induction variable!
-        if (SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(BEValue)) {
+        if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(BEValue)) {
           // If there is a single occurrence of the symbolic value, replace it
           // with a recurrence.
           unsigned FoundIndex = Add->getNumOperands();
@@ -1726,7 +1726,8 @@
               return PHISCEV;
             }
           }
-        } else if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(BEValue)) {
+        } else if (const 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.
@@ -1765,26 +1766,26 @@
 /// the minimum number of times S is divisible by 2.  For example, given {4,+,8}
 /// it returns 2.  If S is guaranteed to be 0, it returns the bitwidth of S.
 static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) {
-  if (SCEVConstant *C = dyn_cast<SCEVConstant>(S))
+  if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S))
     return C->getValue()->getValue().countTrailingZeros();
 
-  if (SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(S))
+  if (const SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(S))
     return std::min(GetMinTrailingZeros(T->getOperand(), SE),
                     (uint32_t)SE.getTypeSizeInBits(T->getType()));
 
-  if (SCEVZeroExtendExpr *E = dyn_cast<SCEVZeroExtendExpr>(S)) {
+  if (const SCEVZeroExtendExpr *E = dyn_cast<SCEVZeroExtendExpr>(S)) {
     uint32_t OpRes = GetMinTrailingZeros(E->getOperand(), SE);
     return OpRes == SE.getTypeSizeInBits(E->getOperand()->getType()) ?
              SE.getTypeSizeInBits(E->getOperand()->getType()) : OpRes;
   }
 
-  if (SCEVSignExtendExpr *E = dyn_cast<SCEVSignExtendExpr>(S)) {
+  if (const SCEVSignExtendExpr *E = dyn_cast<SCEVSignExtendExpr>(S)) {
     uint32_t OpRes = GetMinTrailingZeros(E->getOperand(), SE);
     return OpRes == SE.getTypeSizeInBits(E->getOperand()->getType()) ?
              SE.getTypeSizeInBits(E->getOperand()->getType()) : OpRes;
   }
 
-  if (SCEVAddExpr *A = dyn_cast<SCEVAddExpr>(S)) {
+  if (const SCEVAddExpr *A = dyn_cast<SCEVAddExpr>(S)) {
     // The result is the min of all operands results.
     uint32_t MinOpRes = GetMinTrailingZeros(A->getOperand(0), SE);
     for (unsigned i = 1, e = A->getNumOperands(); MinOpRes && i != e; ++i)
@@ -1792,7 +1793,7 @@
     return MinOpRes;
   }
 
-  if (SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) {
+  if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) {
     // The result is the sum of all operands results.
     uint32_t SumOpRes = GetMinTrailingZeros(M->getOperand(0), SE);
     uint32_t BitWidth = SE.getTypeSizeInBits(M->getType());
@@ -1803,7 +1804,7 @@
     return SumOpRes;
   }
 
-  if (SCEVAddRecExpr *A = dyn_cast<SCEVAddRecExpr>(S)) {
+  if (const SCEVAddRecExpr *A = dyn_cast<SCEVAddRecExpr>(S)) {
     // The result is the min of all operands results.
     uint32_t MinOpRes = GetMinTrailingZeros(A->getOperand(0), SE);
     for (unsigned i = 1, e = A->getNumOperands(); MinOpRes && i != e; ++i)
@@ -1811,7 +1812,7 @@
     return MinOpRes;
   }
 
-  if (SCEVSMaxExpr *M = dyn_cast<SCEVSMaxExpr>(S)) {
+  if (const SCEVSMaxExpr *M = dyn_cast<SCEVSMaxExpr>(S)) {
     // The result is the min of all operands results.
     uint32_t MinOpRes = GetMinTrailingZeros(M->getOperand(0), SE);
     for (unsigned i = 1, e = M->getNumOperands(); MinOpRes && i != e; ++i)
@@ -1819,7 +1820,7 @@
     return MinOpRes;
   }
 
-  if (SCEVUMaxExpr *M = dyn_cast<SCEVUMaxExpr>(S)) {
+  if (const SCEVUMaxExpr *M = dyn_cast<SCEVUMaxExpr>(S)) {
     // The result is the min of all operands results.
     uint32_t MinOpRes = GetMinTrailingZeros(M->getOperand(0), SE);
     for (unsigned i = 1, e = M->getNumOperands(); MinOpRes && i != e; ++i)
@@ -2224,8 +2225,8 @@
 
   // If we have a comparison of a chrec against a constant, try to use value
   // ranges to answer this query.
-  if (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS))
-    if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(LHS))
+  if (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS))
+    if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(LHS))
       if (AddRec->getLoop() == L) {
         // Form the comparison range using the constant of the correct type so
         // that the ConstantRange class knows to do a signed or unsigned
@@ -2610,7 +2611,7 @@
 
   // If this instruction is evolved from a constant-evolving PHI, compute the
   // exit value from the loop without using SCEVs.
-  if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(V)) {
+  if (const SCEVUnknown *SU = dyn_cast<SCEVUnknown>(V)) {
     if (Instruction *I = dyn_cast<Instruction>(SU->getValue())) {
       const Loop *LI = (*this->LI)[I->getParent()];
       if (LI && LI->getParentLoop() == L)  // Looking for loop exit value.
@@ -2621,7 +2622,7 @@
             // count.  If so, we may be able to force computation of the exit
             // value.
             SCEVHandle BackedgeTakenCount = getBackedgeTakenCount(LI);
-            if (SCEVConstant *BTCC =
+            if (const SCEVConstant *BTCC =
                   dyn_cast<SCEVConstant>(BackedgeTakenCount)) {
               // Okay, we know how many times the containing loop executes.  If
               // this is a constant evolving PHI node, get the final value at
@@ -2652,7 +2653,7 @@
               return V;
 
             SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L);
-            if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV)) {
+            if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV)) {
               Constant *C = SC->getValue();
               if (C->getType() != Op->getType())
                 C = ConstantExpr::getCast(CastInst::getCastOpcode(C, false,
@@ -2660,7 +2661,7 @@
                                                                   false),
                                           C, Op->getType());
               Operands.push_back(C);
-            } else if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
+            } else if (const SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
               if (Constant *C = dyn_cast<Constant>(SU->getValue())) {
                 if (C->getType() != Op->getType())
                   C =
@@ -2692,7 +2693,7 @@
     return V;
   }
 
-  if (SCEVCommutativeExpr *Comm = dyn_cast<SCEVCommutativeExpr>(V)) {
+  if (const SCEVCommutativeExpr *Comm = dyn_cast<SCEVCommutativeExpr>(V)) {
     // Avoid performing the look-up in the common case where the specified
     // expression has no loop-variant portions.
     for (unsigned i = 0, e = Comm->getNumOperands(); i != e; ++i) {
@@ -2724,7 +2725,7 @@
     return Comm;
   }
 
-  if (SCEVUDivExpr *Div = dyn_cast<SCEVUDivExpr>(V)) {
+  if (const SCEVUDivExpr *Div = dyn_cast<SCEVUDivExpr>(V)) {
     SCEVHandle LHS = getSCEVAtScope(Div->getLHS(), L);
     if (LHS == UnknownValue) return LHS;
     SCEVHandle RHS = getSCEVAtScope(Div->getRHS(), L);
@@ -2736,7 +2737,7 @@
 
   // If this is a loop recurrence for a loop that does not contain L, then we
   // are dealing with the final value computed by the loop.
-  if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(V)) {
+  if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(V)) {
     if (!L || !AddRec->getLoop()->contains(L->getHeader())) {
       // To evaluate this recurrence, we need to know how many times the AddRec
       // loop iterates.  Compute this now.
@@ -2749,7 +2750,7 @@
     return UnknownValue;
   }
 
-  if (SCEVZeroExtendExpr *Cast = dyn_cast<SCEVZeroExtendExpr>(V)) {
+  if (const SCEVZeroExtendExpr *Cast = dyn_cast<SCEVZeroExtendExpr>(V)) {
     SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L);
     if (Op == UnknownValue) return Op;
     if (Op == Cast->getOperand())
@@ -2757,7 +2758,7 @@
     return getZeroExtendExpr(Op, Cast->getType());
   }
 
-  if (SCEVSignExtendExpr *Cast = dyn_cast<SCEVSignExtendExpr>(V)) {
+  if (const SCEVSignExtendExpr *Cast = dyn_cast<SCEVSignExtendExpr>(V)) {
     SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L);
     if (Op == UnknownValue) return Op;
     if (Op == Cast->getOperand())
@@ -2765,7 +2766,7 @@
     return getSignExtendExpr(Op, Cast->getType());
   }
 
-  if (SCEVTruncateExpr *Cast = dyn_cast<SCEVTruncateExpr>(V)) {
+  if (const SCEVTruncateExpr *Cast = dyn_cast<SCEVTruncateExpr>(V)) {
     SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L);
     if (Op == UnknownValue) return Op;
     if (Op == Cast->getOperand())
@@ -2903,7 +2904,7 @@
 /// value to zero will execute.  If not computable, return UnknownValue
 SCEVHandle ScalarEvolution::HowFarToZero(SCEV *V, const Loop *L) {
   // If the value is a constant
-  if (SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
+  if (const SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
     // If the value is already zero, the branch will execute zero times.
     if (C->getValue()->isZero()) return C;
     return UnknownValue;  // Otherwise it will loop infinitely.
@@ -2931,7 +2932,7 @@
 
     SCEVHandle Step = getSCEVAtScope(AddRec->getOperand(1), L->getParentLoop());
 
-    if (SCEVConstant *StepC = dyn_cast<SCEVConstant>(Step)) {
+    if (const SCEVConstant *StepC = dyn_cast<SCEVConstant>(Step)) {
       // For now we handle only constant steps.
 
       // First, handle unitary steps.
@@ -2941,7 +2942,7 @@
         return Start;                           //    N = Start (as unsigned)
 
       // Then, try to solve the above equation provided that Start is constant.
-      if (SCEVConstant *StartC = dyn_cast<SCEVConstant>(Start))
+      if (const SCEVConstant *StartC = dyn_cast<SCEVConstant>(Start))
         return SolveLinEquationWithOverflow(StepC->getValue()->getValue(),
                                             -StartC->getValue()->getValue(),
                                             *this);
@@ -2988,7 +2989,7 @@
 
   // If the value is a constant, check to see if it is known to be non-zero
   // already.  If so, the backedge will execute zero times.
-  if (SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
+  if (const SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
     if (!C->getValue()->isNullValue())
       return getIntegerSCEV(0, C->getType());
     return UnknownValue;  // Otherwise it will loop infinitely.
@@ -3232,12 +3233,13 @@
     return SE.getCouldNotCompute();
 
   // If the start is a non-zero constant, shift the range to simplify things.
-  if (SCEVConstant *SC = dyn_cast<SCEVConstant>(getStart()))
+  if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(getStart()))
     if (!SC->getValue()->isZero()) {
       std::vector<SCEVHandle> Operands(op_begin(), op_end());
       Operands[0] = SE.getIntegerSCEV(0, SC->getType());
       SCEVHandle Shifted = SE.getAddRecExpr(Operands, getLoop());
-      if (SCEVAddRecExpr *ShiftedAddRec = dyn_cast<SCEVAddRecExpr>(Shifted))
+      if (const SCEVAddRecExpr *ShiftedAddRec =
+            dyn_cast<SCEVAddRecExpr>(Shifted))
         return ShiftedAddRec->getNumIterationsInRange(
                            Range.subtract(SC->getValue()->getValue()), SE);
       // This is strange and shouldn't happen.

Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=70919&r1=70918&r2=70919&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon May  4 17:02:23 2009
@@ -321,7 +321,7 @@
   // for a nested AddRecExpr.
   if (const SCEVAddExpr *AE = dyn_cast<SCEVAddExpr>(SH)) {
     for (unsigned i = 0, e = AE->getNumOperands(); i != e; ++i)
-      if (SCEVAddRecExpr *AddRec =
+      if (const SCEVAddRecExpr *AddRec =
              dyn_cast<SCEVAddRecExpr>(AE->getOperand(i))) {
         if (AddRec->getLoop() == L)
           TheAddRec = SE->getAddExpr(AddRec, TheAddRec);
@@ -1400,8 +1400,8 @@
   // Iterate through the uses to find conditions that automatically rule out
   // full-lsr mode.
   for (unsigned i = 0, e = UsersToProcess.size(); i != e; ) {
-    SCEV *Base = UsersToProcess[i].Base;
-    SCEV *Imm = UsersToProcess[i].Imm;
+    const SCEV *Base = UsersToProcess[i].Base;
+    const SCEV *Imm = UsersToProcess[i].Imm;
     // If any users have a loop-variant component, they can't be fully
     // strength-reduced.
     if (Imm && !Imm->isLoopInvariant(L))
@@ -1410,7 +1410,7 @@
     // the two Imm values can't be folded into the address, full
     // strength reduction would increase register pressure.
     do {
-      SCEV *CurImm = UsersToProcess[i].Imm;
+      const SCEV *CurImm = UsersToProcess[i].Imm;
       if ((CurImm || Imm) && CurImm != Imm) {
         if (!CurImm) CurImm = SE->getIntegerSCEV(0, Stride->getType());
         if (!Imm)       Imm = SE->getIntegerSCEV(0, Stride->getType());





More information about the llvm-commits mailing list