1 ; RUN: llc < %s -mtriple=s390x-linux-gnu -verify-machineinstrs | FileCheck %s
2 ; RUN: llc < %s -mtriple=s390x-linux-gnu -O0 -verify-machineinstrs | FileCheck --check-prefix=CHECK-O0 %s
6 ; Test how llvm handles return type of {i16, i8}. The return value will be
7 ; passed in %r2 and %r3.
10 ; CHECK: brasl %r14, gen
11 ; CHECK-DAG: lhr %{{r[0,2]+}}, %r2
12 ; CHECK-DAG: lbr %{{r[0,2]+}}, %r3
14 ; CHECK-O0-LABEL: test
16 ; CHECK-O0: brasl %r14, gen
17 ; CHECK-O0-DAG: lhr %r2, %r2
18 ; CHECK-O0-DAG: lbr %[[REG2:r[0-9]+]], %r3
19 ; CHECK-O0: ar %r2, %[[REG2]]
20 define i16 @test(i32 %key) {
22 %key.addr = alloca i32, align 4
23 store i32 %key, ptr %key.addr, align 4
24 %0 = load i32, ptr %key.addr, align 4
25 %call = call swiftcc { i16, i8 } @gen(i32 %0)
26 %v3 = extractvalue { i16, i8 } %call, 0
27 %v1 = sext i16 %v3 to i32
28 %v5 = extractvalue { i16, i8 } %call, 1
29 %v2 = sext i8 %v5 to i32
30 %add = add nsw i32 %v1, %v2
31 %conv = trunc i32 %add to i16
35 declare swiftcc { i16, i8 } @gen(i32)
37 ; If we can't pass every return value in registers, we will pass everything
38 ; in memroy. The caller provides space for the return value and passes
39 ; the address in %r2. The first input argument will be in %r3.
42 ; CHECK-DAG: la %r2, 160(%r15)
43 ; CHECK: brasl %r14, gen2
44 ; CHECK: l %r2, 160(%r15)
45 ; CHECK: a %r2, 164(%r15)
46 ; CHECK: a %r2, 168(%r15)
47 ; CHECK: a %r2, 172(%r15)
48 ; CHECK: a %r2, 176(%r15)
49 ; CHECK-O0-LABEL: test2:
50 ; CHECK-O0: st %r2, [[SPILL1:[0-9]+]](%r15)
51 ; CHECK-O0: l %r3, [[SPILL1]](%r15)
52 ; CHECK-O0: la %r2, 160(%r15)
53 ; CHECK-O0: brasl %r14, gen2
54 ; CHECK-O0-DAG: l %r{{.*}}, 176(%r15)
55 ; CHECK-O0-DAG: l %r{{.*}}, 172(%r15)
56 ; CHECK-O0-DAG: l %r{{.*}}, 168(%r15)
57 ; CHECK-O0-DAG: l %r{{.*}}, 164(%r15)
58 ; CHECK-O0-DAG: l %r{{.*}}, 160(%r15)
63 define i32 @test2(i32 %key) #0 {
65 %key.addr = alloca i32, align 4
66 store i32 %key, ptr %key.addr, align 4
67 %0 = load i32, ptr %key.addr, align 4
68 %call = call swiftcc { i32, i32, i32, i32, i32 } @gen2(i32 %0)
70 %v3 = extractvalue { i32, i32, i32, i32, i32 } %call, 0
71 %v5 = extractvalue { i32, i32, i32, i32, i32 } %call, 1
72 %v6 = extractvalue { i32, i32, i32, i32, i32 } %call, 2
73 %v7 = extractvalue { i32, i32, i32, i32, i32 } %call, 3
74 %v8 = extractvalue { i32, i32, i32, i32, i32 } %call, 4
76 %add = add nsw i32 %v3, %v5
77 %add1 = add nsw i32 %add, %v6
78 %add2 = add nsw i32 %add1, %v7
79 %add3 = add nsw i32 %add2, %v8
83 ; The address of the return value is passed in %r2.
84 ; On return, %r2 will contain the adddress that has been passed in by the caller in %r2.
86 ; CHECK: st %r3, 16(%r2)
87 ; CHECK: st %r3, 12(%r2)
88 ; CHECK: st %r3, 8(%r2)
89 ; CHECK: st %r3, 4(%r2)
90 ; CHECK: st %r3, 0(%r2)
91 ; CHECK-O0-LABEL: gen2:
92 ; CHECK-O0-DAG: st %r3, 16(%r2)
93 ; CHECK-O0-DAG: st %r3, 12(%r2)
94 ; CHECK-O0-DAG: st %r3, 8(%r2)
95 ; CHECK-O0-DAG: st %r3, 4(%r2)
96 ; CHECK-O0-DAG: st %r3, 0(%r2)
97 define swiftcc { i32, i32, i32, i32, i32 } @gen2(i32 %key) {
98 %Y = insertvalue { i32, i32, i32, i32, i32 } undef, i32 %key, 0
99 %Z = insertvalue { i32, i32, i32, i32, i32 } %Y, i32 %key, 1
100 %Z2 = insertvalue { i32, i32, i32, i32, i32 } %Z, i32 %key, 2
101 %Z3 = insertvalue { i32, i32, i32, i32, i32 } %Z2, i32 %key, 3
102 %Z4 = insertvalue { i32, i32, i32, i32, i32 } %Z3, i32 %key, 4
103 ret { i32, i32, i32, i32, i32 } %Z4
106 ; The return value {i32, i32, i32, i32} will be returned via registers
107 ; %r2, %r3, %r4, %r5.
108 ; CHECK-LABEL: test3:
109 ; CHECK: brasl %r14, gen3
113 ; CHECK-O0-LABEL: test3:
114 ; CHECK-O0: brasl %r14, gen3
115 ; CHECK-O0: ar %r2, %r3
116 ; CHECK-O0: ar %r2, %r4
117 ; CHECK-O0: ar %r2, %r5
118 define i32 @test3(i32 %key) #0 {
120 %key.addr = alloca i32, align 4
121 store i32 %key, ptr %key.addr, align 4
122 %0 = load i32, ptr %key.addr, align 4
123 %call = call swiftcc { i32, i32, i32, i32 } @gen3(i32 %0)
125 %v3 = extractvalue { i32, i32, i32, i32 } %call, 0
126 %v5 = extractvalue { i32, i32, i32, i32 } %call, 1
127 %v6 = extractvalue { i32, i32, i32, i32 } %call, 2
128 %v7 = extractvalue { i32, i32, i32, i32 } %call, 3
130 %add = add nsw i32 %v3, %v5
131 %add1 = add nsw i32 %add, %v6
132 %add2 = add nsw i32 %add1, %v7
136 declare swiftcc { i32, i32, i32, i32 } @gen3(i32 %key)
138 ; The return value {float, float, float, float} will be returned via registers
139 ; %f0, %f2, %f4, %f6.
140 ; CHECK-LABEL: test4:
141 ; CHECK: brasl %r14, gen4
142 ; CHECK: aebr %f0, %f2
143 ; CHECK: aebr %f0, %f4
144 ; CHECK: aebr %f0, %f6
145 ; CHECK-O0-LABEL: test4:
146 ; CHECK-O0: brasl %r14, gen4
147 ; CHECK-O0: aebr %f0, %f2
148 ; CHECK-O0: aebr %f0, %f4
149 ; CHECK-O0: aebr %f0, %f6
150 define float @test4(float %key) #0 {
152 %key.addr = alloca float, align 4
153 store float %key, ptr %key.addr, align 4
154 %0 = load float, ptr %key.addr, align 4
155 %call = call swiftcc { float, float, float, float } @gen4(float %0)
157 %v3 = extractvalue { float, float, float, float } %call, 0
158 %v5 = extractvalue { float, float, float, float } %call, 1
159 %v6 = extractvalue { float, float, float, float } %call, 2
160 %v7 = extractvalue { float, float, float, float } %call, 3
162 %add = fadd float %v3, %v5
163 %add1 = fadd float %add, %v6
164 %add2 = fadd float %add1, %v7
168 declare swiftcc { float, float, float, float } @gen4(float %key)
170 ; CHECK-LABEL: consume_i1_ret:
171 ; CHECK: brasl %r14, produce_i1_ret
176 ; CHECK-O0-LABEL: consume_i1_ret:
177 ; CHECK-O0: brasl %r14, produce_i1_ret
178 ; CHECK-O0: nilf %r2, 1
179 ; CHECK-O0: nilf %r3, 1
180 ; CHECK-O0: nilf %r4, 1
181 ; CHECK-O0: nilf %r5, 1
182 define void @consume_i1_ret() {
183 %call = call swiftcc { i1, i1, i1, i1 } @produce_i1_ret()
184 %v3 = extractvalue { i1, i1, i1, i1 } %call, 0
185 %v5 = extractvalue { i1, i1, i1, i1 } %call, 1
186 %v6 = extractvalue { i1, i1, i1, i1 } %call, 2
187 %v7 = extractvalue { i1, i1, i1, i1 } %call, 3
188 %val = zext i1 %v3 to i32
189 store volatile i32 %val, ptr @var
190 %val2 = zext i1 %v5 to i32
191 store volatile i32 %val2, ptr @var
192 %val3 = zext i1 %v6 to i32
193 store volatile i32 %val3, ptr @var
194 %val4 = zext i1 %v7 to i32
195 store i32 %val4, ptr @var
199 declare swiftcc { i1, i1, i1, i1 } @produce_i1_ret()