diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index ddce7511042..9a9b0c2aeca 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -483,8 +483,7 @@ static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress) { if (isTargetConstant(Val)) return Val; - SCEVAddExpr *SAE = dyn_cast(Val); - if (SAE) { + if (SCEVAddExpr *SAE = dyn_cast(Val)) { unsigned i = 0; for (; i != SAE->getNumOperands(); ++i) if (isTargetConstant(SAE->getOperand(i))) { @@ -497,6 +496,9 @@ static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress) { ImmVal = SCEVAddExpr::get(ImmVal, SAE->getOperand(i)); return ImmVal; } + } else if (SCEVAddRecExpr *SARE = dyn_cast(Val)) { + // Try to pull immediates out of the start value of nested addrec's. + return GetImmediateValues(SARE->getStart(), isAddress); } return SCEVUnknown::getIntegerSCEV(0, Val->getType());