diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp index f74ede4450ce5..45b5b2979a562 100644 --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -1167,6 +1167,7 @@ SmallVector RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const { SmallVector ReductionOperations; unsigned RedOp = getOpcode(); + const bool IsMinMax = isMinMaxRecurrenceKind(Kind); // Search down from the Phi to the LoopExitInstr, looking for instructions // with a single user of the correct type for the reduction. @@ -1184,7 +1185,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const { // more expensive than out-of-loop reductions, and need to be costed more // carefully. unsigned ExpectedUses = 1; - if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp) + if (IsMinMax) ExpectedUses = 2; auto getNextInstruction = [&](Instruction *Cur) -> Instruction * { @@ -1192,7 +1193,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const { Instruction *UI = cast(User); if (isa(UI)) continue; - if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp) { + if (IsMinMax) { // We are expecting a icmp/select pair, which we go to the next select // instruction if we can. We already know that Cur has 2 uses. if (isa(UI)) @@ -1204,7 +1205,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const { return nullptr; }; auto isCorrectOpcode = [&](Instruction *Cur) { - if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp) { + if (IsMinMax) { Value *LHS, *RHS; return SelectPatternResult::isMinOrMax( matchSelectPattern(Cur, LHS, RHS).Flavor);