From 36e14063cc675bba90633d3fbf7690085692174f Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Thu, 6 Mar 2025 17:58:28 +0800 Subject: [PATCH 1/2] [VPlan] Remove dead AnyOf reduction case in VPReductionRecipe. NFCI From what I understand, we only create VPReductionRecipes for in-loop reductions, and we don't currently support in-loop AnyOf reductions. We only create VPReductionRecipes in the !PhiR->isInLoop() section of adjustRecipesForReductions, and this comment from the initial patch seems to confirm this https://reviews.llvm.org/D108136#anchor-inline-1038338, so I think we can remove this check in the condition logic. I checked compiling SPEC 2017 with -prefer-inloop-predicates and the added assertion doesn't trigger. --- llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index d154d54c37862..6ee98b717a910 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2222,6 +2222,8 @@ void VPReductionRecipe::execute(VPTransformState &State) { assert(!State.Lane && "Reduction being replicated."); Value *PrevInChain = State.get(getChainOp(), /*IsScalar*/ true); RecurKind Kind = RdxDesc.getRecurrenceKind(); + assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) && + "In-loop AnyOf reductions aren't currently supported"); // Propagate the fast-math flags carried by the underlying instruction. IRBuilderBase::FastMathFlagGuard FMFGuard(State.Builder); State.Builder.setFastMathFlags(RdxDesc.getFastMathFlags()); @@ -2232,12 +2234,8 @@ void VPReductionRecipe::execute(VPTransformState &State) { VectorType *VecTy = dyn_cast(NewVecOp->getType()); Type *ElementTy = VecTy ? VecTy->getElementType() : NewVecOp->getType(); - Value *Start; - if (RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind)) - Start = RdxDesc.getRecurrenceStartValue(); - else - Start = llvm::getRecurrenceIdentity(Kind, ElementTy, - RdxDesc.getFastMathFlags()); + Value *Start = llvm::getRecurrenceIdentity(Kind, ElementTy, + RdxDesc.getFastMathFlags()); if (State.VF.isVector()) Start = State.Builder.CreateVectorSplat(VecTy->getElementCount(), Start); From 788b7d43aeb343c382b8f85e03226305db63b61c Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Thu, 6 Mar 2025 18:15:05 +0800 Subject: [PATCH 2/2] Remove llvm:: --- llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 6ee98b717a910..5010bf029d140 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2234,8 +2234,8 @@ void VPReductionRecipe::execute(VPTransformState &State) { VectorType *VecTy = dyn_cast(NewVecOp->getType()); Type *ElementTy = VecTy ? VecTy->getElementType() : NewVecOp->getType(); - Value *Start = llvm::getRecurrenceIdentity(Kind, ElementTy, - RdxDesc.getFastMathFlags()); + Value *Start = + getRecurrenceIdentity(Kind, ElementTy, RdxDesc.getFastMathFlags()); if (State.VF.isVector()) Start = State.Builder.CreateVectorSplat(VecTy->getElementCount(), Start);