Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
Legal);

if (Subtarget.hasStdExtZvabd()) {
setOperationAction(ISD::ABS, VT, Legal);
// Only SEW=8/16 are supported in Zvabd.
if (VT.getVectorElementType() == MVT::i8 ||
VT.getVectorElementType() == MVT::i16)
Expand Down Expand Up @@ -13770,17 +13771,22 @@ SDValue RISCVTargetLowering::lowerABS(SDValue Op, SelectionDAG &DAG) const {
} else
std::tie(Mask, VL) = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget);

SDValue SplatZero = DAG.getNode(
RISCVISD::VMV_V_X_VL, DL, ContainerVT, DAG.getUNDEF(ContainerVT),
DAG.getConstant(0, DL, Subtarget.getXLenVT()), VL);
SDValue NegX = DAG.getNode(RISCVISD::SUB_VL, DL, ContainerVT, SplatZero, X,
DAG.getUNDEF(ContainerVT), Mask, VL);
SDValue Max = DAG.getNode(RISCVISD::SMAX_VL, DL, ContainerVT, X, NegX,
DAG.getUNDEF(ContainerVT), Mask, VL);

SDValue Result;
if (Subtarget.hasStdExtZvabd()) {
Result = DAG.getNode(RISCVISD::ABS_VL, DL, ContainerVT, X,
DAG.getUNDEF(ContainerVT), Mask, VL);
} else {
SDValue SplatZero = DAG.getNode(
RISCVISD::VMV_V_X_VL, DL, ContainerVT, DAG.getUNDEF(ContainerVT),
DAG.getConstant(0, DL, Subtarget.getXLenVT()), VL);
SDValue NegX = DAG.getNode(RISCVISD::SUB_VL, DL, ContainerVT, SplatZero, X,
DAG.getUNDEF(ContainerVT), Mask, VL);
Result = DAG.getNode(RISCVISD::SMAX_VL, DL, ContainerVT, X, NegX,
DAG.getUNDEF(ContainerVT), Mask, VL);
}
if (VT.isFixedLengthVector())
Max = convertFromScalableVector(VT, Max, DAG, Subtarget);
return Max;
Result = convertFromScalableVector(VT, Result, DAG, Subtarget);
return Result;
}

SDValue RISCVTargetLowering::lowerToScalableOp(SDValue Op,
Expand Down
20 changes: 20 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,26 @@ multiclass VPatAVGADDVL_VV_VX_RM<SDNode vop, int vxrm, string suffix = ""> {
}
}

