Skip to content

Commit f219d2c

Browse files
committed
[LV] Use VPWidenIntrinsicRecipe to vp_icmp/vp_fcmp
1 parent 74a4321 commit f219d2c

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,13 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
10001000
// Remove EVL from Args
10011001
Args.pop_back();
10021002

1003+
if (VPCmpIntrinsic::isVPCmp(VectorIntrinsicID)) {
1004+
auto &Ctx = State.Builder.getContext();
1005+
Value *Pred = MetadataAsValue::get(
1006+
Ctx, MDString::get(Ctx, CmpInst::getPredicateName(getPredicate())));
1007+
Args.push_back(Pred);
1008+
}
1009+
10031010
Value *VPInst = VBuilder.createSimpleIntrinsic(
10041011
VectorIntrinsicID, TysForDecl[0], Args, "vp.call");
10051012

@@ -1061,6 +1068,18 @@ InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF,
10611068
ParamTys.push_back(
10621069
ToVectorTy(Ctx.Types.inferScalarType(getOperand(I)), VF));
10631070

1071+
if (std::optional<unsigned> FOp =
1072+
VPIntrinsic::getFunctionalOpcodeForVP(VectorIntrinsicID)) {
1073+
if (VPCmpIntrinsic::isVPCmp(VectorIntrinsicID)) {
1074+
Instruction *CtxI = dyn_cast_or_null<Instruction>(getUnderlyingValue());
1075+
Type *VectorTy = ToVectorTy(Ctx.Types.inferScalarType(getOperand(0)), VF);
1076+
return Ctx.TTI.getCmpSelInstrCost(FOp.value(), VectorTy, nullptr,
1077+
getPredicate(), CostKind,
1078+
{TTI::OK_AnyValue, TTI::OP_None},
1079+
{TTI::OK_AnyValue, TTI::OP_None}, CtxI);
1080+
}
1081+
}
1082+
10641083
// TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst.
10651084
FastMathFlags FMF = hasFastMathFlags() ? getFastMathFlags() : FastMathFlags();
10661085
IntrinsicCostAttributes CostAttrs(

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,9 +1475,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
14751475
})
14761476
.Case<VPWidenRecipe>([&](VPWidenRecipe *W) -> VPRecipeBase * {
14771477
unsigned Opcode = W->getOpcode();
1478-
// TODO: Support other opcodes
1479-
if (!Instruction::isBinaryOp(Opcode) &&
1480-
!Instruction::isUnaryOp(Opcode))
1478+
if (Opcode == Instruction::Freeze)
14811479
return nullptr;
14821480
auto *I = cast<Instruction>(W->getUnderlyingInstr());
14831481
SmallVector<VPValue *> Ops(W->operands());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ define void @vp_icmp(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %N) {
2727
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%c>, vp<[[ST]]>
2828
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
2929
; IF-EVL-NEXT: WIDEN ir<[[LD2:%.+]]> = vp.load vp<[[PTR2]]>, vp<[[EVL]]>
30-
; IF-EVL-NEXT: WIDEN ir<[[ICMP:%.+]]> = vp.icmp sgt ir<[[LD1]]>, ir<[[LD2]]>, vp<[[EVL]]>
30+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[ICMP:%.+]]> = call sgt llvm.vp.icmp(ir<[[LD1]]>, ir<[[LD2]]>, vp<[[EVL]]>)
3131
; IF-EVL-NEXT: WIDEN-CAST ir<[[ZEXT:%.+]]> = zext ir<[[ICMP]]> to i32
3232
; IF-EVL-NEXT: CLONE ir<[[GEP3:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
3333
; IF-EVL-NEXT: vp<[[PTR3:%[0-9]+]]> = vector-pointer ir<[[GEP3]]>
@@ -82,7 +82,7 @@ define void @vp_fcmp(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %N) {
8282
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%c>, vp<[[ST]]>
8383
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
8484
; IF-EVL-NEXT: WIDEN ir<[[LD2:%.+]]> = vp.load vp<[[PTR2]]>, vp<[[EVL]]>
85-
; IF-EVL-NEXT: WIDEN ir<[[FCMP:%.+]]> = vp.fcmp ogt ir<[[LD1]]>, ir<[[LD2]]>, vp<[[EVL]]>
85+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[FCMP:%.+]]> = call ogt llvm.vp.fcmp(ir<[[LD1]]>, ir<[[LD2]]>, vp<[[EVL]]>)
8686
; IF-EVL-NEXT: WIDEN-CAST ir<[[UITOFP:%.+]]> = uitofp ir<[[FCMP]]> to float
8787
; IF-EVL-NEXT: CLONE ir<[[GEP3:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
8888
; IF-EVL-NEXT: vp<[[PTR3:%[0-9]+]]> = vector-pointer ir<[[GEP3]]>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%c>, vp<[[ST]]>
2828
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
2929
; IF-EVL-NEXT: WIDEN ir<[[LD2:%.+]]> = vp.load vp<[[PTR2]]>, vp<[[EVL]]>
30-
; IF-EVL-NEXT: WIDEN ir<[[CMP:%.+]]> = icmp sgt ir<[[LD1]]>, ir<[[LD2]]>
30+
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[CMP:%.+]]> = call sgt llvm.vp.icmp(ir<[[LD1]]>, ir<[[LD2]]>, vp<[[EVL]]>)
3131
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[SUB:%.+]]> = call llvm.vp.sub(ir<0>, ir<[[LD2]]>, vp<[[EVL]]>)
3232
; IF-EVL-NEXT: WIDEN-INTRINSIC vp<[[SELECT:%.+]]> = call llvm.vp.select(ir<[[CMP]]>, ir<%1>, ir<%2>, vp<[[EVL]]>)
3333
; IF-EVL-NEXT: WIDEN-INTRINSIC ir<[[ADD:%.+]]> = call llvm.vp.add(vp<[[SELECT]]>, ir<[[LD1]]>, vp<[[EVL]]>)

0 commit comments

Comments
 (0)