-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[VPlan] Clean up the function VPInstruction::generate for ComputeReductionResult, nfc #140245
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Mel Chen (Mel-Chen) ChangesWhen reducing unrolled parts, explicitly check for min/max reductions using the function RecurrenceDescriptor::isMinMaxRecurrenceKind. Only if the reduction is not min/max reduction, call RecurrenceDescriptor::getOpcode() to handle other cases via CreateBinOp. Based on #140242 Full diff: https://github.com/llvm/llvm-project/pull/140245.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index a216b0347b9fa..a273338670164 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -1154,6 +1154,8 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
return Instruction::Add;
case RecurKind::Mul:
return Instruction::Mul;
+ case RecurKind::IAnyOf:
+ case RecurKind::FAnyOf:
case RecurKind::Or:
return Instruction::Or;
case RecurKind::And:
@@ -1169,7 +1171,6 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
case RecurKind::SMin:
case RecurKind::UMax:
case RecurKind::UMin:
- case RecurKind::IAnyOf:
case RecurKind::IFindLastIV:
return Instruction::ICmp;
case RecurKind::FMax:
@@ -1178,7 +1179,6 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
case RecurKind::FMinimum:
case RecurKind::FMaximumNum:
case RecurKind::FMinimumNum:
- case RecurKind::FAnyOf:
case RecurKind::FFindLastIV:
return Instruction::FCmp;
default:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index fc1ee89e81c75..845db83c6a8a3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -678,10 +678,6 @@ Value *VPInstruction::generate(VPTransformState &State) {
}
// Reduce all of the unrolled parts into a single vector.
Value *ReducedPartRdx = RdxParts[0];
- unsigned Op = RdxDesc.getOpcode();
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
- Op = Instruction::Or;
-
if (PhiR->isOrdered()) {
ReducedPartRdx = RdxParts[UF - 1];
} else {
@@ -690,11 +686,12 @@ Value *VPInstruction::generate(VPTransformState &State) {
Builder.setFastMathFlags(RdxDesc.getFastMathFlags());
for (unsigned Part = 1; Part < UF; ++Part) {
Value *RdxPart = RdxParts[Part];
- if (Op != Instruction::ICmp && Op != Instruction::FCmp)
- ReducedPartRdx = Builder.CreateBinOp(
- (Instruction::BinaryOps)Op, RdxPart, ReducedPartRdx, "bin.rdx");
- else
+ if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RK))
ReducedPartRdx = createMinMaxOp(Builder, RK, ReducedPartRdx, RdxPart);
+ else
+ ReducedPartRdx =
+ Builder.CreateBinOp((Instruction::BinaryOps)RdxDesc.getOpcode(),
+ RdxPart, ReducedPartRdx, "bin.rdx");
}
}
|
@llvm/pr-subscribers-llvm-analysis Author: Mel Chen (Mel-Chen) ChangesWhen reducing unrolled parts, explicitly check for min/max reductions using the function RecurrenceDescriptor::isMinMaxRecurrenceKind. Only if the reduction is not min/max reduction, call RecurrenceDescriptor::getOpcode() to handle other cases via CreateBinOp. Based on #140242 Full diff: https://github.com/llvm/llvm-project/pull/140245.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index a216b0347b9fa..a273338670164 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -1154,6 +1154,8 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
return Instruction::Add;
case RecurKind::Mul:
return Instruction::Mul;
+ case RecurKind::IAnyOf:
+ case RecurKind::FAnyOf:
case RecurKind::Or:
return Instruction::Or;
case RecurKind::And:
@@ -1169,7 +1171,6 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
case RecurKind::SMin:
case RecurKind::UMax:
case RecurKind::UMin:
- case RecurKind::IAnyOf:
case RecurKind::IFindLastIV:
return Instruction::ICmp;
case RecurKind::FMax:
@@ -1178,7 +1179,6 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
case RecurKind::FMinimum:
case RecurKind::FMaximumNum:
case RecurKind::FMinimumNum:
- case RecurKind::FAnyOf:
case RecurKind::FFindLastIV:
return Instruction::FCmp;
default:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index fc1ee89e81c75..845db83c6a8a3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -678,10 +678,6 @@ Value *VPInstruction::generate(VPTransformState &State) {
}
// Reduce all of the unrolled parts into a single vector.
Value *ReducedPartRdx = RdxParts[0];
- unsigned Op = RdxDesc.getOpcode();
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
- Op = Instruction::Or;
-
if (PhiR->isOrdered()) {
ReducedPartRdx = RdxParts[UF - 1];
} else {
@@ -690,11 +686,12 @@ Value *VPInstruction::generate(VPTransformState &State) {
Builder.setFastMathFlags(RdxDesc.getFastMathFlags());
for (unsigned Part = 1; Part < UF; ++Part) {
Value *RdxPart = RdxParts[Part];
- if (Op != Instruction::ICmp && Op != Instruction::FCmp)
- ReducedPartRdx = Builder.CreateBinOp(
- (Instruction::BinaryOps)Op, RdxPart, ReducedPartRdx, "bin.rdx");
- else
+ if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RK))
ReducedPartRdx = createMinMaxOp(Builder, RK, ReducedPartRdx, RdxPart);
+ else
+ ReducedPartRdx =
+ Builder.CreateBinOp((Instruction::BinaryOps)RdxDesc.getOpcode(),
+ RdxPart, ReducedPartRdx, "bin.rdx");
}
}
|
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!
When reducing unrolled parts, explicitly check for min/max reductions using the function RecurrenceDescriptor::isMinMaxRecurrenceKind. Only if the reduction is not min/max reduction, call RecurrenceDescriptor::getOpcode() to handle other cases via CreateBinOp.
Based on #140242
Related to #118393