multiclass VPatUnaryVL_V<SDPatternOperator op, string instruction_name,
Predicate predicate = HasStdExtZvbb> {
foreach vti = AllIntegerVectors in {
let Predicates = !listconcat([predicate],
GetVTypePredicates<vti>.Predicates) in {
def : Pat<(vti.Vector (op (vti.Vector vti.RegClass:$rs1),
(vti.Vector vti.RegClass:$passthru),
(vti.Mask VMV0:$vm),
VLOpFrag)),
(!cast<Instruction>(instruction_name#"_V_"#vti.LMul.MX#"_MASK")
vti.RegClass:$passthru,
vti.RegClass:$rs1,
(vti.Mask VMV0:$vm),
GPR:$vl,
vti.Log2SEW,
TAIL_AGNOSTIC)>;
}
}
}

//===----------------------------------------------------------------------===//
// Patterns.
//===----------------------------------------------------------------------===//
Expand Down
26 changes: 26 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoZvabd.td
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,23 @@ let Predicates = [HasStdExtZvabd] in {
//===----------------------------------------------------------------------===//
// Pseudos
//===----------------------------------------------------------------------===//

multiclass PseudoVABS {
foreach m = MxList in {
defvar mx = m.MX;
let VLMul = m.value in {
def "_V_" # mx : VPseudoUnaryNoMask<m.vrclass, m.vrclass>,
SchedUnary<"WriteVIALUV", "ReadVIALUV", mx, forcePassthruRead=true>;
def "_V_" # mx # "_MASK" :
VPseudoUnaryMask<m.vrclass, m.vrclass>,
RISCVMaskedPseudo<MaskIdx=2>,
SchedUnary<"WriteVIALUV", "ReadVIALUV", mx, forcePassthruRead=true>;
}
}
}

let Predicates = [HasStdExtZvabd] in {
defm PseudoVABS : PseudoVABS;
defm PseudoVABD : VPseudoVALU_VV<Commutable = 1>;
defm PseudoVABDU : VPseudoVALU_VV<Commutable = 1>;
} // Predicates = [HasStdExtZvabd]
Expand All @@ -38,6 +54,7 @@ let Predicates = [HasStdExtZvabd] in {
// CodeGen Patterns
//===----------------------------------------------------------------------===//
let HasPassthruOp = true, HasMaskOp = true in {
def riscv_abs_vl : RVSDNode<"ABS_VL", SDT_RISCVIntUnOp_VL>;
def riscv_abds_vl : RVSDNode<"ABDS_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
def riscv_abdu_vl : RVSDNode<"ABDU_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
} // let HasPassthruOp = true, HasMaskOp = true
Expand All @@ -53,4 +70,13 @@ defm : VPatBinarySDNode_VV<abdu, "PseudoVABDU", ABDIntVectors>;

defm : VPatBinaryVL_VV<riscv_abds_vl, "PseudoVABD", ABDIntVectors>;
defm : VPatBinaryVL_VV<riscv_abdu_vl, "PseudoVABDU", ABDIntVectors>;

foreach vti = AllIntegerVectors in {
def : Pat<(vti.Vector (abs (vti.Vector vti.RegClass:$rs2))),
(!cast<Instruction>("PseudoVABS_V_"#vti.LMul.MX)
(vti.Vector (IMPLICIT_DEF)),
vti.RegClass:$rs2, vti.AVL, vti.Log2SEW, TA_MA)>;
}

defm : VPatUnaryVL_V<riscv_abs_vl, "PseudoVABS", HasStdExtZvabd>;
} // Predicates = [HasStdExtZvabd]
20 changes: 0 additions & 20 deletions llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td
Original file line number Diff line number Diff line change
Expand Up @@ -719,26 +719,6 @@ defm : VPatBinarySDNode_VV_VX<clmulh, "PseudoVCLMULH", I64IntegerVectors, ExtraP
// VL patterns
//===----------------------------------------------------------------------===//

multiclass VPatUnaryVL_V<SDPatternOperator op, string instruction_name,
Predicate predicate = HasStdExtZvbb> {
foreach vti = AllIntegerVectors in {
let Predicates = !listconcat([predicate],
GetVTypePredicates<vti>.Predicates) in {
def : Pat<(vti.Vector (op (vti.Vector vti.RegClass:$rs1),
(vti.Vector vti.RegClass:$passthru),
(vti.Mask VMV0:$vm),
VLOpFrag)),
(!cast<Instruction>(instruction_name#"_V_"#vti.LMul.MX#"_MASK")
vti.RegClass:$passthru,
vti.RegClass:$rs1,
(vti.Mask VMV0:$vm),
GPR:$vl,
vti.Log2SEW,
TAIL_AGNOSTIC)>;
}
}
}

foreach vti = AllIntegerVectors in {
let Predicates = !listconcat([HasStdExtZvkb],
GetVTypePredicates<vti>.Predicates) in {
Expand Down
94 changes: 94 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/abs-sdnode.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv32 -mattr=+v -verify-machineinstrs < %s | FileCheck %s
; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s | FileCheck %s
; RUN: llc -mtriple=riscv32 -mattr=+v,+experimental-zvabd -verify-machineinstrs < %s \
; RUN: | FileCheck %s --check-prefixes=ZVABD
; RUN: llc -mtriple=riscv64 -mattr=+v,+experimental-zvabd -verify-machineinstrs < %s \
; RUN: | FileCheck %s --check-prefixes=ZVABD

define <vscale x 1 x i16> @vabs_nxv1i16(<vscale x 1 x i16> %v) {
; CHECK-LABEL: vabs_nxv1i16:
Expand All @@ -9,6 +13,12 @@ define <vscale x 1 x i16> @vabs_nxv1i16(<vscale x 1 x i16> %v) {
; CHECK-NEXT: vrsub.vi v9, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v9
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv1i16:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e16, mf4, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 1 x i16> @llvm.abs.nxv1i16(<vscale x 1 x i16> %v, i1 false)
ret <vscale x 1 x i16> %r
}
Expand All @@ -20,6 +30,12 @@ define <vscale x 2 x i16> @vabs_nxv2i16(<vscale x 2 x i16> %v) {
; CHECK-NEXT: vrsub.vi v9, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v9
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv2i16:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e16, mf2, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 2 x i16> @llvm.abs.nxv2i16(<vscale x 2 x i16> %v, i1 false)
ret <vscale x 2 x i16> %r
}
Expand All @@ -31,6 +47,12 @@ define <vscale x 4 x i16> @vabs_nxv4i16(<vscale x 4 x i16> %v) {
; CHECK-NEXT: vrsub.vi v9, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v9
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv4i16:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e16, m1, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 4 x i16> @llvm.abs.nxv4i16(<vscale x 4 x i16> %v, i1 false)
ret <vscale x 4 x i16> %r
}
Expand All @@ -42,6 +64,12 @@ define <vscale x 8 x i16> @vabs_nxv8i16(<vscale x 8 x i16> %v) {
; CHECK-NEXT: vrsub.vi v10, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v10
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv8i16:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e16, m2, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 8 x i16> @llvm.abs.nxv8i16(<vscale x 8 x i16> %v, i1 false)
ret <vscale x 8 x i16> %r
}
Expand All @@ -53,6 +81,12 @@ define <vscale x 16 x i16> @vabs_nxv16i16(<vscale x 16 x i16> %v) {
; CHECK-NEXT: vrsub.vi v12, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v12
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv16i16:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e16, m4, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 16 x i16> @llvm.abs.nxv16i16(<vscale x 16 x i16> %v, i1 false)
ret <vscale x 16 x i16> %r
}
Expand All @@ -64,6 +98,12 @@ define <vscale x 32 x i16> @vabs_nxv32i16(<vscale x 32 x i16> %v) {
; CHECK-NEXT: vrsub.vi v16, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v16
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv32i16:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e16, m8, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 32 x i16> @llvm.abs.nxv32i16(<vscale x 32 x i16> %v, i1 false)
ret <vscale x 32 x i16> %r
}
Expand All @@ -75,6 +115,12 @@ define <vscale x 1 x i32> @vabs_nxv1i32(<vscale x 1 x i32> %v) {
; CHECK-NEXT: vrsub.vi v9, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v9
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv1i32:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e32, mf2, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 1 x i32> @llvm.abs.nxv1i32(<vscale x 1 x i32> %v, i1 false)
ret <vscale x 1 x i32> %r
}
Expand All @@ -86,6 +132,12 @@ define <vscale x 2 x i32> @vabs_nxv2i32(<vscale x 2 x i32> %v) {
; CHECK-NEXT: vrsub.vi v9, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v9
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv2i32:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e32, m1, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 2 x i32> @llvm.abs.nxv2i32(<vscale x 2 x i32> %v, i1 false)
ret <vscale x 2 x i32> %r
}
Expand All @@ -97,6 +149,12 @@ define <vscale x 4 x i32> @vabs_nxv4i32(<vscale x 4 x i32> %v) {
; CHECK-NEXT: vrsub.vi v10, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v10
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv4i32:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e32, m2, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32> %v, i1 false)
ret <vscale x 4 x i32> %r
}
Expand All @@ -108,6 +166,12 @@ define <vscale x 8 x i32> @vabs_nxv8i32(<vscale x 8 x i32> %v) {
; CHECK-NEXT: vrsub.vi v12, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v12
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv8i32:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e32, m4, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 8 x i32> @llvm.abs.nxv8i32(<vscale x 8 x i32> %v, i1 false)
ret <vscale x 8 x i32> %r
}
Expand All @@ -119,6 +183,12 @@ define <vscale x 16 x i32> @vabs_nxv16i32(<vscale x 16 x i32> %v) {
; CHECK-NEXT: vrsub.vi v16, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v16
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv16i32:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e32, m8, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 16 x i32> @llvm.abs.nxv16i32(<vscale x 16 x i32> %v, i1 false)
ret <vscale x 16 x i32> %r
}
Expand All @@ -130,6 +200,12 @@ define <vscale x 1 x i64> @vabs_nxv1i64(<vscale x 1 x i64> %v) {
; CHECK-NEXT: vrsub.vi v9, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v9
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv1i64:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e64, m1, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 1 x i64> @llvm.abs.nxv1i64(<vscale x 1 x i64> %v, i1 false)
ret <vscale x 1 x i64> %r
}
Expand All @@ -141,6 +217,12 @@ define <vscale x 2 x i64> @vabs_nxv2i64(<vscale x 2 x i64> %v) {
; CHECK-NEXT: vrsub.vi v10, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v10
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv2i64:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e64, m2, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 2 x i64> @llvm.abs.nxv2i64(<vscale x 2 x i64> %v, i1 false)
ret <vscale x 2 x i64> %r
}
Expand All @@ -152,6 +234,12 @@ define <vscale x 4 x i64> @vabs_nxv4i64(<vscale x 4 x i64> %v) {
; CHECK-NEXT: vrsub.vi v12, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v12
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv4i64:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e64, m4, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 4 x i64> @llvm.abs.nxv4i64(<vscale x 4 x i64> %v, i1 false)
ret <vscale x 4 x i64> %r
}
Expand All @@ -163,6 +251,12 @@ define <vscale x 8 x i64> @vabs_nxv8i64(<vscale x 8 x i64> %v) {
; CHECK-NEXT: vrsub.vi v16, v8, 0
; CHECK-NEXT: vmax.vv v8, v8, v16
; CHECK-NEXT: ret
;
; ZVABD-LABEL: vabs_nxv8i64:
; ZVABD: # %bb.0:
; ZVABD-NEXT: vsetvli a0, zero, e64, m8, ta, ma
; ZVABD-NEXT: vabs.v v8, v8
; ZVABD-NEXT: ret
%r = call <vscale x 8 x i64> @llvm.abs.nxv8i64(<vscale x 8 x i64> %v, i1 false)
ret <vscale x 8 x i64> %r
}
Loading
Loading