aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2024-09-25 14:13:49 +0100
committerFlorian Hahn <flo@fhahn.com>2024-09-25 14:13:50 +0100
commit4be1c19a9fbdff02044cd46b703c842bb7a6afdb (patch)
treed356056ef653068f4e2f282a3a6aa648ed3a2f00
parentfd88121a58da87bf0c5f3e4d8434948c28722640 (diff)
downloadllvm-4be1c19a9fbdff02044cd46b703c842bb7a6afdb.zip
llvm-4be1c19a9fbdff02044cd46b703c842bb7a6afdb.tar.gz
llvm-4be1c19a9fbdff02044cd46b703c842bb7a6afdb.tar.bz2
[VPlan] Adjust AnyOf after creating ComputeReductionResult (NFC).
Prepares for a follow-up change to use VPInstruction::ResumePhi to create the resume phi for reductions.
-rw-r--r--llvm/lib/Transforms/Vectorize/LoopVectorize.cpp70
1 files changed, 35 insertions, 35 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 5e4f33c..6298c54 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9294,41 +9294,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
continue;
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
- // Adjust AnyOf reductions; replace the reduction phi for the selected value
- // with a boolean reduction phi node to check if the condition is true in
- // any iteration. The final value is selected by the final
- // ComputeReductionResult.
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
- RdxDesc.getRecurrenceKind())) {
- auto *Select = cast<VPRecipeBase>(*find_if(PhiR->users(), [](VPUser *U) {
- return isa<VPWidenSelectRecipe>(U) ||
- (isa<VPReplicateRecipe>(U) &&
- cast<VPReplicateRecipe>(U)->getUnderlyingInstr()->getOpcode() ==
- Instruction::Select);
- }));
- VPValue *Cmp = Select->getOperand(0);
- // If the compare is checking the reduction PHI node, adjust it to check
- // the start value.
- if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
- for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
- if (CmpR->getOperand(I) == PhiR)
- CmpR->setOperand(I, PhiR->getStartValue());
- }
- VPBuilder::InsertPointGuard Guard(Builder);
- Builder.setInsertPoint(Select);
-
- // If the true value of the select is the reduction phi, the new value is
- // selected if the negated condition is true in any iteration.
- if (Select->getOperand(1) == PhiR)
- Cmp = Builder.createNot(Cmp);
- VPValue *Or = Builder.createOr(PhiR, Cmp);
- Select->getVPSingleValue()->replaceAllUsesWith(Or);
-
- // Convert the reduction phi to operate on bools.
- PhiR->setOperand(0, Plan->getOrAddLiveIn(ConstantInt::getFalse(
- OrigLoop->getHeader()->getContext())));
- }
-
// If tail is folded by masking, introduce selects between the phi
// and the live-out instruction of each reduction, at the beginning of the
// dedicated latch block.
@@ -9401,6 +9366,41 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
return match(&User, m_Binary<VPInstruction::ExtractFromEnd>(m_VPValue(),
m_VPValue()));
});
+
+ // Adjust AnyOf reductions; replace the reduction phi for the selected value
+ // with a boolean reduction phi node to check if the condition is true in
+ // any iteration. The final value is selected by the final
+ // ComputeReductionResult.
+ if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
+ RdxDesc.getRecurrenceKind())) {
+ auto *Select = cast<VPRecipeBase>(*find_if(PhiR->users(), [](VPUser *U) {
+ return isa<VPWidenSelectRecipe>(U) ||
+ (isa<VPReplicateRecipe>(U) &&
+ cast<VPReplicateRecipe>(U)->getUnderlyingInstr()->getOpcode() ==
+ Instruction::Select);
+ }));
+ VPValue *Cmp = Select->getOperand(0);
+ // If the compare is checking the reduction PHI node, adjust it to check
+ // the start value.
+ if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
+ for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
+ if (CmpR->getOperand(I) == PhiR)
+ CmpR->setOperand(I, PhiR->getStartValue());
+ }
+ VPBuilder::InsertPointGuard Guard(Builder);
+ Builder.setInsertPoint(Select);
+
+ // If the true value of the select is the reduction phi, the new value is
+ // selected if the negated condition is true in any iteration.
+ if (Select->getOperand(1) == PhiR)
+ Cmp = Builder.createNot(Cmp);
+ VPValue *Or = Builder.createOr(PhiR, Cmp);
+ Select->getVPSingleValue()->replaceAllUsesWith(Or);
+
+ // Convert the reduction phi to operate on bools.
+ PhiR->setOperand(0, Plan->getOrAddLiveIn(ConstantInt::getFalse(
+ OrigLoop->getHeader()->getContext())));
+ }
}
VPlanTransforms::clearReductionWrapFlags(*Plan);