Skip to content

Commit e62fe9e

Browse files
committed
fix the commets
1 parent a3c6a13 commit e62fe9e

File tree

4 files changed

+51
-46
lines changed

4 files changed

+51
-46
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,23 +1648,14 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
16481648
bool MayHaveSideEffects;
16491649

16501650
public:
1651-
VPWidenIntrinsicRecipe(CallInst &CI, Intrinsic::ID VectorIntrinsicID,
1651+
VPWidenIntrinsicRecipe(Instruction &I, Intrinsic::ID VectorIntrinsicID,
16521652
ArrayRef<VPValue *> CallArguments, Type *Ty,
16531653
DebugLoc DL = {})
1654-
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1654+
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, I),
16551655
VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1656-
MayReadFromMemory(CI.mayReadFromMemory()),
1657-
MayWriteToMemory(CI.mayWriteToMemory()),
1658-
MayHaveSideEffects(CI.mayHaveSideEffects()) {}
1659-
1660-
VPWidenIntrinsicRecipe(CastInst &CI, Intrinsic::ID VectorIntrinsicID,
1661-
ArrayRef<VPValue *> CallArguments, Type *Ty,
1662-
DebugLoc DL = {})
1663-
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1664-
VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1665-
MayReadFromMemory(CI.mayReadFromMemory()),
1666-
MayWriteToMemory(CI.mayWriteToMemory()),
1667-
MayHaveSideEffects(CI.mayHaveSideEffects()) {}
1656+
MayReadFromMemory(I.mayReadFromMemory()),
1657+
MayWriteToMemory(I.mayWriteToMemory()),
1658+
MayHaveSideEffects(I.mayHaveSideEffects()) {}
16681659

16691660
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID,
16701661
ArrayRef<VPValue *> CallArguments, Type *Ty,

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -959,18 +959,31 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
959959

960960
// Use vector version of the intrinsic.
961961
Module *M = State.Builder.GetInsertBlock()->getModule();
962+
bool IsVPIntrinsic = VPIntrinsic::isVPIntrinsic(VectorIntrinsicID);
962963
Function *VectorF =
963-
Intrinsic::getOrInsertDeclaration(M, VectorIntrinsicID, TysForDecl);
964+
IsVPIntrinsic
965+
? VPIntrinsic::getOrInsertDeclarationForParams(M, VectorIntrinsicID,
966+
TysForDecl[0], Args)
967+
: Intrinsic::getOrInsertDeclaration(M, VectorIntrinsicID, TysForDecl);
964968
assert(VectorF && "Can't retrieve vector intrinsic.");
965969

966-
auto *CI = cast_or_null<CallInst>(getUnderlyingValue());
967970
SmallVector<OperandBundleDef, 1> OpBundles;
968-
if (CI)
969-
CI->getOperandBundlesAsDefs(OpBundles);
971+
if (!IsVPIntrinsic) {
972+
if (auto *CI = cast_or_null<CallInst>(getUnderlyingValue()))
973+
CI->getOperandBundlesAsDefs(OpBundles);
974+
}
970975

971-
CallInst *V = State.Builder.CreateCall(VectorF, Args, OpBundles);
976+
Value *V = State.Builder.CreateCall(VectorF, Args, OpBundles);
972977

973-
setFlags(V);
978+
if (IsVPIntrinsic) {
979+
// Currently vp-intrinsics only accept FMF flags.
980+
// TODO: Enable other flags when support is added.
981+
// vp_uitofp will get OperationType::NonNegOp
982+
if (isa<FPMathOperator>(V) && VectorIntrinsicID != Intrinsic::vp_uitofp)
983+
setFlags(cast<Instruction>(V));
984+
} else {
985+
setFlags(cast<Instruction>(V));
986+
}
974987

