diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 03966672d623..dac734029b4a 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -2116,6 +2116,11 @@ ICmpInst *LoopStrengthReduce::OptimizeSMax(Loop *L, ICmpInst *Cond, const SCEVSMaxExpr *SMax = dyn_cast(IterationCount); if (!SMax || SMax != SE->getSCEV(Sel)) return Cond; + // Two handle a max with more than two operands, this optimization would + // require additional checking and setup. + if (SMax->getNumOperands() != 2) + return Cond; + SCEVHandle SMaxLHS = SMax->getOperand(0); SCEVHandle SMaxRHS = SMax->getOperand(1); if (!SMaxLHS || SMaxLHS != One) return Cond;