@@ -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+
799810bool 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