Skip to content

Commit cd2a9ff

Browse files
committed
[RISCV] Select int_riscv_vsll with shift of 1 to vadd.vv.
Add might be faster than shift. We can't do this earlier without using a Freeze instruction. This is the intrinsic version of D106689. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D118013
1 parent c133516 commit cd2a9ff

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4543,6 +4543,30 @@ defm : VPatBinaryV_VV_VX_VI<"int_riscv_vsrl", "PseudoVSRL", AllIntegerVectors,
45434543
defm : VPatBinaryV_VV_VX_VI<"int_riscv_vsra", "PseudoVSRA", AllIntegerVectors,
45444544
uimm5>;
45454545

4546+
foreach vti = AllIntegerVectors in {
4547+
// Emit shift by 1 as an add since it might be faster.
4548+
def : Pat<(vti.Vector (int_riscv_vsll (vti.Vector vti.RegClass:$rs1),
4549+
(XLenVT 1), VLOpFrag)),
4550+
(!cast<Instruction>("PseudoVADD_VV_"#vti.LMul.MX) vti.RegClass:$rs1,
4551+
vti.RegClass:$rs1,
4552+
GPR:$vl,
4553+
vti.Log2SEW)>;
4554+
def : Pat<(vti.Vector (int_riscv_vsll_mask (vti.Vector vti.RegClass:$merge),
4555+
(vti.Vector vti.RegClass:$rs1),
4556+
(XLenVT 1),
4557+
(vti.Mask V0),
4558+
VLOpFrag,
4559+
(XLenVT timm:$policy))),
4560+
(!cast<Instruction>("PseudoVADD_VV_"#vti.LMul.MX#"_MASK")
4561+
vti.RegClass:$merge,
4562+
vti.RegClass:$rs1,
4563+
vti.RegClass:$rs1,
4564+
(vti.Mask V0),
4565+
GPR:$vl,
4566+
vti.Log2SEW,
4567+
(XLenVT timm:$policy))>;
4568+
}
4569+
45464570
//===----------------------------------------------------------------------===//
45474571
// 12.7. Vector Narrowing Integer Right Shift Instructions
45484572
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/rvv/vsll-rv32.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,21 @@ entry:
20002000
ret <vscale x 1 x i8> %a
20012001
}
20022002

2003+
define <vscale x 1 x i8> @intrinsic_vsll_1_nxv1i8_nxv1i8_i8(<vscale x 1 x i8> %0, i32 %1) nounwind {
2004+
; CHECK-LABEL: intrinsic_vsll_1_nxv1i8_nxv1i8_i8:
2005+
; CHECK: # %bb.0: # %entry
2006+
; CHECK-NEXT: vsetvli zero, a0, e8, mf8, ta, mu
2007+
; CHECK-NEXT: vadd.vv v8, v8, v8
2008+
; CHECK-NEXT: ret
2009+
entry:
2010+
%a = call <vscale x 1 x i8> @llvm.riscv.vsll.nxv1i8(
2011+
<vscale x 1 x i8> %0,
2012+
i32 1,
2013+
i32 %1)
2014+
2015+
ret <vscale x 1 x i8> %a
2016+
}
2017+
20032018
define <vscale x 1 x i8> @intrinsic_vsll_mask_vi_nxv1i8_nxv1i8_i8(<vscale x 1 x i8> %0, <vscale x 1 x i8> %1, <vscale x 1 x i1> %2, i32 %3) nounwind {
20042019
; CHECK-LABEL: intrinsic_vsll_mask_vi_nxv1i8_nxv1i8_i8:
20052020
; CHECK: # %bb.0: # %entry
@@ -2017,6 +2032,23 @@ entry:
20172032
ret <vscale x 1 x i8> %a
20182033
}
20192034

2035+
define <vscale x 1 x i8> @intrinsic_vsll_mask_1_nxv1i8_nxv1i8_i8(<vscale x 1 x i8> %0, <vscale x 1 x i8> %1, <vscale x 1 x i1> %2, i32 %3) nounwind {
2036+
; CHECK-LABEL: intrinsic_vsll_mask_1_nxv1i8_nxv1i8_i8:
2037+
; CHECK: # %bb.0: # %entry
2038+
; CHECK-NEXT: vsetvli zero, a0, e8, mf8, ta, mu
2039+
; CHECK-NEXT: vadd.vv v8, v9, v9, v0.t
2040+
; CHECK-NEXT: ret
2041+
entry:
2042+
%a = call <vscale x 1 x i8> @llvm.riscv.vsll.mask.nxv1i8(
2043+
<vscale x 1 x i8> %0,
2044+
<vscale x 1 x i8> %1,
2045+
i32 1,
2046+
<vscale x 1 x i1> %2,
2047+
i32 %3, i32 1)
2048+
2049+
ret <vscale x 1 x i8> %a
2050+
}
2051+
20202052
define <vscale x 2 x i8> @intrinsic_vsll_vi_nxv2i8_nxv2i8_i8(<vscale x 2 x i8> %0, i32 %1) nounwind {
20212053
; CHECK-LABEL: intrinsic_vsll_vi_nxv2i8_nxv2i8_i8:
20222054
; CHECK: # %bb.0: # %entry

llvm/test/CodeGen/RISCV/rvv/vsll-rv64.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,21 @@ entry:
20002000
ret <vscale x 1 x i8> %a
20012001
}
20022002

2003+
define <vscale x 1 x i8> @intrinsic_vsll_1_nxv1i8_nxv1i8_i8(<vscale x 1 x i8> %0, i64 %1) nounwind {
2004+
; CHECK-LABEL: intrinsic_vsll_1_nxv1i8_nxv1i8_i8:
2005+
; CHECK: # %bb.0: # %entry
2006+
; CHECK-NEXT: vsetvli zero, a0, e8, mf8, ta, mu
2007+
; CHECK-NEXT: vadd.vv v8, v8, v8
2008+
; CHECK-NEXT: ret
2009+
entry:
2010+
%a = call <vscale x 1 x i8> @llvm.riscv.vsll.nxv1i8(
2011+
<vscale x 1 x i8> %0,
2012+
i64 1,
2013+
i64 %1)
2014+
2015+
ret <vscale x 1 x i8> %a
2016+
}
2017+
20032018
define <vscale x 1 x i8> @intrinsic_vsll_mask_vi_nxv1i8_nxv1i8_i8(<vscale x 1 x i8> %0, <vscale x 1 x i8> %1, <vscale x 1 x i1> %2, i64 %3) nounwind {
20042019
; CHECK-LABEL: intrinsic_vsll_mask_vi_nxv1i8_nxv1i8_i8:
20052020
; CHECK: # %bb.0: # %entry
@@ -2017,6 +2032,23 @@ entry:
20172032
ret <vscale x 1 x i8> %a
20182033
}
20192034

2035+
define <vscale x 1 x i8> @intrinsic_vsll_mask_1_nxv1i8_nxv1i8_i8(<vscale x 1 x i8> %0, <vscale x 1 x i8> %1, <vscale x 1 x i1> %2, i64 %3) nounwind {
2036+
; CHECK-LABEL: intrinsic_vsll_mask_1_nxv1i8_nxv1i8_i8:
2037+
; CHECK: # %bb.0: # %entry
2038+
; CHECK-NEXT: vsetvli zero, a0, e8, mf8, ta, mu
2039+
; CHECK-NEXT: vadd.vv v8, v9, v9, v0.t
2040+
; CHECK-NEXT: ret
2041+
entry:
2042+
%a = call <vscale x 1 x i8> @llvm.riscv.vsll.mask.nxv1i8(
2043+
<vscale x 1 x i8> %0,
2044+
<vscale x 1 x i8> %1,
2045+
i64 1,
2046+
<vscale x 1 x i1> %2,
2047+
i64 %3, i64 1)
2048+
2049+
ret <vscale x 1 x i8> %a
2050+
}
2051+
20202052
define <vscale x 2 x i8> @intrinsic_vsll_vi_nxv2i8_nxv2i8_i8(<vscale x 2 x i8> %0, i64 %1) nounwind {
20212053
; CHECK-LABEL: intrinsic_vsll_vi_nxv2i8_nxv2i8_i8:
20222054
; CHECK: # %bb.0: # %entry

0 commit comments

Comments
 (0)