1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+zbb -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefixes=RV32ZB
4 ; RUN: llc -mtriple=riscv64 -mattr=+zbb -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=RV64ZB
6 ; RUN: llc -mtriple=riscv32 -mattr=+zbkb -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefixes=RV32ZB
8 ; RUN: llc -mtriple=riscv64 -mattr=+zbkb -verify-machineinstrs < %s \
9 ; RUN: | FileCheck %s -check-prefixes=RV64ZB
11 ; TODO: These tests can be optmised, with x%8 == 0
12 ; fold (bswap(srl (bswap c), x)) -> (shl c, x)
13 ; fold (bswap(shl (bswap c), x)) -> (srl c, x)
15 declare i16 @llvm.bswap.i16(i16)
16 declare i32 @llvm.bswap.i32(i32)
17 declare i64 @llvm.bswap.i64(i64)
19 define i16 @test_bswap_srli_7_bswap_i16(i16 %a) nounwind {
20 ; RV32ZB-LABEL: test_bswap_srli_7_bswap_i16:
22 ; RV32ZB-NEXT: rev8 a0, a0
23 ; RV32ZB-NEXT: srli a0, a0, 23
24 ; RV32ZB-NEXT: rev8 a0, a0
25 ; RV32ZB-NEXT: srli a0, a0, 16
28 ; RV64ZB-LABEL: test_bswap_srli_7_bswap_i16:
30 ; RV64ZB-NEXT: rev8 a0, a0
31 ; RV64ZB-NEXT: srli a0, a0, 55
32 ; RV64ZB-NEXT: rev8 a0, a0
33 ; RV64ZB-NEXT: srli a0, a0, 48
35 %1 = call i16 @llvm.bswap.i16(i16 %a)
37 %3 = call i16 @llvm.bswap.i16(i16 %2)
41 define i16 @test_bswap_srli_8_bswap_i16(i16 %a) nounwind {
42 ; RV32ZB-LABEL: test_bswap_srli_8_bswap_i16:
44 ; RV32ZB-NEXT: slli a0, a0, 8
47 ; RV64ZB-LABEL: test_bswap_srli_8_bswap_i16:
49 ; RV64ZB-NEXT: slli a0, a0, 8
51 %1 = call i16 @llvm.bswap.i16(i16 %a)
53 %3 = call i16 @llvm.bswap.i16(i16 %2)
57 define i32 @test_bswap_srli_8_bswap_i32(i32 %a) nounwind {
58 ; RV32ZB-LABEL: test_bswap_srli_8_bswap_i32:
60 ; RV32ZB-NEXT: slli a0, a0, 8
63 ; RV64ZB-LABEL: test_bswap_srli_8_bswap_i32:
65 ; RV64ZB-NEXT: slliw a0, a0, 8
67 %1 = call i32 @llvm.bswap.i32(i32 %a)
69 %3 = call i32 @llvm.bswap.i32(i32 %2)
73 define i32 @test_bswap_srli_16_bswap_i32(i32 %a) nounwind {
74 ; RV32ZB-LABEL: test_bswap_srli_16_bswap_i32:
76 ; RV32ZB-NEXT: slli a0, a0, 16
79 ; RV64ZB-LABEL: test_bswap_srli_16_bswap_i32:
81 ; RV64ZB-NEXT: slliw a0, a0, 16
83 %1 = call i32 @llvm.bswap.i32(i32 %a)
85 %3 = call i32 @llvm.bswap.i32(i32 %2)
89 define i32 @test_bswap_srli_24_bswap_i32(i32 %a) nounwind {
90 ; RV32ZB-LABEL: test_bswap_srli_24_bswap_i32:
92 ; RV32ZB-NEXT: slli a0, a0, 24
95 ; RV64ZB-LABEL: test_bswap_srli_24_bswap_i32:
97 ; RV64ZB-NEXT: slliw a0, a0, 24
99 %1 = call i32 @llvm.bswap.i32(i32 %a)
101 %3 = call i32 @llvm.bswap.i32(i32 %2)
105 define i64 @test_bswap_srli_48_bswap_i64(i64 %a) nounwind {
106 ; RV32ZB-LABEL: test_bswap_srli_48_bswap_i64:
108 ; RV32ZB-NEXT: slli a1, a0, 16
109 ; RV32ZB-NEXT: li a0, 0
112 ; RV64ZB-LABEL: test_bswap_srli_48_bswap_i64:
114 ; RV64ZB-NEXT: slli a0, a0, 48
116 %1 = call i64 @llvm.bswap.i64(i64 %a)
118 %3 = call i64 @llvm.bswap.i64(i64 %2)
122 define i16 @test_bswap_shli_7_bswap_i16(i16 %a) nounwind {
123 ; RV32ZB-LABEL: test_bswap_shli_7_bswap_i16:
125 ; RV32ZB-NEXT: rev8 a0, a0
126 ; RV32ZB-NEXT: srli a0, a0, 16
127 ; RV32ZB-NEXT: slli a0, a0, 7
128 ; RV32ZB-NEXT: rev8 a0, a0
129 ; RV32ZB-NEXT: srli a0, a0, 16
132 ; RV64ZB-LABEL: test_bswap_shli_7_bswap_i16:
134 ; RV64ZB-NEXT: rev8 a0, a0
135 ; RV64ZB-NEXT: srli a0, a0, 48
136 ; RV64ZB-NEXT: slli a0, a0, 7
137 ; RV64ZB-NEXT: rev8 a0, a0
138 ; RV64ZB-NEXT: srli a0, a0, 48
140 %1 = call i16 @llvm.bswap.i16(i16 %a)
142 %3 = call i16 @llvm.bswap.i16(i16 %2)
146 define i16 @test_bswap_shli_8_bswap_i16(i16 %a) nounwind {
147 ; RV32ZB-LABEL: test_bswap_shli_8_bswap_i16:
149 ; RV32ZB-NEXT: slli a0, a0, 16
150 ; RV32ZB-NEXT: srli a0, a0, 24
153 ; RV64ZB-LABEL: test_bswap_shli_8_bswap_i16:
155 ; RV64ZB-NEXT: slli a0, a0, 48
156 ; RV64ZB-NEXT: srli a0, a0, 56
158 %1 = call i16 @llvm.bswap.i16(i16 %a)
160 %3 = call i16 @llvm.bswap.i16(i16 %2)
164 define i32 @test_bswap_shli_8_bswap_i32(i32 %a) nounwind {
165 ; RV32ZB-LABEL: test_bswap_shli_8_bswap_i32:
167 ; RV32ZB-NEXT: srli a0, a0, 8
170 ; RV64ZB-LABEL: test_bswap_shli_8_bswap_i32:
172 ; RV64ZB-NEXT: srliw a0, a0, 8
174 %1 = call i32 @llvm.bswap.i32(i32 %a)
176 %3 = call i32 @llvm.bswap.i32(i32 %2)
180 define i32 @test_bswap_shli_16_bswap_i32(i32 %a) nounwind {
181 ; RV32ZB-LABEL: test_bswap_shli_16_bswap_i32:
183 ; RV32ZB-NEXT: srli a0, a0, 16
186 ; RV64ZB-LABEL: test_bswap_shli_16_bswap_i32:
188 ; RV64ZB-NEXT: srliw a0, a0, 16
190 %1 = call i32 @llvm.bswap.i32(i32 %a)
192 %3 = call i32 @llvm.bswap.i32(i32 %2)
196 define i32 @test_bswap_shli_24_bswap_i32(i32 %a) nounwind {
197 ; RV32ZB-LABEL: test_bswap_shli_24_bswap_i32:
199 ; RV32ZB-NEXT: srli a0, a0, 24
202 ; RV64ZB-LABEL: test_bswap_shli_24_bswap_i32:
204 ; RV64ZB-NEXT: srliw a0, a0, 24
206 %1 = call i32 @llvm.bswap.i32(i32 %a)
208 %3 = call i32 @llvm.bswap.i32(i32 %2)
212 define i64 @test_bswap_shli_48_bswap_i64(i64 %a) nounwind {
213 ; RV32ZB-LABEL: test_bswap_shli_48_bswap_i64:
215 ; RV32ZB-NEXT: srli a0, a1, 16
216 ; RV32ZB-NEXT: li a1, 0
219 ; RV64ZB-LABEL: test_bswap_shli_48_bswap_i64:
221 ; RV64ZB-NEXT: srli a0, a0, 48
223 %1 = call i64 @llvm.bswap.i64(i64 %a)
225 %3 = call i64 @llvm.bswap.i64(i64 %2)