3 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s
7 ; Test the simple case.
8 define i64 @f1(i64 %easy, ptr %ptr, i64 %limit) {
10 ; CHECK: clgfi %r4, 42
11 ; CHECK: locghe %r2, 0(%r3)
13 %cond = icmp ult i64 %limit, 42
14 %other = load i64, ptr %ptr
15 %res = select i1 %cond, i64 %easy, i64 %other
19 ; ...and again with the operands swapped.
20 define i64 @f2(i64 %easy, ptr %ptr, i64 %limit) {
22 ; CHECK: clgfi %r4, 42
23 ; CHECK: locgl %r2, 0(%r3)
25 %cond = icmp ult i64 %limit, 42
26 %other = load i64, ptr %ptr
27 %res = select i1 %cond, i64 %other, i64 %easy
31 ; Check the high end of the aligned LOCG range.
32 define i64 @f3(i64 %easy, ptr %base, i64 %limit) {
34 ; CHECK: clgfi %r4, 42
35 ; CHECK: locghe %r2, 524280(%r3)
37 %ptr = getelementptr i64, ptr %base, i64 65535
38 %cond = icmp ult i64 %limit, 42
39 %other = load i64, ptr %ptr
40 %res = select i1 %cond, i64 %easy, i64 %other
44 ; Check the next doubleword up. Other sequences besides this one would be OK.
45 define i64 @f4(i64 %easy, ptr %base, i64 %limit) {
47 ; CHECK: agfi %r3, 524288
48 ; CHECK: clgfi %r4, 42
49 ; CHECK: locghe %r2, 0(%r3)
51 %ptr = getelementptr i64, ptr %base, i64 65536
52 %cond = icmp ult i64 %limit, 42
53 %other = load i64, ptr %ptr
54 %res = select i1 %cond, i64 %easy, i64 %other
58 ; Check the low end of the LOCG range.
59 define i64 @f5(i64 %easy, ptr %base, i64 %limit) {
61 ; CHECK: clgfi %r4, 42
62 ; CHECK: locghe %r2, -524288(%r3)
64 %ptr = getelementptr i64, ptr %base, i64 -65536
65 %cond = icmp ult i64 %limit, 42
66 %other = load i64, ptr %ptr
67 %res = select i1 %cond, i64 %easy, i64 %other
71 ; Check the next doubleword down, with the same comments as f4.
72 define i64 @f6(i64 %easy, ptr %base, i64 %limit) {
74 ; CHECK: agfi %r3, -524296
75 ; CHECK: clgfi %r4, 42
76 ; CHECK: locghe %r2, 0(%r3)
78 %ptr = getelementptr i64, ptr %base, i64 -65537
79 %cond = icmp ult i64 %limit, 42
80 %other = load i64, ptr %ptr
81 %res = select i1 %cond, i64 %easy, i64 %other
85 ; Try a frame index base.
86 define i64 @f7(i64 %alt, i64 %limit) {
88 ; CHECK: brasl %r14, foo@PLT
89 ; CHECK: locghe %r2, {{[0-9]+}}(%r15)
92 %easy = call i64 @foo(ptr %ptr)
93 %cond = icmp ult i64 %limit, 42
94 %other = load i64, ptr %ptr
95 %res = select i1 %cond, i64 %easy, i64 %other
99 ; Try a case when an index is involved.
100 define i64 @f8(i64 %easy, i64 %limit, i64 %base, i64 %index) {
102 ; CHECK: clgfi %r3, 42
103 ; CHECK: locghe %r2, 0({{%r[1-5]}})
105 %add = add i64 %base, %index
106 %ptr = inttoptr i64 %add to ptr
107 %cond = icmp ult i64 %limit, 42
108 %other = load i64, ptr %ptr
109 %res = select i1 %cond, i64 %easy, i64 %other
113 ; Test that conditionally-executed loads do not use LOCG, since it is allowed
114 ; to trap even when the condition is false.
115 define i64 @f9(i64 %easy, i64 %limit, ptr %ptr) {
120 %cmp = icmp ule i64 %easy, %limit
121 br i1 %cmp, label %load, label %exit
124 %other = load i64, ptr %ptr
128 %res = phi i64 [ %easy, %entry ], [ %other, %load ]
132 ; Test that volatile loads do not use LOCG, since if the condition is false,
133 ; it is unspecified whether or not the load happens. LOCGR is fine though.
134 define i64 @f10(i64 %easy, ptr %ptr, i64 %limit) {
136 ; CHECK: lg {{%r[0-9]*}}, 0(%r3)
139 %cond = icmp ult i64 %limit, 42
140 %other = load volatile i64, ptr %ptr
141 %res = select i1 %cond, i64 %easy, i64 %other