3 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s
5 ; Run the test again to make sure it still works the same even
6 ; in the presence of the load-store-on-condition-2 facility.
7 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 | FileCheck %s
11 ; Test the simple case.
12 define i32 @f1(i32 %easy, ptr %ptr, i32 %limit) {
15 ; CHECK: loche %r2, 0(%r3)
17 %cond = icmp ult i32 %limit, 42
18 %other = load i32, ptr %ptr
19 %res = select i1 %cond, i32 %easy, i32 %other
23 ; ...and again with the operands swapped.
24 define i32 @f2(i32 %easy, ptr %ptr, i32 %limit) {
27 ; CHECK: locl %r2, 0(%r3)
29 %cond = icmp ult i32 %limit, 42
30 %other = load i32, ptr %ptr
31 %res = select i1 %cond, i32 %other, i32 %easy
35 ; Check the high end of the aligned LOC range.
36 define i32 @f3(i32 %easy, ptr %base, i32 %limit) {
39 ; CHECK: loche %r2, 524284(%r3)
41 %ptr = getelementptr i32, ptr %base, i64 131071
42 %cond = icmp ult i32 %limit, 42
43 %other = load i32, ptr %ptr
44 %res = select i1 %cond, i32 %easy, i32 %other
48 ; Check the next word up. Other sequences besides this one would be OK.
49 define i32 @f4(i32 %easy, ptr %base, i32 %limit) {
51 ; CHECK: agfi %r3, 524288
53 ; CHECK: loche %r2, 0(%r3)
55 %ptr = getelementptr i32, ptr %base, i64 131072
56 %cond = icmp ult i32 %limit, 42
57 %other = load i32, ptr %ptr
58 %res = select i1 %cond, i32 %easy, i32 %other
62 ; Check the low end of the LOC range.
63 define i32 @f5(i32 %easy, ptr %base, i32 %limit) {
66 ; CHECK: loche %r2, -524288(%r3)
68 %ptr = getelementptr i32, ptr %base, i64 -131072
69 %cond = icmp ult i32 %limit, 42
70 %other = load i32, ptr %ptr
71 %res = select i1 %cond, i32 %easy, i32 %other
75 ; Check the next word down, with the same comments as f4.
76 define i32 @f6(i32 %easy, ptr %base, i32 %limit) {
78 ; CHECK: agfi %r3, -524292
80 ; CHECK: loche %r2, 0(%r3)
82 %ptr = getelementptr i32, ptr %base, i64 -131073
83 %cond = icmp ult i32 %limit, 42
84 %other = load i32, ptr %ptr
85 %res = select i1 %cond, i32 %easy, i32 %other
89 ; Try a frame index base.
90 define i32 @f7(i32 %alt, i32 %limit) {
92 ; CHECK: brasl %r14, foo@PLT
93 ; CHECK: loche %r2, {{[0-9]+}}(%r15)
96 %easy = call i32 @foo(ptr %ptr)
97 %cond = icmp ult i32 %limit, 42
98 %other = load i32, ptr %ptr
99 %res = select i1 %cond, i32 %easy, i32 %other
103 ; Try a case when an index is involved.
104 define i32 @f8(i32 %easy, i32 %limit, i64 %base, i64 %index) {
106 ; CHECK: clfi %r3, 42
107 ; CHECK: loche %r2, 0({{%r[1-5]}})
109 %add = add i64 %base, %index
110 %ptr = inttoptr i64 %add to ptr
111 %cond = icmp ult i32 %limit, 42
112 %other = load i32, ptr %ptr
113 %res = select i1 %cond, i32 %easy, i32 %other
117 ; Test that conditionally-executed loads do not use LOC, since it is allowed
118 ; to trap even when the condition is false.
119 define i32 @f9(i32 %easy, i32 %limit, ptr %ptr) {
124 %cmp = icmp ule i32 %easy, %limit
125 br i1 %cmp, label %load, label %exit
128 %other = load i32, ptr %ptr
132 %res = phi i32 [ %easy, %entry ], [ %other, %load ]
136 ; Test that volatile loads do not use LOC, since if the condition is false,
137 ; it is unspecified whether or not the load happens. LOCR is fine though.
138 define i32 @f10(i32 %easy, ptr %ptr, i32 %limit) {
140 ; CHECK: l {{%r[0-9]*}}, 0(%r3)
143 %cond = icmp ult i32 %limit, 42
144 %other = load volatile i32, ptr %ptr
145 %res = select i1 %cond, i32 %easy, i32 %other