Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -6178,15 +6178,17 @@ // Some DVIs that were single location-op when cached are now multi-op, // due to LSR optimisations. However, multi-op salvaging is not yet // supported by SCEV salvaging. But, we can attempt a salvage by restoring - // the pre-LSR single-op expression. + // the pre-LSR single-op location and expression. if (DVIRec.DVI->hasArgList()) { if (!DVIRec.DVI->getVariableLocationOp(0)) continue; llvm::Type *Ty = DVIRec.DVI->getVariableLocationOp(0)->getType(); DVIRec.DVI->setRawLocation( llvm::ValueAsMetadata::get(UndefValue::get(Ty))); - DVIRec.DVI->setExpression(DVIRec.Expr); } + // LSR may have updated the expression, so restore to the expression + // that corresponds to te cached SCEV. + DVIRec.DVI->setExpression(DVIRec.Expr); Changed |= RewriteDVIUsingIterCount(DVIRec, IterCountExpr, SE); }