-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[IVDescriptor] Explicitly check for isMinMaxRecurrenceKind in getReductionOpChain. NFC #132025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ctionOpChain. NFC 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 llvm#131830 easier. Note that these currently fail the ExpectedUses/isCorrectOpcode checks anyway, so there shouldn't be any functional change.
@llvm/pr-subscribers-llvm-analysis Author: Luke Lau (lukel97) ChangesThere are other types of recurrences with an icmp/fcmp opcode, AnyOf and FindLastIV, so don't rely on the opcode to detect them. Note that these currently fail the ExpectedUses/isCorrectOpcode checks anyway, so there shouldn't be any functional change. Full diff: https://github.com/llvm/llvm-project/pull/132025.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index f74ede4450ce5..0b7f32e55faa5 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -1184,7 +1184,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 (isMinMaxRecurrenceKind(Kind))
ExpectedUses = 2;
auto getNextInstruction = [&](Instruction *Cur) -> Instruction * {
@@ -1192,7 +1192,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
Instruction *UI = cast<Instruction>(User);
if (isa<PHINode>(UI))
continue;
- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp) {
+ if (isMinMaxRecurrenceKind(Kind)) {
// 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<SelectInst>(UI))
@@ -1204,7 +1204,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
return nullptr;
};
auto isCorrectOpcode = [&](Instruction *Cur) {
- if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp) {
+ if (isMinMaxRecurrenceKind(Kind)) {
Value *LHS, *RHS;
return SelectPatternResult::isMinOrMax(
matchSelectPattern(Cur, LHS, RHS).Flavor);
|
llvm/lib/Analysis/IVDescriptors.cpp
Outdated
@@ -1184,15 +1184,15 @@ 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 (isMinMaxRecurrenceKind(Kind)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of recalculating this each time, is it perhaps better to calculate it once and store it in a variable for reuse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please address David's comment before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
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.