Skip to content

Commit 02db15b

Browse files
committed
Step 2: Transform llvm.splice to vp.splice
This version depend on branch explicit-FOR-op.
1 parent 9b43266 commit 02db15b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ bool llvm::isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
154154
case Intrinsic::umul_fix:
155155
case Intrinsic::umul_fix_sat:
156156
return (ScalarOpdIdx == 2);
157+
case Intrinsic::experimental_vp_splice:
158+
return ScalarOpdIdx == 2 || ScalarOpdIdx == 4 || ScalarOpdIdx == 5;
157159
default:
158160
return false;
159161
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,11 +1643,13 @@ void VPlanTransforms::addActiveLaneMask(
16431643
/// \p TypeInfo VPlan-based type analysis.
16441644
/// \p AllOneMask The vector mask parameter of vector-predication intrinsics.
16451645
/// \p EVL The explicit vector length parameter of vector-predication
1646+
/// \p PrevEVL The explicit vector length of the previous iteration.
16461647
/// intrinsics.
16471648
static VPRecipeBase *createEVLRecipe(VPValue *HeaderMask,
16481649
VPRecipeBase &CurRecipe,
16491650
VPTypeAnalysis &TypeInfo,
1650-
VPValue &AllOneMask, VPValue &EVL) {
1651+
VPValue &AllOneMask, VPValue &EVL,
1652+
VPValue *PrevEVL) {
16511653
using namespace llvm::VPlanPatternMatch;
16521654
auto GetNewMask = [&](VPValue *OrigMask) -> VPValue * {
16531655
assert(OrigMask && "Unmasked recipe when folding tail");
@@ -1705,6 +1707,15 @@ static VPRecipeBase *createEVLRecipe(VPValue *HeaderMask,
17051707
Sel->getDebugLoc());
17061708
})
17071709
.Case<VPInstruction>([&](VPInstruction *VPI) -> VPRecipeBase * {
1710+
if (VPI->getOpcode() == VPInstruction::FirstOrderRecurrenceSplice) {
1711+
assert(PrevEVL && "Fixed-order recurrences require previous EVL");
1712+
SmallVector<VPValue *> Ops(VPI->operands());
1713+
Ops.append({&AllOneMask, PrevEVL, &EVL});
1714+
return new VPWidenIntrinsicRecipe(Intrinsic::experimental_vp_splice,
1715+
Ops, TypeInfo.inferScalarType(VPI),
1716+
VPI->getDebugLoc());
1717+
}
1718+
17081719
VPValue *LHS, *RHS;
17091720
// Transform select with a header mask condition
17101721
// select(header_mask, LHS, RHS)
@@ -1733,6 +1744,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
17331744

17341745
// Create a scalar phi to track the previous EVL if fixed-order recurrence is
17351746
// contained.
1747+
VPScalarPHIRecipe *PrevEVL = nullptr;
17361748
bool ContainsFORs =
17371749
any_of(Header->phis(), IsaPred<VPFirstOrderRecurrencePHIRecipe>);
17381750
if (ContainsFORs) {
@@ -1748,7 +1760,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
17481760
VPBasicBlock *Preheader = LoopRegion->getPreheaderVPBB();
17491761
Preheader->appendRecipe(cast<VPScalarCastRecipe>(MaxEVL));
17501762
}
1751-
auto *PrevEVL = new VPScalarPHIRecipe(MaxEVL, &EVL, DebugLoc(), "prev.evl");
1763+
PrevEVL = new VPScalarPHIRecipe(MaxEVL, &EVL, DebugLoc(), "prev.evl");
17521764
PrevEVL->insertBefore(*Header, Header->getFirstNonPhi());
17531765
}
17541766

@@ -1762,8 +1774,8 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
17621774
for (VPValue *HeaderMask : collectAllHeaderMasks(Plan)) {
17631775
for (VPUser *U : collectUsersRecursively(HeaderMask)) {
17641776
auto *CurRecipe = cast<VPRecipeBase>(U);
1765-
VPRecipeBase *EVLRecipe =
1766-
createEVLRecipe(HeaderMask, *CurRecipe, TypeInfo, *AllOneMask, EVL);
1777+
VPRecipeBase *EVLRecipe = createEVLRecipe(
1778+
HeaderMask, *CurRecipe, TypeInfo, *AllOneMask, EVL, PrevEVL);
17671779
if (!EVLRecipe)
17681780
continue;
17691781

0 commit comments

Comments
 (0)