975988
if (!V->getType()->isVoidTy())
976989
State.set(this, V);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,22 +1476,23 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
14761476
})
14771477
.Case<VPWidenCastRecipe>(
14781478
[&](VPWidenCastRecipe *CInst) -> VPRecipeBase * {
1479-
auto *CI = cast<CastInst>(CInst->getUnderlyingInstr());
1479+
auto *CI = dyn_cast<CastInst>(CInst->getUnderlyingInstr());
14801480
Intrinsic::ID VPID =
14811481
VPIntrinsic::getForOpcode(CI->getOpcode());
14821482
if (VPID == Intrinsic::not_intrinsic)
14831483
return nullptr;
1484+
14841485
SmallVector<VPValue *> Ops(CInst->operands());
1485-
if (VPIntrinsic::getMaskParamPos(VPID)) {
1486-
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::getTrue(
1487-
IntegerType::getInt1Ty(CI->getContext())));
1488-
Ops.push_back(Mask);
1489-
}
1490-
if (VPIntrinsic::getVectorLengthParamPos(VPID)) {
1491-
Ops.push_back(&EVL);
1492-
}
1486+
assert(VPIntrinsic::getMaskParamPos(VPID) &&
1487+
VPIntrinsic::getVectorLengthParamPos(VPID) &&
1488+
"Expected VP intrinsic");
1489+
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::getTrue(
1490+
IntegerType::getInt1Ty(CI->getContext())));
1491+
Ops.push_back(Mask);
1492+
Ops.push_back(&EVL);
14931493
return new VPWidenIntrinsicRecipe(
1494-
*CI, VPID, Ops, CI->getType(), CI->getDebugLoc());
1494+
*CI, VPID, Ops, TypeInfo.inferScalarType(CInst),
1495+
CInst->getDebugLoc());
14951496
})
14961497
.Case<VPWidenSelectRecipe>([&](VPWidenSelectRecipe *Sel) {
14971498
SmallVector<VPValue *> Ops(Sel->operands());

llvm/test/Transforms/LoopVectorize/RISCV/vplan-vp-cast-intrinsics.ll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; RUN: -prefer-predicate-over-epilogue=predicate-dont-vectorize \
55
; RUN: -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -disable-output < %s 2>&1 | FileCheck --check-prefix=IF-EVL %s
66

7-
define void @vp_sext(ptr noalias %a, ptr noalias %b, i64 %N) {
7+
define void @vp_sext(ptr %a, ptr %b, i64 %N) {
88
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2},UF={1}' {
99
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
1010
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -23,7 +23,7 @@ define void @vp_sext(ptr noalias %a, ptr noalias %b, i64 %N) {
2323
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
2424
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
2525
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
26-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[SEXT:%.+]]> = call llvm.vp.sext(ir<[[LD1]]>, vp<[[EVL]]>)
26+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[SEXT:%.+]]> = call llvm.vp.sext(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
2727
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
2828
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
2929
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[SEXT]]>, vp<[[EVL]]>
@@ -54,7 +54,7 @@ exit:
5454
ret void
5555
}
5656

57-
define void @vp_zext(ptr noalias %a, ptr noalias %b, i64 %N) {
57+
define void @vp_zext(ptr %a, ptr %b, i64 %N) {
5858
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2},UF={1}' {
5959
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
6060
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -73,7 +73,7 @@ define void @vp_zext(ptr noalias %a, ptr noalias %b, i64 %N) {
7373
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
7474
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
7575
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
76-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[ZEXT:%.+]]> = call llvm.vp.zext(ir<[[LD1]]>, vp<[[EVL]]>)
76+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[ZEXT:%.+]]> = call llvm.vp.zext(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
7777
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
7878
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
7979
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[ZEXT]]>, vp<[[EVL]]>
@@ -102,7 +102,7 @@ exit:
102102
ret void
103103
}
104104

