Skip to content

Commit 4be1c19

Browse files
committed
[VPlan] Adjust AnyOf after creating ComputeReductionResult (NFC).
Prepares for a follow-up change to use VPInstruction::ResumePhi to create the resume phi for reductions.
1 parent fd88121 commit 4be1c19

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9294,41 +9294,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
92949294
continue;
92959295

92969296
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
9297-
// Adjust AnyOf reductions; replace the reduction phi for the selected value
9298-
// with a boolean reduction phi node to check if the condition is true in
9299-
// any iteration. The final value is selected by the final
9300-
// ComputeReductionResult.
9301-
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
9302-
RdxDesc.getRecurrenceKind())) {
9303-
auto *Select = cast<VPRecipeBase>(*find_if(PhiR->users(), [](VPUser *U) {
9304-
return isa<VPWidenSelectRecipe>(U) ||
9305-
(isa<VPReplicateRecipe>(U) &&
9306-
cast<VPReplicateRecipe>(U)->getUnderlyingInstr()->getOpcode() ==
9307-
Instruction::Select);
9308-
}));
9309-
VPValue *Cmp = Select->getOperand(0);
9310-
// If the compare is checking the reduction PHI node, adjust it to check
9311-
// the start value.
9312-
if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
9313-
for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
9314-
if (CmpR->getOperand(I) == PhiR)
9315-
CmpR->setOperand(I, PhiR->getStartValue());
9316-
}
9317-
VPBuilder::InsertPointGuard Guard(Builder);
9318-
Builder.setInsertPoint(Select);
9319-
9320-
// If the true value of the select is the reduction phi, the new value is
9321-
// selected if the negated condition is true in any iteration.
9322-
if (Select->getOperand(1) == PhiR)
9323-
Cmp = Builder.createNot(Cmp);
9324-
VPValue *Or = Builder.createOr(PhiR, Cmp);
9325-
Select->getVPSingleValue()->replaceAllUsesWith(Or);
9326-
9327-
// Convert the reduction phi to operate on bools.
9328-
PhiR->setOperand(0, Plan->getOrAddLiveIn(ConstantInt::getFalse(
9329-
OrigLoop->getHeader()->getContext())));
9330-
}
9331-
93329297
// If tail is folded by masking, introduce selects between the phi
93339298
// and the live-out instruction of each reduction, at the beginning of the
93349299
// dedicated latch block.
@@ -9401,6 +9366,41 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
94019366
return match(&User, m_Binary<VPInstruction::ExtractFromEnd>(m_VPValue(),
94029367
m_VPValue()));
94039368
});
9369+
9370+
// Adjust AnyOf reductions; replace the reduction phi for the selected value
9371+
// with a boolean reduction phi node to check if the condition is true in
9372+
// any iteration. The final value is selected by the final
9373+
// ComputeReductionResult.
9374+
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
9375+
RdxDesc.getRecurrenceKind())) {
9376+
auto *Select = cast<VPRecipeBase>(*find_if(PhiR->users(), [](VPUser *U) {
9377+
return isa<VPWidenSelectRecipe>(U) ||
9378+
(isa<VPReplicateRecipe>(U) &&
9379+
cast<VPReplicateRecipe>(U)->getUnderlyingInstr()->getOpcode() ==
9380+
Instruction::Select);
9381+
}));
9382+
VPValue *Cmp = Select->getOperand(0);
9383+
// If the compare is checking the reduction PHI node, adjust it to check
9384+
// the start value.
9385+
if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
9386+
for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
9387+
if (CmpR->getOperand(I) == PhiR)
9388+
CmpR->setOperand(I, PhiR->getStartValue());
9389+
}
9390+
VPBuilder::InsertPointGuard Guard(Builder);
9391+
Builder.setInsertPoint(Select);
9392+
9393+
// If the true value of the select is the reduction phi, the new value is
9394+
// selected if the negated condition is true in any iteration.
9395+
if (Select->getOperand(1) == PhiR)
9396+
Cmp = Builder.createNot(Cmp);
9397+
VPValue *Or = Builder.createOr(PhiR, Cmp);
9398+
Select->getVPSingleValue()->replaceAllUsesWith(Or);
9399+
9400+
// Convert the reduction phi to operate on bools.
9401+
PhiR->setOperand(0, Plan->getOrAddLiveIn(ConstantInt::getFalse(
9402+
OrigLoop->getHeader()->getContext())));
9403+
}
94049404
}
94059405

94069406
VPlanTransforms::clearReductionWrapFlags(*Plan);

0 commit comments

Comments
 (0)