Index: lib/Analysis/DependenceAnalysis.cpp =================================================================== --- lib/Analysis/DependenceAnalysis.cpp +++ lib/Analysis/DependenceAnalysis.cpp @@ -2256,11 +2256,14 @@ // Given a product, e.g., 10*X*Y, returns the first constant operand, // in this case 10. If there is no constant part, returns NULL. static -const SCEVConstant *getConstantPart(const SCEVMulExpr *Product) { - for (unsigned Op = 0, Ops = Product->getNumOperands(); Op < Ops; Op++) { - if (const SCEVConstant *Constant = dyn_cast(Product->getOperand(Op))) - return Constant; - } +const SCEVConstant *getConstantPart(const SCEV *Expr) { + if (const SCEVConstant *Constant = dyn_cast(Expr)) + return Constant; + else if (const SCEVMulExpr *Product = dyn_cast(Expr)) + for (unsigned Op = 0, Ops = Product->getNumOperands(); Op < Ops; Op++) + if (const SCEVConstant *Constant = + dyn_cast(Product->getOperand(Op))) + return Constant; return nullptr; } @@ -2299,11 +2302,8 @@ while (const SCEVAddRecExpr *AddRec = dyn_cast(Coefficients)) { const SCEV *Coeff = AddRec->getStepRecurrence(*SE); - const SCEVConstant *Constant = dyn_cast(Coeff); - if (const SCEVMulExpr *Product = dyn_cast(Coeff)) - // If the coefficient is the product of a constant and other stuff, - // we can use the constant in the GCD computation. - Constant = getConstantPart(Product); + // we can use the constant in the GCD computation. + const SCEVConstant *Constant = getConstantPart(Coeff); if (!Constant) return false; APInt ConstCoeff = Constant->getAPInt(); @@ -2320,11 +2320,9 @@ while (const SCEVAddRecExpr *AddRec = dyn_cast(Coefficients)) { const SCEV *Coeff = AddRec->getStepRecurrence(*SE); - const SCEVConstant *Constant = dyn_cast(Coeff); - if (const SCEVMulExpr *Product = dyn_cast(Coeff)) - // If the coefficient is the product of a constant and other stuff, - // we can use the constant in the GCD computation. - Constant = getConstantPart(Product); + // If the coefficient is the product of a constant and other stuff, + // we can use the constant in the GCD computation. + const SCEVConstant *Constant = getConstantPart(Coeff); if (!Constant) return false; APInt ConstCoeff = Constant->getAPInt(); @@ -2403,12 +2401,9 @@ if (CurLoop == AddRec->getLoop()) ; // SrcCoeff == Coeff else { - if (const SCEVMulExpr *Product = dyn_cast(Coeff)) - // If the coefficient is the product of a constant and other stuff, - // we can use the constant in the GCD computation. - Constant = getConstantPart(Product); - else - Constant = cast(Coeff); + // If the coefficient is the product of a constant and other stuff, + // we can use the constant in the GCD computation. + Constant = getConstantPart(Coeff); if (!Constant) return false; APInt ConstCoeff = Constant->getAPInt(); @@ -2423,12 +2418,9 @@ if (CurLoop == AddRec->getLoop()) DstCoeff = Coeff; else { - if (const SCEVMulExpr *Product = dyn_cast(Coeff)) - // If the coefficient is the product of a constant and other stuff, - // we can use the constant in the GCD computation. - Constant = getConstantPart(Product); - else - Constant = cast(Coeff); + // If the coefficient is the product of a constant and other stuff, + // we can use the constant in the GCD computation. + Constant = getConstantPart(Coeff); if (!Constant) return false; APInt ConstCoeff = Constant->getAPInt(); @@ -2437,19 +2429,13 @@ Inner = AddRec->getStart(); } Delta = SE->getMinusSCEV(SrcCoeff, DstCoeff); - if (const SCEVMulExpr *Product = dyn_cast(Delta)) - // If the coefficient is the product of a constant and other stuff, - // we can use the constant in the GCD computation. - Constant = getConstantPart(Product); - else if (isa(Delta)) - Constant = cast(Delta); - else { + // If the coefficient is the product of a constant and other stuff, + // we can use the constant in the GCD computation. + Constant = getConstantPart(Delta); + if (!Constant) // The difference of the two coefficients might not be a product // or constant, in which case we give up on this direction. continue; - } - if (!Constant) - continue; APInt ConstCoeff = Constant->getAPInt(); RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs()); DEBUG(dbgs() << "\tRunningGCD = " << RunningGCD << "\n");