Skip to content

Commit eaf1947

Browse files
committed
[VPlan] Move FOR splice cost into VPInstruction::FirstOrderRecurrenceSplice
After llvm#124093 we now support fixed-order recurrences with EVL tail folding by replacing VPInstruction::FirstOrderRecurrenceSplice with a VP splice intrinsic. However the costing for the splice is currently done in VPFirstOrderRecurrencePHIRecipe, so when we add the VP splice intrinsic we end up costing it twice. This fixes it by splitting out the cost for the splice into FirstOrderRecurrenceSplice so that it's not duplicated when we replace it. We still have to keep the VF=1 checks in VPFirstOrderRecurrencePHIRecipe since the splice might end up dead and discarded, e.g. in the test @pr97452_scalable_vf1_for.
1 parent a3d6cf4 commit eaf1947

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,17 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
743743
return Ctx.TTI.getArithmeticReductionCost(
744744
Instruction::Or, cast<VectorType>(VecTy), std::nullopt, Ctx.CostKind);
745745
}
746+
case VPInstruction::FirstOrderRecurrenceSplice: {
747+
assert(VF.isVector());
748+
SmallVector<int> Mask(VF.getKnownMinValue());
749+
std::iota(Mask.begin(), Mask.end(), VF.getKnownMinValue() - 1);
750+
Type *VectorTy =
751+
toVectorTy(Ctx.Types.inferScalarType(this->getVPSingleValue()), VF);
752+
753+
return Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Splice,
754+
cast<VectorType>(VectorTy), Mask,
755+
Ctx.CostKind, VF.getKnownMinValue() - 1);
756+
}
746757
default:
747758
// TODO: Compute cost other VPInstructions once the legacy cost model has
748759
// been retired.
@@ -3463,14 +3474,7 @@ VPFirstOrderRecurrencePHIRecipe::computeCost(ElementCount VF,
34633474
if (VF.isScalable() && VF.getKnownMinValue() == 1)
34643475
return InstructionCost::getInvalid();
34653476

3466-
SmallVector<int> Mask(VF.getKnownMinValue());
3467-
std::iota(Mask.begin(), Mask.end(), VF.getKnownMinValue() - 1);
3468-
Type *VectorTy =
3469-
toVectorTy(Ctx.Types.inferScalarType(this->getVPSingleValue()), VF);
3470-
3471-
return Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Splice,
3472-
cast<VectorType>(VectorTy), Mask, Ctx.CostKind,
3473-
VF.getKnownMinValue() - 1);
3477+
return 0;
34743478
}
34753479

34763480
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/test/Transforms/LoopVectorize/RISCV/vplan-vp-intrinsics-fixed-order-recurrence.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ define void @first_order_recurrence(ptr noalias %A, ptr noalias %B, i64 %TC) {
5151
; IF-EVL-NEXT: EMIT vp<[[RESUME_EXTRACT:%.+]]> = extract-from-end ir<[[LD]]>, ir<1>
5252
; IF-EVL-NEXT: EMIT branch-on-cond ir<true>
5353
; IF-EVL-NEXT: Successor(s): ir-bb<for.end>, scalar.ph
54-
; IF-EVL: Cost of 4 for VF vscale x 4: FIRST-ORDER-RECURRENCE-PHI ir<[[FOR_PHI]]> = phi ir<33>, ir<[[LD]]>
54+
; IF-EVL: Cost of 0 for VF vscale x 4: FIRST-ORDER-RECURRENCE-PHI ir<[[FOR_PHI]]> = phi ir<33>, ir<[[LD]]>
5555
; IF-EVL: Cost of 4 for VF vscale x 4: WIDEN-INTRINSIC vp<[[SPLICE]]> = call llvm.experimental.vp.splice(ir<[[FOR_PHI]]>, ir<[[LD]]>, ir<-1>, ir<true>, vp<[[PREV_EVL]]>, vp<[[EVL]]>)
5656
entry:
5757
br label %for.body

0 commit comments

Comments
 (0)