Skip to content

Commit bafa934

Browse files
committed
[RISCV] Add test case for failure to use GREVIW for i32 bswap if result is not sign extended. NFC
1 parent 01d8715 commit bafa934

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

llvm/test/CodeGen/RISCV/rv64Zbp.ll

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,47 @@ define signext i32 @bswap_i32(i32 signext %a) nounwind {
933933
ret i32 %1
934934
}
935935

936+
; Similar to bswap_i32 but the result is not sign extended.
937+
; FIXME: We should use greviw here.
938+
define void @bswap_i32_nosext(i32 signext %a, i32* %x) nounwind {
939+
; RV64I-LABEL: bswap_i32_nosext:
940+
; RV64I: # %bb.0:
941+
; RV64I-NEXT: slli a2, a0, 8
942+
; RV64I-NEXT: addi a3, zero, 255
943+
; RV64I-NEXT: slli a4, a3, 32
944+
; RV64I-NEXT: and a2, a2, a4
945+
; RV64I-NEXT: slli a4, a0, 24
946+
; RV64I-NEXT: slli a5, a3, 40
947+
; RV64I-NEXT: and a4, a4, a5
948+
; RV64I-NEXT: or a2, a4, a2
949+
; RV64I-NEXT: slli a4, a0, 40
950+
; RV64I-NEXT: slli a3, a3, 48
951+
; RV64I-NEXT: and a3, a4, a3
952+
; RV64I-NEXT: slli a0, a0, 56
953+
; RV64I-NEXT: or a0, a0, a3
954+
; RV64I-NEXT: or a0, a0, a2
955+
; RV64I-NEXT: srli a0, a0, 32
956+
; RV64I-NEXT: sw a0, 0(a1)
957+
; RV64I-NEXT: ret
958+
;
959+
; RV64IB-LABEL: bswap_i32_nosext:
960+
; RV64IB: # %bb.0:
961+
; RV64IB-NEXT: rev8 a0, a0
962+
; RV64IB-NEXT: srli a0, a0, 32
963+
; RV64IB-NEXT: sw a0, 0(a1)
964+
; RV64IB-NEXT: ret
965+
;
966+
; RV64IBP-LABEL: bswap_i32_nosext:
967+
; RV64IBP: # %bb.0:
968+
; RV64IBP-NEXT: rev8 a0, a0
969+
; RV64IBP-NEXT: srli a0, a0, 32
970+
; RV64IBP-NEXT: sw a0, 0(a1)
971+
; RV64IBP-NEXT: ret
972+
%1 = tail call i32 @llvm.bswap.i32(i32 %a)
973+
store i32 %1, i32* %x
974+
ret void
975+
}
976+
936977
declare i64 @llvm.bswap.i64(i64)
937978

938979
define i64 @bswap_i64(i64 %a) {

0 commit comments

Comments
 (0)