Skip to content

Commit e42ab4c

Browse files
authored
[RISCV] Handle zvbb instructions in getVectorLowDemandedScalarBits. (#129011)
1 parent db0e7c7 commit e42ab4c

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4107,7 +4107,6 @@ bool RISCV::hasEqualFRM(const MachineInstr &MI1, const MachineInstr &MI2) {
41074107

41084108
std::optional<unsigned>
41094109
RISCV::getVectorLowDemandedScalarBits(uint16_t Opcode, unsigned Log2SEW) {
4110-
// TODO: Handle Zvbb instructions
41114110
switch (Opcode) {
41124111
default:
41134112
return std::nullopt;
@@ -4119,6 +4118,9 @@ RISCV::getVectorLowDemandedScalarBits(uint16_t Opcode, unsigned Log2SEW) {
41194118
// 12.4. Vector Single-Width Scaling Shift Instructions
41204119
case RISCV::VSSRL_VX:
41214120
case RISCV::VSSRA_VX:
4121+
// Zvbb
4122+
case RISCV::VROL_VX:
4123+
case RISCV::VROR_VX:
41224124
// Only the low lg2(SEW) bits of the shift-amount value are used.
41234125
return Log2SEW;
41244126

@@ -4128,6 +4130,8 @@ RISCV::getVectorLowDemandedScalarBits(uint16_t Opcode, unsigned Log2SEW) {
41284130
// 12.5. Vector Narrowing Fixed-Point Clip Instructions
41294131
case RISCV::VNCLIPU_WX:
41304132
case RISCV::VNCLIP_WX:
4133+
// Zvbb
4134+
case RISCV::VWSLL_VX:
41314135
// Only the low lg2(2*SEW) bits of the shift-amount value are used.
41324136
return Log2SEW + 1;
41334137

@@ -4213,6 +4217,8 @@ RISCV::getVectorLowDemandedScalarBits(uint16_t Opcode, unsigned Log2SEW) {
42134217
case RISCV::VSMUL_VX:
42144218
// 16.1. Integer Scalar Move Instructions
42154219
case RISCV::VMV_S_X:
4220+
// Zvbb
4221+
case RISCV::VANDN_VX:
42164222
return 1U << Log2SEW;
42174223
}
42184224
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=riscv64 -mattr=+v,+zvbb,+prefer-w-inst \
3+
; RUN: -verify-machineinstrs < %s | FileCheck %s
4+
5+
define <vscale x 1 x i8> @vrol_vx_nxv1i8(<vscale x 1 x i8> %a, i8 %b) {
6+
; CHECK-LABEL: vrol_vx_nxv1i8:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: addiw a0, a0, 1
9+
; CHECK-NEXT: vsetvli a1, zero, e8, mf8, ta, ma
10+
; CHECK-NEXT: vrol.vx v8, v8, a0
11+
; CHECK-NEXT: ret
12+
%s = add i8 %b, 1
13+
%b.head = insertelement <vscale x 1 x i8> poison, i8 %s, i32 0
14+
%b.splat = shufflevector <vscale x 1 x i8> %b.head, <vscale x 1 x i8> poison, <vscale x 1 x i32> zeroinitializer
15+
%x = call <vscale x 1 x i8> @llvm.fshl.nxv1i8(<vscale x 1 x i8> %a, <vscale x 1 x i8> %a, <vscale x 1 x i8> %b.splat)
16+
ret <vscale x 1 x i8> %x
17+
}
18+
19+
define <vscale x 1 x i8> @vror_vx_nxv1i8(<vscale x 1 x i8> %a, i8 %b) {
20+
; CHECK-LABEL: vror_vx_nxv1i8:
21+
; CHECK: # %bb.0:
22+
; CHECK-NEXT: addiw a0, a0, 1
23+
; CHECK-NEXT: vsetvli a1, zero, e8, mf8, ta, ma
24+
; CHECK-NEXT: vror.vx v8, v8, a0
25+
; CHECK-NEXT: ret
26+
%s = add i8 %b, 1
27+
%b.head = insertelement <vscale x 1 x i8> poison, i8 %s, i32 0
28+
%b.splat = shufflevector <vscale x 1 x i8> %b.head, <vscale x 1 x i8> poison, <vscale x 1 x i32> zeroinitializer
29+
%x = call <vscale x 1 x i8> @llvm.fshr.nxv1i8(<vscale x 1 x i8> %a, <vscale x 1 x i8> %a, <vscale x 1 x i8> %b.splat)
30+
ret <vscale x 1 x i8> %x
31+
}
32+
33+
define <vscale x 2 x i64> @vwsll_vx_i8_nxv2i64_zext(<vscale x 2 x i32> %a, i8 %b) {
34+
; CHECK-LABEL: vwsll_vx_i8_nxv2i64_zext:
35+
; CHECK: # %bb.0:
36+
; CHECK-NEXT: addiw a0, a0, 1
37+
; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, ma
38+
; CHECK-NEXT: vwsll.vx v10, v8, a0
39+
; CHECK-NEXT: vmv2r.v v8, v10
40+
; CHECK-NEXT: ret
41+
%s = add i8 %b, 1
42+
%head = insertelement <vscale x 2 x i8> poison, i8 %s, i32 0
43+
%splat = shufflevector <vscale x 2 x i8> %head, <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer
44+
%x = zext <vscale x 2 x i32> %a to <vscale x 2 x i64>
45+
%y = zext <vscale x 2 x i8> %splat to <vscale x 2 x i64>
46+
%z = shl <vscale x 2 x i64> %x, %y
47+
ret <vscale x 2 x i64> %z
48+
}
49+
50+
define <vscale x 1 x i8> @vandn_vx_nxv1i8(i8 %x, <vscale x 1 x i8> %y) {
51+
; CHECK-LABEL: vandn_vx_nxv1i8:
52+
; CHECK: # %bb.0:
53+
; CHECK-NEXT: addiw a0, a0, 1
54+
; CHECK-NEXT: vsetvli a1, zero, e8, mf8, ta, ma
55+
; CHECK-NEXT: vandn.vx v8, v8, a0
56+
; CHECK-NEXT: ret
57+
%s = add i8 %x, 1
58+
%a = xor i8 %s, -1
59+
%head = insertelement <vscale x 1 x i8> poison, i8 %a, i32 0
60+
%splat = shufflevector <vscale x 1 x i8> %head, <vscale x 1 x i8> poison, <vscale x 1 x i32> zeroinitializer
61+
%b = and <vscale x 1 x i8> %splat, %y
62+
ret <vscale x 1 x i8> %b
63+
}

0 commit comments

Comments
 (0)