22; RUN: llc -mtriple=riscv32 -global-isel -global-isel-abort=1 < %s 2>&1 | FileCheck %s --check-prefixes=RV32
33; RUN: llc -mtriple=riscv64 -global-isel -global-isel-abort=1 < %s 2>&1 | FileCheck %s --check-prefixes=RV64
44
5+ ; FIXME: andi a0, a0, 1 is unneeded
56define i2 @bitreverse_i2 (i2 %x ) {
67; RV32-LABEL: bitreverse_i2:
78; RV32: # %bb.0:
@@ -18,12 +19,14 @@ define i2 @bitreverse_i2(i2 %x) {
1819; RV64-NEXT: andi a1, a1, 2
1920; RV64-NEXT: andi a0, a0, 3
2021; RV64-NEXT: srliw a0, a0, 1
22+ ; RV64-NEXT: andi a0, a0, 1
2123; RV64-NEXT: or a0, a1, a0
2224; RV64-NEXT: ret
2325 %rev = call i2 @llvm.bitreverse.i2 (i2 %x )
2426 ret i2 %rev
2527}
2628
29+ ; FIXME: andi a0, a0, 1 is unneeded
2730define i3 @bitreverse_i3 (i3 %x ) {
2831; RV32-LABEL: bitreverse_i3:
2932; RV32: # %bb.0:
@@ -44,12 +47,14 @@ define i3 @bitreverse_i3(i3 %x) {
4447; RV64-NEXT: andi a2, a0, 2
4548; RV64-NEXT: or a1, a1, a2
4649; RV64-NEXT: srliw a0, a0, 2
50+ ; RV64-NEXT: andi a0, a0, 1
4751; RV64-NEXT: or a0, a1, a0
4852; RV64-NEXT: ret
4953 %rev = call i3 @llvm.bitreverse.i3 (i3 %x )
5054 ret i3 %rev
5155}
5256
57+ ; FIXME: andi a0, a0, 1 is unneeded
5358define i4 @bitreverse_i4 (i4 %x ) {
5459; RV32-LABEL: bitreverse_i4:
5560; RV32: # %bb.0:
@@ -78,12 +83,14 @@ define i4 @bitreverse_i4(i4 %x) {
7883; RV64-NEXT: andi a2, a2, 2
7984; RV64-NEXT: or a1, a1, a2
8085; RV64-NEXT: srliw a0, a0, 3
86+ ; RV64-NEXT: andi a0, a0, 1
8187; RV64-NEXT: or a0, a1, a0
8288; RV64-NEXT: ret
8389 %rev = call i4 @llvm.bitreverse.i4 (i4 %x )
8490 ret i4 %rev
8591}
8692
93+ ; FIXME: andi a0, a0, 1 is unneeded
8794define i7 @bitreverse_i7 (i7 %x ) {
8895; RV32-LABEL: bitreverse_i7:
8996; RV32: # %bb.0:
@@ -128,6 +135,7 @@ define i7 @bitreverse_i7(i7 %x) {
128135; RV64-NEXT: or a2, a2, a3
129136; RV64-NEXT: or a1, a1, a2
130137; RV64-NEXT: srliw a0, a0, 6
138+ ; RV64-NEXT: andi a0, a0, 1
131139; RV64-NEXT: or a0, a1, a0
132140; RV64-NEXT: ret
133141 %rev = call i7 @llvm.bitreverse.i7 (i7 %x )
@@ -177,24 +185,27 @@ define i24 @bitreverse_i24(i24 %x) {
177185; RV64-NEXT: and a0, a0, a2
178186; RV64-NEXT: srliw a0, a0, 16
179187; RV64-NEXT: or a0, a0, a1
180- ; RV64-NEXT: lui a1, 1048335
181- ; RV64-NEXT: addi a1, a1, 240
188+ ; RV64-NEXT: lui a1, 65521
189+ ; RV64-NEXT: addi a1, a1, -241
190+ ; RV64-NEXT: slli a1, a1, 4
182191; RV64-NEXT: and a3, a1, a2
183192; RV64-NEXT: and a3, a0, a3
184193; RV64-NEXT: srliw a3, a3, 4
185194; RV64-NEXT: slli a0, a0, 4
186195; RV64-NEXT: and a0, a0, a1
187196; RV64-NEXT: or a0, a3, a0
188- ; RV64-NEXT: lui a1, 1047757
189- ; RV64-NEXT: addi a1, a1, -820
197+ ; RV64-NEXT: lui a1, 261939
198+ ; RV64-NEXT: addi a1, a1, 819
199+ ; RV64-NEXT: slli a1, a1, 2
190200; RV64-NEXT: and a3, a1, a2
191201; RV64-NEXT: and a3, a0, a3
192202; RV64-NEXT: srliw a3, a3, 2
193203; RV64-NEXT: slli a0, a0, 2
194204; RV64-NEXT: and a0, a0, a1
195205; RV64-NEXT: or a0, a3, a0
196- ; RV64-NEXT: lui a1, 1047211
197- ; RV64-NEXT: addiw a1, a1, -1366
206+ ; RV64-NEXT: lui a1, 523605
207+ ; RV64-NEXT: addiw a1, a1, 1365
208+ ; RV64-NEXT: slli a1, a1, 1
198209; RV64-NEXT: and a2, a1, a2
199210; RV64-NEXT: and a2, a0, a2
200211; RV64-NEXT: srliw a2, a2, 1
0 commit comments