1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s --check-prefix=LA32
4 ; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s --check-prefix=LA64
7 declare i16 @llvm.bswap.i16(i16)
8 declare i32 @llvm.bswap.i32(i32)
9 declare i48 @llvm.bswap.i48(i48)
10 declare i64 @llvm.bswap.i64(i64)
11 declare i80 @llvm.bswap.i80(i80)
12 declare i128 @llvm.bswap.i128(i128)
14 define i16 @test_bswap_i16(i16 %a) nounwind {
15 ; LA32-LABEL: test_bswap_i16:
17 ; LA32-NEXT: revb.2h $a0, $a0
20 ; LA64-LABEL: test_bswap_i16:
22 ; LA64-NEXT: revb.2h $a0, $a0
24 %tmp = call i16 @llvm.bswap.i16(i16 %a)
28 define i32 @test_bswap_i32(i32 %a) nounwind {
29 ; LA32-LABEL: test_bswap_i32:
31 ; LA32-NEXT: revb.2h $a0, $a0
32 ; LA32-NEXT: rotri.w $a0, $a0, 16
35 ; LA64-LABEL: test_bswap_i32:
37 ; LA64-NEXT: revb.2w $a0, $a0
39 %tmp = call i32 @llvm.bswap.i32(i32 %a)
43 define i64 @test_bswap_i64(i64 %a) nounwind {
44 ; LA32-LABEL: test_bswap_i64:
46 ; LA32-NEXT: revb.2h $a1, $a1
47 ; LA32-NEXT: rotri.w $a2, $a1, 16
48 ; LA32-NEXT: revb.2h $a0, $a0
49 ; LA32-NEXT: rotri.w $a1, $a0, 16
50 ; LA32-NEXT: move $a0, $a2
53 ; LA64-LABEL: test_bswap_i64:
55 ; LA64-NEXT: revb.d $a0, $a0
57 %tmp = call i64 @llvm.bswap.i64(i64 %a)
61 ;; Bswap on non-native integer widths.
63 define i48 @test_bswap_i48(i48 %a) nounwind {
64 ; LA32-LABEL: test_bswap_i48:
66 ; LA32-NEXT: revb.2h $a0, $a0
67 ; LA32-NEXT: rotri.w $a2, $a0, 16
68 ; LA32-NEXT: revb.2h $a0, $a1
69 ; LA32-NEXT: rotri.w $a0, $a0, 16
70 ; LA32-NEXT: bytepick.w $a0, $a0, $a2, 2
71 ; LA32-NEXT: srli.w $a1, $a2, 16
74 ; LA64-LABEL: test_bswap_i48:
76 ; LA64-NEXT: revb.d $a0, $a0
77 ; LA64-NEXT: srli.d $a0, $a0, 16
79 %tmp = call i48 @llvm.bswap.i48(i48 %a)
83 define i80 @test_bswap_i80(i80 %a) nounwind {
84 ; LA32-LABEL: test_bswap_i80:
86 ; LA32-NEXT: ld.w $a2, $a1, 0
87 ; LA32-NEXT: revb.2h $a2, $a2
88 ; LA32-NEXT: rotri.w $a2, $a2, 16
89 ; LA32-NEXT: ld.w $a3, $a1, 4
90 ; LA32-NEXT: revb.2h $a3, $a3
91 ; LA32-NEXT: rotri.w $a3, $a3, 16
92 ; LA32-NEXT: bytepick.w $a4, $a3, $a2, 2
93 ; LA32-NEXT: st.w $a4, $a0, 4
94 ; LA32-NEXT: ld.w $a1, $a1, 8
95 ; LA32-NEXT: revb.2h $a1, $a1
96 ; LA32-NEXT: rotri.w $a1, $a1, 16
97 ; LA32-NEXT: bytepick.w $a1, $a1, $a3, 2
98 ; LA32-NEXT: st.w $a1, $a0, 0
99 ; LA32-NEXT: srli.w $a1, $a2, 16
100 ; LA32-NEXT: st.h $a1, $a0, 8
103 ; LA64-LABEL: test_bswap_i80:
105 ; LA64-NEXT: revb.d $a2, $a0
106 ; LA64-NEXT: revb.d $a0, $a1
107 ; LA64-NEXT: bytepick.d $a0, $a0, $a2, 2
108 ; LA64-NEXT: srli.d $a1, $a2, 48
110 %tmp = call i80 @llvm.bswap.i80(i80 %a)
114 define i128 @test_bswap_i128(i128 %a) nounwind {
115 ; LA32-LABEL: test_bswap_i128:
117 ; LA32-NEXT: ld.w $a2, $a1, 0
118 ; LA32-NEXT: revb.2h $a2, $a2
119 ; LA32-NEXT: rotri.w $a2, $a2, 16
120 ; LA32-NEXT: st.w $a2, $a0, 12
121 ; LA32-NEXT: ld.w $a2, $a1, 4
122 ; LA32-NEXT: revb.2h $a2, $a2
123 ; LA32-NEXT: rotri.w $a2, $a2, 16
124 ; LA32-NEXT: st.w $a2, $a0, 8
125 ; LA32-NEXT: ld.w $a2, $a1, 8
126 ; LA32-NEXT: revb.2h $a2, $a2
127 ; LA32-NEXT: rotri.w $a2, $a2, 16
128 ; LA32-NEXT: st.w $a2, $a0, 4
129 ; LA32-NEXT: ld.w $a1, $a1, 12
130 ; LA32-NEXT: revb.2h $a1, $a1
131 ; LA32-NEXT: rotri.w $a1, $a1, 16
132 ; LA32-NEXT: st.w $a1, $a0, 0
135 ; LA64-LABEL: test_bswap_i128:
137 ; LA64-NEXT: revb.d $a2, $a1
138 ; LA64-NEXT: revb.d $a1, $a0
139 ; LA64-NEXT: move $a0, $a2
141 %tmp = call i128 @llvm.bswap.i128(i128 %a)