@@ -62,6 +62,11 @@ bool RecurrenceDescriptor::isFloatingPointRecurrenceKind(RecurKind Kind) {
6262 return (Kind != RecurKind::None) && !isIntegerRecurrenceKind (Kind);
6363}
6464
65+ bool RecurrenceDescriptor::isArithmeticRecurrenceKind (RecurKind Kind) {
66+ return (Kind != RecurKind::None) && !isMinMaxRecurrenceKind (Kind) &&
67+ !isAnyOfRecurrenceKind (Kind);
68+ }
69+
6570// / Determines if Phi may have been type-promoted. If Phi has a single user
6671// / that ANDs the Phi with a type mask, return the user. RT is updated to
6772// / account for the narrower bit width represented by the mask, and the AND
@@ -1166,7 +1171,7 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
11661171SmallVector<Instruction *, 4 >
11671172RecurrenceDescriptor::getReductionOpChain (PHINode *Phi, Loop *L) const {
11681173 SmallVector<Instruction *, 4 > ReductionOperations;
1169- unsigned RedOp = getOpcode ( );
1174+ bool IsArithmetic = isArithmeticRecurrenceKind (Kind );
11701175
11711176 // Search down from the Phi to the LoopExitInstr, looking for instructions
11721177 // with a single user of the correct type for the reduction.
@@ -1184,15 +1189,15 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
11841189 // more expensive than out-of-loop reductions, and need to be costed more
11851190 // carefully.
11861191 unsigned ExpectedUses = 1 ;
1187- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp )
1192+ if (!IsArithmetic )
11881193 ExpectedUses = 2 ;
11891194
11901195 auto getNextInstruction = [&](Instruction *Cur) -> Instruction * {
11911196 for (auto *User : Cur->users ()) {
11921197 Instruction *UI = cast<Instruction>(User);
11931198 if (isa<PHINode>(UI))
11941199 continue ;
1195- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp ) {
1200+ if (!IsArithmetic ) {
11961201 // We are expecting a icmp/select pair, which we go to the next select
11971202 // instruction if we can. We already know that Cur has 2 uses.
11981203 if (isa<SelectInst>(UI))
@@ -1204,7 +1209,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
12041209 return nullptr ;
12051210 };
12061211 auto isCorrectOpcode = [&](Instruction *Cur) {
1207- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp ) {
1212+ if (!IsArithmetic ) {
12081213 Value *LHS, *RHS;
12091214 return SelectPatternResult::isMinOrMax (
12101215 matchSelectPattern (Cur, LHS, RHS).Flavor );
@@ -1213,7 +1218,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
12131218 if (isFMulAddIntrinsic (Cur))
12141219 return true ;
12151220
1216- return Cur->getOpcode () == RedOp ;
1221+ return Cur->getOpcode () == getOpcode () ;
12171222 };
12181223
12191224 // Attempt to look through Phis which are part of the reduction chain
0 commit comments