1 ; Test 32-bit byteswaps from memory to registers.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 declare i32 @llvm.bswap.i32(i32 %a)
7 ; Check LRV with no displacement.
8 define i32 @f1(ptr %src) {
10 ; CHECK: lrv %r2, 0(%r2)
12 %a = load i32, ptr %src
13 %swapped = call i32 @llvm.bswap.i32(i32 %a)
17 ; Check the high end of the aligned LRV range.
18 define i32 @f2(ptr %src) {
20 ; CHECK: lrv %r2, 524284(%r2)
22 %ptr = getelementptr i32, ptr %src, i64 131071
23 %a = load i32, ptr %ptr
24 %swapped = call i32 @llvm.bswap.i32(i32 %a)
28 ; Check the next word up, which needs separate address logic.
29 ; Other sequences besides this one would be OK.
30 define i32 @f3(ptr %src) {
32 ; CHECK: agfi %r2, 524288
33 ; CHECK: lrv %r2, 0(%r2)
35 %ptr = getelementptr i32, ptr %src, i64 131072
36 %a = load i32, ptr %ptr
37 %swapped = call i32 @llvm.bswap.i32(i32 %a)
41 ; Check the high end of the negative aligned LRV range.
42 define i32 @f4(ptr %src) {
44 ; CHECK: lrv %r2, -4(%r2)
46 %ptr = getelementptr i32, ptr %src, i64 -1
47 %a = load i32, ptr %ptr
48 %swapped = call i32 @llvm.bswap.i32(i32 %a)
52 ; Check the low end of the LRV range.
53 define i32 @f5(ptr %src) {
55 ; CHECK: lrv %r2, -524288(%r2)
57 %ptr = getelementptr i32, ptr %src, i64 -131072
58 %a = load i32, ptr %ptr
59 %swapped = call i32 @llvm.bswap.i32(i32 %a)
63 ; Check the next word down, which needs separate address logic.
64 ; Other sequences besides this one would be OK.
65 define i32 @f6(ptr %src) {
67 ; CHECK: agfi %r2, -524292
68 ; CHECK: lrv %r2, 0(%r2)
70 %ptr = getelementptr i32, ptr %src, i64 -131073
71 %a = load i32, ptr %ptr
72 %swapped = call i32 @llvm.bswap.i32(i32 %a)
76 ; Check that LRV allows an index.
77 define i32 @f7(i64 %src, i64 %index) {
79 ; CHECK: lrv %r2, 524287({{%r3,%r2|%r2,%r3}})
81 %add1 = add i64 %src, %index
82 %add2 = add i64 %add1, 524287
83 %ptr = inttoptr i64 %add2 to ptr
84 %a = load i32, ptr %ptr
85 %swapped = call i32 @llvm.bswap.i32(i32 %a)
89 ; Test a case where we spill the source of at least one LRVR. We want
90 ; to use LRV if possible.
91 define i32 @f8(ptr %ptr0) {
93 ; CHECK: lrv {{%r[0-9]+}}, 16{{[04]}}(%r15)
96 %val0 = call i32 @foo()
97 %val1 = call i32 @foo()
98 %val2 = call i32 @foo()
99 %val3 = call i32 @foo()
100 %val4 = call i32 @foo()
101 %val5 = call i32 @foo()
102 %val6 = call i32 @foo()
103 %val7 = call i32 @foo()
104 %val8 = call i32 @foo()
105 %val9 = call i32 @foo()
107 %swapped0 = call i32 @llvm.bswap.i32(i32 %val0)
108 %swapped1 = call i32 @llvm.bswap.i32(i32 %val1)
109 %swapped2 = call i32 @llvm.bswap.i32(i32 %val2)
110 %swapped3 = call i32 @llvm.bswap.i32(i32 %val3)
111 %swapped4 = call i32 @llvm.bswap.i32(i32 %val4)
112 %swapped5 = call i32 @llvm.bswap.i32(i32 %val5)
113 %swapped6 = call i32 @llvm.bswap.i32(i32 %val6)
114 %swapped7 = call i32 @llvm.bswap.i32(i32 %val7)
115 %swapped8 = call i32 @llvm.bswap.i32(i32 %val8)
116 %swapped9 = call i32 @llvm.bswap.i32(i32 %val9)
118 %ret1 = add i32 %swapped0, %swapped1
119 %ret2 = add i32 %ret1, %swapped2
120 %ret3 = add i32 %ret2, %swapped3
121 %ret4 = add i32 %ret3, %swapped4
122 %ret5 = add i32 %ret4, %swapped5
123 %ret6 = add i32 %ret5, %swapped6
124 %ret7 = add i32 %ret6, %swapped7
125 %ret8 = add i32 %ret7, %swapped8
126 %ret9 = add i32 %ret8, %swapped9