Skip to content

Commit 4a3f46d

Browse files
authored
[LV][EVL] Support call instruction with EVL-vectorization (llvm#110412)
1 parent 819b155 commit 4a3f46d

File tree

6 files changed

+1513
-1
lines changed

6 files changed

+1513
-1
lines changed

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ bool llvm::isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
118118
unsigned ScalarOpdIdx) {
119119
switch (ID) {
120120
case Intrinsic::abs:
121+
case Intrinsic::vp_abs:
121122
case Intrinsic::ctlz:
123+
case Intrinsic::vp_ctlz:
122124
case Intrinsic::cttz:
125+
case Intrinsic::vp_cttz:
123126
case Intrinsic::is_fpclass:
127+
case Intrinsic::vp_is_fpclass:
124128
case Intrinsic::powi:
125129
return (ScalarOpdIdx == 1);
126130
case Intrinsic::smul_fix:
@@ -145,10 +149,13 @@ bool llvm::isVectorIntrinsicWithOverloadTypeAtArg(
145149
case Intrinsic::fptoui_sat:
146150
case Intrinsic::lrint:
147151
case Intrinsic::llrint:
152+
case Intrinsic::vp_lrint:
153+
case Intrinsic::vp_llrint:
148154
case Intrinsic::ucmp:
149155
case Intrinsic::scmp:
150156
return OpdIdx == -1 || OpdIdx == 0;
151157
case Intrinsic::is_fpclass:
158+
case Intrinsic::vp_is_fpclass:
152159
return OpdIdx == 0;
153160
case Intrinsic::powi:
154161
return OpdIdx == -1 || OpdIdx == 1;

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,15 @@ InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF,
993993
for (const auto &[Idx, Op] : enumerate(operands())) {
994994
auto *V = Op->getUnderlyingValue();
995995
if (!V) {
996+
// Push all the VP Intrinsic's ops into the Argments even if is nullptr.
997+
// Some VP Intrinsic's cost will assert the number of parameters.
998+
// Mainly appears in the following two scenarios:
999+
// 1. EVL Op is nullptr
1000+
// 2. The Argmunt of the VP Intrinsic is also the VP Intrinsic
1001+
if (VPIntrinsic::isVPIntrinsic(VectorIntrinsicID)) {
1002+
Arguments.push_back(V);
1003+
continue;
1004+
}
9961005
if (auto *UI = dyn_cast_or_null<CallBase>(getUnderlyingValue())) {
9971006
Arguments.push_back(UI->getArgOperand(Idx));
9981007
continue;

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,26 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
14811481
VPValue *NewMask = GetNewMask(Red->getCondOp());
14821482
return new VPReductionEVLRecipe(*Red, EVL, NewMask);
14831483
})
1484+
.Case<VPWidenIntrinsicRecipe>(
1485+
[&](VPWidenIntrinsicRecipe *CInst) -> VPRecipeBase * {
1486+
auto *CI = cast<CallInst>(CInst->getUnderlyingInstr());
1487+
Intrinsic::ID VPID = VPIntrinsic::getForIntrinsic(
1488+
CI->getCalledFunction()->getIntrinsicID());
1489+
if (VPID == Intrinsic::not_intrinsic)
1490+
return nullptr;
1491+
1492+
SmallVector<VPValue *> Ops(CInst->operands());
1493+
assert(VPIntrinsic::getMaskParamPos(VPID) &&
1494+
VPIntrinsic::getVectorLengthParamPos(VPID) &&
1495+
"Expected VP intrinsic");
1496+
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::getTrue(
1497+
IntegerType::getInt1Ty(CI->getContext())));
1498+
Ops.push_back(Mask);
1499+
Ops.push_back(&EVL);
1500+
return new VPWidenIntrinsicRecipe(
1501+
*CI, VPID, Ops, TypeInfo.inferScalarType(CInst),
1502+
CInst->getDebugLoc());
1503+
})
14841504
.Case<VPWidenSelectRecipe>([&](VPWidenSelectRecipe *Sel) {
14851505
SmallVector<VPValue *> Ops(Sel->operands());
14861506
Ops.push_back(&EVL);

0 commit comments

Comments
 (0)