105-
define void @vp_truncate(ptr noalias %a, ptr noalias %b, i64 %N) {
105+
define void @vp_truncate(ptr %a, ptr %b, i64 %N) {
106106
; IF-EVL: VPlan 'Initial VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF={1}' {
107107
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
108108
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -121,7 +121,7 @@ define void @vp_truncate(ptr noalias %a, ptr noalias %b, i64 %N) {
121121
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
122122
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
123123
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
124-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[TRUNC:%.+]]> = call llvm.vp.trunc(ir<[[LD1]]>, vp<[[EVL]]>)
124+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[TRUNC:%.+]]> = call llvm.vp.trunc(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
125125
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
126126
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
127127
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[TRUNC]]>, vp<[[EVL]]>
@@ -150,7 +150,7 @@ exit:
150150
ret void
151151
}
152152

153-
define void @vp_fpext(ptr noalias %a, ptr noalias %b, i64 %N) {
153+
define void @vp_fpext(ptr %a, ptr %b, i64 %N) {
154154
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2},UF={1}' {
155155
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
156156
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -169,7 +169,7 @@ define void @vp_fpext(ptr noalias %a, ptr noalias %b, i64 %N) {
169169
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
170170
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
171171
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
172-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[FPEXT:%.+]]> = call llvm.vp.fpext(ir<[[LD1]]>, vp<[[EVL]]>)
172+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[FPEXT:%.+]]> = call llvm.vp.fpext(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
173173
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
174174
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
175175
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[FPEXT]]>, vp<[[EVL]]>
@@ -198,7 +198,7 @@ exit:
198198
ret void
199199
}
200200

201-
define void @vp_fptrunct(ptr noalias %a, ptr noalias %b, i64 %N) {
201+
define void @vp_fptrunct(ptr %a, ptr %b, i64 %N) {
202202
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2},UF={1}' {
203203
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
204204
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -217,7 +217,7 @@ define void @vp_fptrunct(ptr noalias %a, ptr noalias %b, i64 %N) {
217217
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
218218
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
219219
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
220-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[FPTRUNC:%.+]]> = call llvm.vp.fptrunc(ir<[[LD1]]>, vp<[[EVL]]>)
220+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[FPTRUNC:%.+]]> = call llvm.vp.fptrunc(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
221221
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
222222
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
223223
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[FPTRUNC]]>, vp<[[EVL]]>
@@ -246,7 +246,7 @@ exit:
246246
ret void
247247
}
248248

249-
define void @vp_fptosi(ptr noalias %a, ptr noalias %b, i64 %N) {
249+
define void @vp_fptosi(ptr %a, ptr %b, i64 %N) {
250250
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF={1}' {
251251
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
252252
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -265,7 +265,7 @@ define void @vp_fptosi(ptr noalias %a, ptr noalias %b, i64 %N) {
265265
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
266266
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
267267
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
268-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[FPTOSI:%.+]]> = call llvm.vp.fptoui(ir<[[LD1]]>, vp<[[EVL]]>)
268+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[FPTOSI:%.+]]> = call llvm.vp.fptoui(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
269269
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
270270
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
271271
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[FPTOSI]]>, vp<[[EVL]]>
@@ -294,7 +294,7 @@ exit:
294294
ret void
295295
}
296296

297-
define void @vp_inttofp(ptr noalias %a, ptr noalias %b, i64 %N) {
297+
define void @vp_inttofp(ptr %a, ptr %b, i64 %N) {
298298
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF={1}' {
299299
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
300300
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -313,7 +313,7 @@ define void @vp_inttofp(ptr noalias %a, ptr noalias %b, i64 %N) {
313313
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
314314
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
315315
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
316-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[SITOFP:%.+]]> = call llvm.vp.sitofp(ir<[[LD1]]>, vp<[[EVL]]>)
316+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[SITOFP:%.+]]> = call llvm.vp.sitofp(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
317317
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
318318
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
319319
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[SITOFP]]>, vp<[[EVL]]>
@@ -342,7 +342,7 @@ exit:
342342
ret void
343343
}
344344

345-
define void @vp_uinttofp(ptr noalias %a, ptr noalias %b, i64 %N) {
345+
define void @vp_uinttofp(ptr %a, ptr %b, i64 %N) {
346346
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF={1}' {
347347
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
348348
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
@@ -361,7 +361,7 @@ define void @vp_uinttofp(ptr noalias %a, ptr noalias %b, i64 %N) {
361361
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
362362
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
363363
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
364-
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[UITOFP:%.+]]> = call llvm.vp.uitofp(ir<[[LD1]]>, vp<[[EVL]]>)
364+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[UITOFP:%.+]]> = call llvm.vp.uitofp(ir<[[LD1]]>, ir<true>, vp<[[EVL]]>)
365365
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
366366
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
367367
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR2]]>, ir<[[UITOFP]]>, vp<[[EVL]]>

0 commit comments

Comments
 (0)