[VPlan] Adjust AnyOf after creating ComputeReductionResult (NFC).
Prepares for a follow-up change to use VPInstruction::ResumePhi to create the resume phi for reductions.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user