1; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z14 | FileCheck %s
2; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z15 | FileCheck %s
3;
4; Test that a reload of a LOCGR/SELGR operand can be folded into a LOC
5; instruction.
6
7declare i64 @foo()
8declare i32 @foo32()
9
10; Check that conditional loads of spilled values can use LOCG rather than LOCGR.
11define void @f0(i64 *%ptr0, i64 *%dstPtr) {
12; CHECK-LABEL: f0:
13; CHECK: brasl %r14, foo@PLT
14; CHECK: locglh {{.*}}           # 8-byte Folded Reload
15; CHECK: br %r14
16  %ptr1 = getelementptr i64, i64 *%ptr0, i64 2
17  %ptr2 = getelementptr i64, i64 *%ptr0, i64 4
18  %ptr3 = getelementptr i64, i64 *%ptr0, i64 6
19  %ptr4 = getelementptr i64, i64 *%ptr0, i64 8
20  %ptr5 = getelementptr i64, i64 *%ptr0, i64 10
21  %ptr6 = getelementptr i64, i64 *%ptr0, i64 12
22  %ptr7 = getelementptr i64, i64 *%ptr0, i64 14
23  %ptr8 = getelementptr i64, i64 *%ptr0, i64 16
24  %ptr9 = getelementptr i64, i64 *%ptr0, i64 18
25
26  %val0 = load i64, i64 *%ptr0
27  %val1 = load i64, i64 *%ptr1
28  %val2 = load i64, i64 *%ptr2
29  %val3 = load i64, i64 *%ptr3
30  %val4 = load i64, i64 *%ptr4
31  %val5 = load i64, i64 *%ptr5
32  %val6 = load i64, i64 *%ptr6
33  %val7 = load i64, i64 *%ptr7
34  %val8 = load i64, i64 *%ptr8
35  %val9 = load i64, i64 *%ptr9
36
37  %ret = call i64 @foo()
38
39  %add0 = add i64 %ret, %val0
40  %add1 = add i64 %add0, %val1
41  %add2 = add i64 %add1, %val2
42  %add3 = add i64 %add2, %val3
43  %add4 = add i64 %add3, %val4
44  %add5 = add i64 %add4, %val5
45  %add6 = add i64 %add5, %val6
46  %add7 = add i64 %add6, %val7
47  %add8 = add i64 %add7, %val8
48
49  %cond = icmp eq i64 %add7, %add8
50  %res = select i1 %cond, i64 %add8, i64 %val9
51
52  store i64 %res, i64* %dstPtr
53  ret void
54}
55
56; Check that conditional loads of spilled values can use LOC rather than LOCR.
57define void @f1(i32 *%ptr0, i32 *%dstPtr) {
58; CHECK-LABEL: f1:
59; CHECK: brasl %r14, foo32@PLT
60; CHECK: loclh {{.*}}            # 4-byte Folded Reload
61; CHECK: br %r14
62  %ptr1 = getelementptr i32, i32 *%ptr0, i32 2
63  %ptr2 = getelementptr i32, i32 *%ptr0, i32 4
64  %ptr3 = getelementptr i32, i32 *%ptr0, i32 6
65  %ptr4 = getelementptr i32, i32 *%ptr0, i32 8
66  %ptr5 = getelementptr i32, i32 *%ptr0, i32 10
67  %ptr6 = getelementptr i32, i32 *%ptr0, i32 12
68  %ptr7 = getelementptr i32, i32 *%ptr0, i32 14
69  %ptr8 = getelementptr i32, i32 *%ptr0, i32 16
70  %ptr9 = getelementptr i32, i32 *%ptr0, i32 18
71
72  %val0 = load i32, i32 *%ptr0
73  %val1 = load i32, i32 *%ptr1
74  %val2 = load i32, i32 *%ptr2
75  %val3 = load i32, i32 *%ptr3
76  %val4 = load i32, i32 *%ptr4
77  %val5 = load i32, i32 *%ptr5
78  %val6 = load i32, i32 *%ptr6
79  %val7 = load i32, i32 *%ptr7
80  %val8 = load i32, i32 *%ptr8
81  %val9 = load i32, i32 *%ptr9
82
83  %ret = call i32 @foo32()
84
85  %add0 = add i32 %ret, %val0
86  %add1 = add i32 %add0, %val1
87  %add2 = add i32 %add1, %val2
88  %add3 = add i32 %add2, %val3
89  %add4 = add i32 %add3, %val4
90  %add5 = add i32 %add4, %val5
91  %add6 = add i32 %add5, %val6
92  %add7 = add i32 %add6, %val7
93  %add8 = add i32 %add7, %val8
94
95  %cond = icmp eq i32 %add7, %add8
96  %res = select i1 %cond, i32 %add8, i32 %val9
97
98  store i32 %res, i32* %dstPtr
99  ret void
100}
101