@@ -60,6 +60,11 @@ bool RecurrenceDescriptor::isFloatingPointRecurrenceKind(RecurKind Kind) {
6060 return (Kind != RecurKind::None) && !isIntegerRecurrenceKind (Kind);
6161}
6262
63+ bool RecurrenceDescriptor::isArithmeticRecurrenceKind (RecurKind Kind) {
64+ return (Kind != RecurKind::None) && !isMinMaxRecurrenceKind (Kind) &&
65+ !isAnyOfRecurrenceKind (Kind);
66+ }
67+
6368// / Determines if Phi may have been type-promoted. If Phi has a single user
6469// / that ANDs the Phi with a type mask, return the user. RT is updated to
6570// / account for the narrower bit width represented by the mask, and the AND
@@ -1063,7 +1068,7 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
10631068SmallVector<Instruction *, 4 >
10641069RecurrenceDescriptor::getReductionOpChain (PHINode *Phi, Loop *L) const {
10651070 SmallVector<Instruction *, 4 > ReductionOperations;
1066- unsigned RedOp = getOpcode ( );
1071+ bool IsArithmetic = isArithmeticRecurrenceKind (Kind );
10671072
10681073 // Search down from the Phi to the LoopExitInstr, looking for instructions
10691074 // with a single user of the correct type for the reduction.
@@ -1081,15 +1086,15 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
10811086 // more expensive than out-of-loop reductions, and need to be costed more
10821087 // carefully.
10831088 unsigned ExpectedUses = 1 ;
1084- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp )
1089+ if (!IsArithmetic )
10851090 ExpectedUses = 2 ;
10861091
10871092 auto getNextInstruction = [&](Instruction *Cur) -> Instruction * {
10881093 for (auto *User : Cur->users ()) {
10891094 Instruction *UI = cast<Instruction>(User);
10901095 if (isa<PHINode>(UI))
10911096 continue ;
1092- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp ) {
1097+ if (!IsArithmetic ) {
10931098 // We are expecting a icmp/select pair, which we go to the next select
10941099 // instruction if we can. We already know that Cur has 2 uses.
10951100 if (isa<SelectInst>(UI))
@@ -1101,7 +1106,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
11011106 return nullptr ;
11021107 };
11031108 auto isCorrectOpcode = [&](Instruction *Cur) {
1104- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp ) {
1109+ if (!IsArithmetic ) {
11051110 Value *LHS, *RHS;
11061111 return SelectPatternResult::isMinOrMax (
11071112 matchSelectPattern (Cur, LHS, RHS).Flavor );
@@ -1110,7 +1115,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
11101115 if (isFMulAddIntrinsic (Cur))
11111116 return true ;
11121117
1113- return Cur->getOpcode () == RedOp ;
1118+ return Cur->getOpcode () == getOpcode () ;
11141119 };
11151120
11161121 // Attempt to look through Phis which are part of the reduction chain
0 commit comments