Skip to content

Commit 4e71530

Browse files
committed
[VPlan] Add findComputeReductionResult helper. (NFC)
Move utility to helper for re-use in follow-up patches.
1 parent 3ff3c4e commit 4e71530

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,17 @@ void VPlanTransforms::addMinimumVectorEpilogueIterationCheck(
796796
Branch->addMetadata(LLVMContext::MD_prof, BranchWeights);
797797
}
798798

799+
/// If \p RedPhiR is used by a ComputeReductionResult recipe, return it.
800+
/// Otherwise return nullptr.
801+
static VPInstruction *
802+
findComputeReductionResult(VPReductionPHIRecipe *RedPhiR) {
803+
auto It = find_if(RedPhiR->users(), [](VPUser *U) {
804+
auto *VPI = dyn_cast<VPInstruction>(U);
805+
return VPI && VPI->getOpcode() == VPInstruction::ComputeReductionResult;
806+
});
807+
return It == RedPhiR->user_end() ? nullptr : cast<VPInstruction>(*It);
808+
}
809+
799810
bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
800811
auto GetMinMaxCompareValue = [](VPReductionPHIRecipe *RedPhiR) -> VPValue * {
801812
auto *MinMaxR =
@@ -900,13 +911,7 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
900911

901912
// If we exit early due to NaNs, compute the final reduction result based on
902913
// the reduction phi at the beginning of the last vector iteration.
903-
auto *RdxResult = find_singleton<VPSingleDefRecipe>(
904-
RedPhiR->users(), [](VPUser *U, bool) -> VPSingleDefRecipe * {
905-
auto *VPI = dyn_cast<VPInstruction>(U);
906-
if (VPI && VPI->getOpcode() == VPInstruction::ComputeReductionResult)
907-
return VPI;
908-
return nullptr;
909-
});
914+
auto *RdxResult = findComputeReductionResult(RedPhiR);
910915

911916
auto *NewSel = MiddleBuilder.createSelect(AnyNaNLane, RedPhiR,
912917
RdxResult->getOperand(1));

0 commit comments

Comments
 (0)