From 622ed671b90d449496d582b3a03c7aad1e98324a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 4 May 2009 22:02:23 +0000 Subject: [PATCH] Constify a bunch of SCEV-using code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70919 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 120 ++++++++++++++------------- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 8 +- 2 files changed, 65 insertions(+), 63 deletions(-) diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index a6d39541aae..c29ea3e09df 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -650,25 +650,25 @@ SCEVHandle ScalarEvolution::getTruncateExpr(const SCEVHandle &Op, "This is not a conversion to a SCEVable type!"); Ty = getEffectiveSCEVType(Ty); - if (SCEVConstant *SC = dyn_cast(Op)) + if (const SCEVConstant *SC = dyn_cast(Op)) return getUnknown( ConstantExpr::getTrunc(SC->getValue(), Ty)); // trunc(trunc(x)) --> trunc(x) - if (SCEVTruncateExpr *ST = dyn_cast(Op)) + if (const SCEVTruncateExpr *ST = dyn_cast(Op)) return getTruncateExpr(ST->getOperand(), Ty); // trunc(sext(x)) --> sext(x) if widening or trunc(x) if narrowing - if (SCEVSignExtendExpr *SS = dyn_cast(Op)) + if (const SCEVSignExtendExpr *SS = dyn_cast(Op)) return getTruncateOrSignExtend(SS->getOperand(), Ty); // trunc(zext(x)) --> zext(x) if widening or trunc(x) if narrowing - if (SCEVZeroExtendExpr *SZ = dyn_cast(Op)) + if (const SCEVZeroExtendExpr *SZ = dyn_cast(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(Op)) { + if (const SCEVAddRecExpr *AddRec = dyn_cast(Op)) { std::vector Operands; for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i) // FIXME: This should allow truncation of other expression types! @@ -693,7 +693,7 @@ SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op, "This is not a conversion to a SCEVable type!"); Ty = getEffectiveSCEVType(Ty); - if (SCEVConstant *SC = dyn_cast(Op)) { + if (const SCEVConstant *SC = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op, } // zext(zext(x)) --> zext(x) - if (SCEVZeroExtendExpr *SZ = dyn_cast(Op)) + if (const SCEVZeroExtendExpr *SZ = dyn_cast(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(Op)) + if (const SCEVAddRecExpr *AR = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getSignExtendExpr(const SCEVHandle &Op, "This is not a conversion to a SCEVable type!"); Ty = getEffectiveSCEVType(Ty); - if (SCEVConstant *SC = dyn_cast(Op)) { + if (const SCEVConstant *SC = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getSignExtendExpr(const SCEVHandle &Op, } // sext(sext(x)) --> sext(x) - if (SCEVSignExtendExpr *SS = dyn_cast(Op)) + if (const SCEVSignExtendExpr *SS = dyn_cast(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(Op)) + if (const SCEVAddRecExpr *AR = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector &Ops) { // If there are any constants, fold them together. unsigned Idx = 0; - if (SCEVConstant *LHSC = dyn_cast(Ops[0])) { + if (const SCEVConstant *LHSC = dyn_cast(Ops[0])) { ++Idx; assert(Idx < Ops.size()); - while (SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { + while (const SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { // We found two constants, fold them together! ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() + RHSC->getValue()->getValue()); @@ -896,7 +896,7 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector &Ops) { // If there are add operands they would be next. if (Idx < Ops.size()) { bool DeletedAdd = false; - while (SCEVAddExpr *Add = dyn_cast(Ops[Idx])) { + while (const SCEVAddExpr *Add = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector &Ops) { // If there are any constants, fold them together. unsigned Idx = 0; - if (SCEVConstant *LHSC = dyn_cast(Ops[0])) { + if (const SCEVConstant *LHSC = dyn_cast(Ops[0])) { // C1*(C2+V) -> C1*C2 + C1*V if (Ops.size() == 2) - if (SCEVAddExpr *Add = dyn_cast(Ops[1])) + if (const SCEVAddExpr *Add = dyn_cast(Ops[1])) if (Add->getNumOperands() == 2 && isa(Add->getOperand(0))) return getAddExpr(getMulExpr(LHSC, Add->getOperand(0)), @@ -1087,7 +1087,7 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector &Ops) { ++Idx; - while (SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { + while (const SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { // We found two constants, fold them together! ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() * RHSC->getValue()->getValue()); @@ -1117,7 +1117,7 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector &Ops) { // If there are mul operands inline them all into this expression. if (Idx < Ops.size()) { bool DeletedMul = false; - while (SCEVMulExpr *Mul = dyn_cast(Ops[Idx])) { + while (const SCEVMulExpr *Mul = dyn_cast(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::getMulExpr(std::vector &Ops) { } SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS, const SCEVHandle &RHS) { - if (SCEVConstant *RHSC = dyn_cast(RHS)) { + if (const SCEVConstant *RHSC = dyn_cast(RHS)) { if (RHSC->getValue()->equalsInt(1)) return LHS; // X udiv 1 --> x - if (SCEVConstant *LHSC = dyn_cast(LHS)) { + if (const SCEVConstant *LHSC = dyn_cast(LHS)) { Constant *LHSCV = LHSC->getValue(); Constant *RHSCV = RHSC->getValue(); return getUnknown(ConstantExpr::getUDiv(LHSCV, RHSCV)); @@ -1250,7 +1250,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(const SCEVHandle &Start, const SCEVHandle &Step, const Loop *L) { std::vector Operands; Operands.push_back(Start); - if (SCEVAddRecExpr *StepChrec = dyn_cast(Step)) + if (const SCEVAddRecExpr *StepChrec = dyn_cast(Step)) if (StepChrec->getLoop() == L) { Operands.insert(Operands.end(), StepChrec->op_begin(), StepChrec->op_end()); @@ -1273,7 +1273,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(std::vector &Operands, } // Canonicalize nested AddRecs in by nesting them in order of loop depth. - if (SCEVAddRecExpr *NestedAR = dyn_cast(Operands[0])) { + if (const SCEVAddRecExpr *NestedAR = dyn_cast(Operands[0])) { const Loop* NestedLoop = NestedAR->getLoop(); if (L->getLoopDepth() < NestedLoop->getLoopDepth()) { std::vector NestedOperands(NestedAR->op_begin(), @@ -1309,10 +1309,10 @@ SCEVHandle ScalarEvolution::getSMaxExpr(std::vector Ops) { // If there are any constants, fold them together. unsigned Idx = 0; - if (SCEVConstant *LHSC = dyn_cast(Ops[0])) { + if (const SCEVConstant *LHSC = dyn_cast(Ops[0])) { ++Idx; assert(Idx < Ops.size()); - while (SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { + while (const SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { // We found two constants, fold them together! ConstantInt *Fold = ConstantInt::get( APIntOps::smax(LHSC->getValue()->getValue(), @@ -1340,7 +1340,7 @@ SCEVHandle ScalarEvolution::getSMaxExpr(std::vector Ops) { // onto our operand list, and recurse to simplify. if (Idx < Ops.size()) { bool DeletedSMax = false; - while (SCEVSMaxExpr *SMax = dyn_cast(Ops[Idx])) { + while (const SCEVSMaxExpr *SMax = dyn_cast(Ops[Idx])) { Ops.insert(Ops.end(), SMax->op_begin(), SMax->op_end()); Ops.erase(Ops.begin()+Idx); DeletedSMax = true; @@ -1389,10 +1389,10 @@ SCEVHandle ScalarEvolution::getUMaxExpr(std::vector Ops) { // If there are any constants, fold them together. unsigned Idx = 0; - if (SCEVConstant *LHSC = dyn_cast(Ops[0])) { + if (const SCEVConstant *LHSC = dyn_cast(Ops[0])) { ++Idx; assert(Idx < Ops.size()); - while (SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { + while (const SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { // We found two constants, fold them together! ConstantInt *Fold = ConstantInt::get( APIntOps::umax(LHSC->getValue()->getValue(), @@ -1420,7 +1420,7 @@ SCEVHandle ScalarEvolution::getUMaxExpr(std::vector Ops) { // onto our operand list, and recurse to simplify. if (Idx < Ops.size()) { bool DeletedUMax = false; - while (SCEVUMaxExpr *UMax = dyn_cast(Ops[Idx])) { + while (const SCEVUMaxExpr *UMax = dyn_cast(Ops[Idx])) { Ops.insert(Ops.end(), UMax->op_begin(), UMax->op_end()); Ops.erase(Ops.begin()+Idx); DeletedUMax = true; @@ -1580,7 +1580,7 @@ SCEVHandle ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) { /// getNegativeSCEV - Return a SCEV corresponding to -V = -1*V /// SCEVHandle ScalarEvolution::getNegativeSCEV(const SCEVHandle &V) { - if (SCEVConstant *VC = dyn_cast(V)) + if (const SCEVConstant *VC = dyn_cast(V)) return getUnknown(ConstantExpr::getNeg(VC->getValue())); const Type *Ty = V->getType(); @@ -1590,7 +1590,7 @@ SCEVHandle ScalarEvolution::getNegativeSCEV(const SCEVHandle &V) { /// getNotSCEV - Return a SCEV corresponding to ~V = -1-V SCEVHandle ScalarEvolution::getNotSCEV(const SCEVHandle &V) { - if (SCEVConstant *VC = dyn_cast(V)) + if (const SCEVConstant *VC = dyn_cast(V)) return getUnknown(ConstantExpr::getNot(VC->getValue())); const Type *Ty = V->getType(); @@ -1690,7 +1690,7 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) { // 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(BEValue)) { + if (const SCEVAddExpr *Add = dyn_cast(BEValue)) { // If there is a single occurrence of the symbolic value, replace it // with a recurrence. unsigned FoundIndex = Add->getNumOperands(); @@ -1726,7 +1726,8 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) { return PHISCEV; } } - } else if (SCEVAddRecExpr *AddRec = dyn_cast(BEValue)) { + } else if (const SCEVAddRecExpr *AddRec = + dyn_cast(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 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) { /// 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(S)) + if (const SCEVConstant *C = dyn_cast(S)) return C->getValue()->getValue().countTrailingZeros(); - if (SCEVTruncateExpr *T = dyn_cast(S)) + if (const SCEVTruncateExpr *T = dyn_cast(S)) return std::min(GetMinTrailingZeros(T->getOperand(), SE), (uint32_t)SE.getTypeSizeInBits(T->getType())); - if (SCEVZeroExtendExpr *E = dyn_cast(S)) { + if (const SCEVZeroExtendExpr *E = dyn_cast(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(S)) { + if (const SCEVSignExtendExpr *E = dyn_cast(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(S)) { + if (const SCEVAddExpr *A = dyn_cast(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 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) { return MinOpRes; } - if (SCEVMulExpr *M = dyn_cast(S)) { + if (const SCEVMulExpr *M = dyn_cast(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 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) { return SumOpRes; } - if (SCEVAddRecExpr *A = dyn_cast(S)) { + if (const SCEVAddRecExpr *A = dyn_cast(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 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) { return MinOpRes; } - if (SCEVSMaxExpr *M = dyn_cast(S)) { + if (const SCEVSMaxExpr *M = dyn_cast(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 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) { return MinOpRes; } - if (SCEVUMaxExpr *M = dyn_cast(S)) { + if (const SCEVUMaxExpr *M = dyn_cast(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 @@ ScalarEvolution::ComputeBackedgeTakenCount(const Loop *L) { // 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(RHS)) - if (SCEVAddRecExpr *AddRec = dyn_cast(LHS)) + if (const SCEVConstant *RHSC = dyn_cast(RHS)) + if (const SCEVAddRecExpr *AddRec = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { // 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(V)) { + if (const SCEVUnknown *SU = dyn_cast(V)) { if (Instruction *I = dyn_cast(SU->getValue())) { const Loop *LI = (*this->LI)[I->getParent()]; if (LI && LI->getParentLoop() == L) // Looking for loop exit value. @@ -2621,7 +2622,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { // 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(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 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { return V; SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L); - if (SCEVConstant *SC = dyn_cast(OpV)) { + if (const SCEVConstant *SC = dyn_cast(OpV)) { Constant *C = SC->getValue(); if (C->getType() != Op->getType()) C = ConstantExpr::getCast(CastInst::getCastOpcode(C, false, @@ -2660,7 +2661,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { false), C, Op->getType()); Operands.push_back(C); - } else if (SCEVUnknown *SU = dyn_cast(OpV)) { + } else if (const SCEVUnknown *SU = dyn_cast(OpV)) { if (Constant *C = dyn_cast(SU->getValue())) { if (C->getType() != Op->getType()) C = @@ -2692,7 +2693,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { return V; } - if (SCEVCommutativeExpr *Comm = dyn_cast(V)) { + if (const SCEVCommutativeExpr *Comm = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { return Comm; } - if (SCEVUDivExpr *Div = dyn_cast(V)) { + if (const SCEVUDivExpr *Div = dyn_cast(V)) { SCEVHandle LHS = getSCEVAtScope(Div->getLHS(), L); if (LHS == UnknownValue) return LHS; SCEVHandle RHS = getSCEVAtScope(Div->getRHS(), L); @@ -2736,7 +2737,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { // 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(V)) { + if (const SCEVAddRecExpr *AddRec = dyn_cast(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 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { return UnknownValue; } - if (SCEVZeroExtendExpr *Cast = dyn_cast(V)) { + if (const SCEVZeroExtendExpr *Cast = dyn_cast(V)) { SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L); if (Op == UnknownValue) return Op; if (Op == Cast->getOperand()) @@ -2757,7 +2758,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { return getZeroExtendExpr(Op, Cast->getType()); } - if (SCEVSignExtendExpr *Cast = dyn_cast(V)) { + if (const SCEVSignExtendExpr *Cast = dyn_cast(V)) { SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L); if (Op == UnknownValue) return Op; if (Op == Cast->getOperand()) @@ -2765,7 +2766,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) { return getSignExtendExpr(Op, Cast->getType()); } - if (SCEVTruncateExpr *Cast = dyn_cast(V)) { + if (const SCEVTruncateExpr *Cast = dyn_cast(V)) { SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L); if (Op == UnknownValue) return Op; if (Op == Cast->getOperand()) @@ -2903,7 +2904,7 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) { /// 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(V)) { + if (const SCEVConstant *C = dyn_cast(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 ScalarEvolution::HowFarToZero(SCEV *V, const Loop *L) { SCEVHandle Step = getSCEVAtScope(AddRec->getOperand(1), L->getParentLoop()); - if (SCEVConstant *StepC = dyn_cast(Step)) { + if (const SCEVConstant *StepC = dyn_cast(Step)) { // For now we handle only constant steps. // First, handle unitary steps. @@ -2941,7 +2942,7 @@ SCEVHandle ScalarEvolution::HowFarToZero(SCEV *V, const Loop *L) { return Start; // N = Start (as unsigned) // Then, try to solve the above equation provided that Start is constant. - if (SCEVConstant *StartC = dyn_cast(Start)) + if (const SCEVConstant *StartC = dyn_cast(Start)) return SolveLinEquationWithOverflow(StepC->getValue()->getValue(), -StartC->getValue()->getValue(), *this); @@ -2988,7 +2989,7 @@ SCEVHandle ScalarEvolution::HowFarToNonZero(SCEV *V, const Loop *L) { // 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(V)) { + if (const SCEVConstant *C = dyn_cast(V)) { if (!C->getValue()->isNullValue()) return getIntegerSCEV(0, C->getType()); return UnknownValue; // Otherwise it will loop infinitely. @@ -3232,12 +3233,13 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, return SE.getCouldNotCompute(); // If the start is a non-zero constant, shift the range to simplify things. - if (SCEVConstant *SC = dyn_cast(getStart())) + if (const SCEVConstant *SC = dyn_cast(getStart())) if (!SC->getValue()->isZero()) { std::vector Operands(op_begin(), op_end()); Operands[0] = SE.getIntegerSCEV(0, SC->getType()); SCEVHandle Shifted = SE.getAddRecExpr(Operands, getLoop()); - if (SCEVAddRecExpr *ShiftedAddRec = dyn_cast(Shifted)) + if (const SCEVAddRecExpr *ShiftedAddRec = + dyn_cast(Shifted)) return ShiftedAddRec->getNumIterationsInRange( Range.subtract(SC->getValue()->getValue()), SE); // This is strange and shouldn't happen. diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index b9406651525..50603d97578 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -321,7 +321,7 @@ static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L, // for a nested AddRecExpr. if (const SCEVAddExpr *AE = dyn_cast(SH)) { for (unsigned i = 0, e = AE->getNumOperands(); i != e; ++i) - if (SCEVAddRecExpr *AddRec = + if (const SCEVAddRecExpr *AddRec = dyn_cast(AE->getOperand(i))) { if (AddRec->getLoop() == L) TheAddRec = SE->getAddExpr(AddRec, TheAddRec); @@ -1400,8 +1400,8 @@ bool LoopStrengthReduce::ShouldUseFullStrengthReductionMode( // 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 @@ bool LoopStrengthReduce::ShouldUseFullStrengthReductionMode( // 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()); -- 2.11.0