Skip to content

Commit

Permalink
[VP] Reorder is_int_min_poison/is_zero_poison operand before mask for…
Browse files Browse the repository at this point in the history
… vp.abs/ctlz/cttz.

The patch ensures last two operands of vp.abs/ctlz/cttz are mask and evl.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D144536
  • Loading branch information
yetingk committed Feb 23, 2023
1 parent 08a0923 commit 419948f
Show file tree
Hide file tree
Showing 11 changed files with 843 additions and 844 deletions.
14 changes: 7 additions & 7 deletions llvm/include/llvm/IR/Intrinsics.td
Expand Up @@ -1545,9 +1545,9 @@ let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn] in {
llvm_i32_ty]>;
def int_vp_abs : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
[ LLVMMatchType<0>,
llvm_i1_ty,
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
llvm_i32_ty,
llvm_i1_ty]>;
llvm_i32_ty]>;
def int_vp_smin : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
[ LLVMMatchType<0>,
LLVMMatchType<0>,
Expand Down Expand Up @@ -1826,17 +1826,17 @@ let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn] in {
llvm_i32_ty]>;
}

let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn, ImmArg<ArgIndex<3>>] in {
let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn, ImmArg<ArgIndex<1>>] in {
def int_vp_ctlz : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
[ LLVMMatchType<0>,
llvm_i1_ty,
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
llvm_i32_ty,
llvm_i1_ty]>;
llvm_i32_ty]>;
def int_vp_cttz : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
[ LLVMMatchType<0>,
llvm_i1_ty,
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
llvm_i32_ty,
llvm_i1_ty]>;
llvm_i32_ty]>;
}

def int_get_active_lane_mask:
Expand Down
14 changes: 8 additions & 6 deletions llvm/include/llvm/IR/VPIntrinsics.def
Expand Up @@ -222,8 +222,10 @@ BEGIN_REGISTER_VP(vp_umax, 2, 3, VP_UMAX, -1)
VP_PROPERTY_BINARYOP
END_REGISTER_VP(vp_umax, VP_UMAX)

// llvm.vp.abs(x,mask,vlen,is_int_min_poison)
BEGIN_REGISTER_VP(vp_abs, 1, 2, VP_ABS, -1)
// llvm.vp.abs(x,is_int_min_poison,mask,vlen)
BEGIN_REGISTER_VP_INTRINSIC(vp_abs, 2, 3)
BEGIN_REGISTER_VP_SDNODE(VP_ABS, -1, vp_abs, 1, 2)
HELPER_MAP_VPID_TO_VPSD(vp_abs, VP_ABS)
END_REGISTER_VP(vp_abs, VP_ABS)

// llvm.vp.bswap(x,mask,vlen)
Expand All @@ -238,16 +240,16 @@ END_REGISTER_VP(vp_bitreverse, VP_BITREVERSE)
BEGIN_REGISTER_VP(vp_ctpop, 1, 2, VP_CTPOP, -1)
END_REGISTER_VP(vp_ctpop, VP_CTPOP)

// llvm.vp.ctlz(x,mask,vlen, is_zero_poison)
BEGIN_REGISTER_VP_INTRINSIC(vp_ctlz, 1, 2)
// llvm.vp.ctlz(x,is_zero_poison,mask,vlen)
BEGIN_REGISTER_VP_INTRINSIC(vp_ctlz, 2, 3)
BEGIN_REGISTER_VP_SDNODE(VP_CTLZ, -1, vp_ctlz, 1, 2)
END_REGISTER_VP_SDNODE(VP_CTLZ)
BEGIN_REGISTER_VP_SDNODE(VP_CTLZ_ZERO_UNDEF, -1, vp_ctlz_zero_undef, 1, 2)
END_REGISTER_VP_SDNODE(VP_CTLZ_ZERO_UNDEF)
END_REGISTER_VP_INTRINSIC(vp_ctlz)

// llvm.vp.cttz(x,mask,vlen, is_zero_poison)
BEGIN_REGISTER_VP_INTRINSIC(vp_cttz, 1, 2)
// llvm.vp.cttz(x,is_zero_poison,mask,vlen)
BEGIN_REGISTER_VP_INTRINSIC(vp_cttz, 2, 3)
BEGIN_REGISTER_VP_SDNODE(VP_CTTZ, -1, vp_cttz, 1, 2)
END_REGISTER_VP_SDNODE(VP_CTTZ)
BEGIN_REGISTER_VP_SDNODE(VP_CTTZ_ZERO_UNDEF, -1, vp_cttz_zero_undef, 1, 2)
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Expand Up @@ -7446,12 +7446,12 @@ static unsigned getISDForVPIntrinsic(const VPIntrinsic &VPIntrin) {
std::optional<unsigned> ResOPC;
switch (VPIntrin.getIntrinsicID()) {
case Intrinsic::vp_ctlz: {
bool IsZeroUndef = cast<ConstantInt>(VPIntrin.getArgOperand(3))->isOne();
bool IsZeroUndef = cast<ConstantInt>(VPIntrin.getArgOperand(1))->isOne();
ResOPC = IsZeroUndef ? ISD::VP_CTLZ_ZERO_UNDEF : ISD::VP_CTLZ;
break;
}
case Intrinsic::vp_cttz: {
bool IsZeroUndef = cast<ConstantInt>(VPIntrin.getArgOperand(3))->isOne();
bool IsZeroUndef = cast<ConstantInt>(VPIntrin.getArgOperand(1))->isOne();
ResOPC = IsZeroUndef ? ISD::VP_CTTZ_ZERO_UNDEF : ISD::VP_CTTZ;
break;
}
Expand Down Expand Up @@ -7794,10 +7794,8 @@ void SelectionDAGBuilder::visitVectorPredicationIntrinsic(
case ISD::VP_CTLZ_ZERO_UNDEF:
case ISD::VP_CTTZ:
case ISD::VP_CTTZ_ZERO_UNDEF: {
// Pop is_zero_poison operand for cp.ctlz/cttz or
// is_int_min_poison operand for vp.abs.
OpValues.pop_back();
SDValue Result = DAG.getNode(Opcode, DL, VTs, OpValues);
SDValue Result =
DAG.getNode(Opcode, DL, VTs, {OpValues[0], OpValues[2], OpValues[3]});
setValue(&VPIntrin, Result);
break;
}
Expand Down
548 changes: 274 additions & 274 deletions llvm/test/Analysis/CostModel/RISCV/int-bit-manip.ll

Large diffs are not rendered by default.

144 changes: 72 additions & 72 deletions llvm/test/CodeGen/RISCV/rvv/abs-vp.ll

Large diffs are not rendered by default.

240 changes: 120 additions & 120 deletions llvm/test/CodeGen/RISCV/rvv/ctlz-vp.ll

Large diffs are not rendered by default.

240 changes: 120 additions & 120 deletions llvm/test/CodeGen/RISCV/rvv/cttz-vp.ll

Large diffs are not rendered by default.

0 comments on commit 419948f

Please sign in to comment.