Skip to content

Commit fdf5e7b

Browse files
lukel97frederik-h
authored andcommitted
[VPlan] Move FOR splice cost into VPInstruction::FirstOrderRecurrenceSplice (llvm#129645)
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 2dbf6c5 commit fdf5e7b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,16 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
772772
return Cost + Ctx.TTI.getVectorInstrCost(Instruction::ExtractElement, VecTy,
773773
Ctx.CostKind);
774774
}
775+
case VPInstruction::FirstOrderRecurrenceSplice: {
776+
assert(VF.isVector() && "Scalar FirstOrderRecurrenceSplice?");
777+
SmallVector<int> Mask(VF.getKnownMinValue());
778+
std::iota(Mask.begin(), Mask.end(), VF.getKnownMinValue() - 1);
779+
Type *VectorTy = toVectorTy(Ctx.Types.inferScalarType(this), VF);
780+
781+
return Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Splice,
782+
cast<VectorType>(VectorTy), Mask,
783+
Ctx.CostKind, VF.getKnownMinValue() - 1);
784+
}
775785
default:
776786
// TODO: Compute cost other VPInstructions once the legacy cost model has
777787
// been retired.
@@ -3494,14 +3504,7 @@ VPFirstOrderRecurrencePHIRecipe::computeCost(ElementCount VF,
34943504
if (VF.isScalable() && VF.getKnownMinValue() == 1)
34953505
return InstructionCost::getInvalid();
34963506

3497-
SmallVector<int> Mask(VF.getKnownMinValue());
3498-
std::iota(Mask.begin(), Mask.end(), VF.getKnownMinValue() - 1);
3499-
Type *VectorTy =
3500-
toVectorTy(Ctx.Types.inferScalarType(this->getVPSingleValue()), VF);
3501-
3502-
return Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Splice,
3503-
cast<VectorType>(VectorTy), Mask, Ctx.CostKind,
3504-
VF.getKnownMinValue() - 1);
3507+
return 0;
35053508
}
35063509

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ 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-
54+
; IF-EVL: Cost of 0 for VF vscale x 4: FIRST-ORDER-RECURRENCE-PHI ir<[[FOR_PHI]]> = phi ir<33>, ir<[[LD]]>
55+
; 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]]>)
5556
entry:
5657
br label %for.body
5758

0 commit comments

Comments
 (0)