Skip to content

Commit 345748e

Browse files
authored
[IVDescriptor] Explicitly check for isMinMaxRecurrenceKind in getReductionOpChain. NFC (#132025)
There are other types of recurrences with an icmp/fcmp opcode, AnyOf and FindLastIV, so don't rely on the opcode to detect them. This makes adding support for AnyOf in #131830 easier. Note that these currently fail the ExpectedUses/isCorrectOpcode checks anyway, so there shouldn't be any functional change.
1 parent 73558dc commit 345748e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@ SmallVector<Instruction *, 4>
11671167
RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
11681168
SmallVector<Instruction *, 4> ReductionOperations;
11691169
unsigned RedOp = getOpcode();
1170+
const bool IsMinMax = isMinMaxRecurrenceKind(Kind);
11701171

11711172
// Search down from the Phi to the LoopExitInstr, looking for instructions
11721173
// with a single user of the correct type for the reduction.
@@ -1184,15 +1185,15 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
11841185
// more expensive than out-of-loop reductions, and need to be costed more
11851186
// carefully.
11861187
unsigned ExpectedUses = 1;
1187-
if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp)
1188+
if (IsMinMax)
11881189
ExpectedUses = 2;
11891190

11901191
auto getNextInstruction = [&](Instruction *Cur) -> Instruction * {
11911192
for (auto *User : Cur->users()) {
11921193
Instruction *UI = cast<Instruction>(User);
11931194
if (isa<PHINode>(UI))
11941195
continue;
1195-
if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp) {
1196+
if (IsMinMax) {
11961197
// We are expecting a icmp/select pair, which we go to the next select
11971198
// instruction if we can. We already know that Cur has 2 uses.
11981199
if (isa<SelectInst>(UI))
@@ -1204,7 +1205,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
12041205
return nullptr;
12051206
};
12061207
auto isCorrectOpcode = [&](Instruction *Cur) {
1207-
if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp) {
1208+
if (IsMinMax) {
12081209
Value *LHS, *RHS;
12091210
return SelectPatternResult::isMinOrMax(
12101211
matchSelectPattern(Cur, LHS, RHS).Flavor);

0 commit comments

Comments
 (0)