Skip to content

Commit 0e45dc4

Browse files
committed
fix the commets
1 parent 363d625 commit 0e45dc4

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
@@ -1650,23 +1650,14 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
16501650
bool MayHaveSideEffects;
16511651

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

16711662
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID,
16721663
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
@@ -962,18 +962,31 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
962962

963963
// Use vector version of the intrinsic.
964964
Module *M = State.Builder.GetInsertBlock()->getModule();
965+
bool IsVPIntrinsic = VPIntrinsic::isVPIntrinsic(VectorIntrinsicID);
965966
Function *VectorF =
966-
Intrinsic::getOrInsertDeclaration(M, VectorIntrinsicID, TysForDecl);
967+
IsVPIntrinsic
968+
? VPIntrinsic::getOrInsertDeclarationForParams(M, VectorIntrinsicID,
969+
TysForDecl[0], Args)
970+
: Intrinsic::getOrInsertDeclaration(M, VectorIntrinsicID, TysForDecl);
967971
assert(VectorF && "Can't retrieve vector intrinsic.");
968972

969-
auto *CI = cast_or_null<CallInst>(getUnderlyingValue());
970973
SmallVector<OperandBundleDef, 1> OpBundles;
971-
if (CI)
972-
CI->getOperandBundlesAsDefs(OpBundles);
974+
if (!IsVPIntrinsic) {
975+
if (auto *CI = cast_or_null<CallInst>(getUnderlyingValue()))
976+
CI->getOperandBundlesAsDefs(OpBundles);
977+
}
973978

974-
CallInst *V = State.Builder.CreateCall(VectorF, Args, OpBundles);
979+
Value *V = State.Builder.CreateCall(VectorF, Args, OpBundles);
975980

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

978991
if (!V->getType()->isVoidTy())
979992
State.set(this, V);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,22 +1503,23 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
15031503
})
15041504
.Case<VPWidenCastRecipe>(
15051505
[&](VPWidenCastRecipe *CInst) -> VPRecipeBase * {
1506-
auto *CI = cast<CastInst>(CInst->getUnderlyingInstr());
1506+
auto *CI = dyn_cast<CastInst>(CInst->getUnderlyingInstr());
15071507
Intrinsic::ID VPID =
15081508
VPIntrinsic::getForOpcode(CI->getOpcode());
15091509
if (VPID == Intrinsic::not_intrinsic)
15101510
return nullptr;
1511+
15111512
SmallVector<VPValue *> Ops(CInst->operands());
1512-
if (VPIntrinsic::getMaskParamPos(VPID)) {
1513-
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::getTrue(
1514-
IntegerType::getInt1Ty(CI->getContext())));
1515-
Ops.push_back(Mask);
1516-
}
1517-
if (VPIntrinsic::getVectorLengthParamPos(VPID)) {
1518-
Ops.push_back(&EVL);
1519-
}
1513+
assert(VPIntrinsic::getMaskParamPos(VPID) &&
1514+
VPIntrinsic::getVectorLengthParamPos(VPID) &&
1515+
"Expected VP intrinsic");
1516+
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::getTrue(
1517+
IntegerType::getInt1Ty(CI->getContext())));
1518+
Ops.push_back(Mask);
1519+
Ops.push_back(&EVL);
15201520
return new VPWidenIntrinsicRecipe(
1521-
*CI, VPID, Ops, CI->getType(), CI->getDebugLoc());
1521+
*CI, VPID, Ops, TypeInfo.inferScalarType(CInst),
1522+
CInst->getDebugLoc());
15221523
})
15231524
.Case<VPWidenSelectRecipe>([&](VPWidenSelectRecipe *Sel) {
15241525
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)