@@ -60,6 +60,11 @@ bool RecurrenceDescriptor::isFloatingPointRecurrenceKind(RecurKind Kind) {
60
60
return (Kind != RecurKind::None) && !isIntegerRecurrenceKind (Kind);
61
61
}
62
62
63
+ bool RecurrenceDescriptor::isArithmeticRecurrenceKind (RecurKind Kind) {
64
+ return (Kind != RecurKind::None) && !isMinMaxRecurrenceKind (Kind) &&
65
+ !isAnyOfRecurrenceKind (Kind);
66
+ }
67
+
63
68
// / Determines if Phi may have been type-promoted. If Phi has a single user
64
69
// / that ANDs the Phi with a type mask, return the user. RT is updated to
65
70
// / account for the narrower bit width represented by the mask, and the AND
@@ -1063,7 +1068,7 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
1063
1068
SmallVector<Instruction *, 4 >
1064
1069
RecurrenceDescriptor::getReductionOpChain (PHINode *Phi, Loop *L) const {
1065
1070
SmallVector<Instruction *, 4 > ReductionOperations;
1066
- unsigned RedOp = getOpcode ( );
1071
+ bool IsArithmetic = isArithmeticRecurrenceKind (Kind );
1067
1072
1068
1073
// Search down from the Phi to the LoopExitInstr, looking for instructions
1069
1074
// with a single user of the correct type for the reduction.
@@ -1081,15 +1086,15 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
1081
1086
// more expensive than out-of-loop reductions, and need to be costed more
1082
1087
// carefully.
1083
1088
unsigned ExpectedUses = 1 ;
1084
- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp )
1089
+ if (!IsArithmetic )
1085
1090
ExpectedUses = 2 ;
1086
1091
1087
1092
auto getNextInstruction = [&](Instruction *Cur) -> Instruction * {
1088
1093
for (auto *User : Cur->users ()) {
1089
1094
Instruction *UI = cast<Instruction>(User);
1090
1095
if (isa<PHINode>(UI))
1091
1096
continue ;
1092
- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp ) {
1097
+ if (!IsArithmetic ) {
1093
1098
// We are expecting a icmp/select pair, which we go to the next select
1094
1099
// instruction if we can. We already know that Cur has 2 uses.
1095
1100
if (isa<SelectInst>(UI))
@@ -1101,7 +1106,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
1101
1106
return nullptr ;
1102
1107
};
1103
1108
auto isCorrectOpcode = [&](Instruction *Cur) {
1104
- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp ) {
1109
+ if (!IsArithmetic ) {
1105
1110
Value *LHS, *RHS;
1106
1111
return SelectPatternResult::isMinOrMax (
1107
1112
matchSelectPattern (Cur, LHS, RHS).Flavor );
@@ -1110,7 +1115,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
1110
1115
if (isFMulAddIntrinsic (Cur))
1111
1116
return true ;
1112
1117
1113
- return Cur->getOpcode () == RedOp ;
1118
+ return Cur->getOpcode () == getOpcode () ;
1114
1119
};
1115
1120
1116
1121
// Attempt to look through Phis which are part of the reduction chain
0 commit comments