diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index f2112446ade..7e71683dc1a 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -704,8 +704,9 @@ static bool isHighCostExpansion(const SCEV *S, Value *UVal = U->getValue(); for (Value::use_iterator UI = UVal->use_begin(), UE = UVal->use_end(); UI != UE; ++UI) { - Instruction *User = cast(*UI); - if (User->getOpcode() == Instruction::Mul + // If U is a constant, it may be used by a ConstantExpr. + Instruction *User = dyn_cast(*UI); + if (User && User->getOpcode() == Instruction::Mul && SE.isSCEVable(User->getType())) { return SE.getSCEV(User) == Mul; }