1 ; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
3 target triple = "wasm32-unknown-unknown"
5 ; Return multiple values, some of which will be legalized into multiple values.
6 declare { i64, i128, i192, i128, i64 } @return_multi_multi()
8 ; Test returning a single value from @return_multi_multi.
12 ; CHECK: call return_multi_multi
13 ; CHECK: i64.load $[[RV:[0-9]+]]=, 8(${{[0-9]+}})
14 ; CHECK: local.copy $push8=, $[[RV]]
15 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
16 %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
20 define i128 @test1() {
22 ; CHECK: call return_multi_multi
23 ; CHECK: i64.load $[[RV:[0-9]+]]=, 16($[[SP:[0-9]+]])
24 ; CHECK: i32.const $push0=, 24
25 ; CHECK: i32.add $push1=, $[[SP]], $pop0
26 ; CHECK: i64.load $push2=, 0($pop1)
27 ; CHECK: i64.store 8($0), $pop2
28 ; CHECK: i64.store 0($0), $[[RV]]
29 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
30 %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
34 define i192 @test2() {
36 ; CHECK: call return_multi_multi
37 ; CHECK: i32.const $push0=, 40
38 ; CHECK: i32.add $push1=, $[[SP:[0-9]+]], $pop0
39 ; CHECK: i64.load $[[L1:[0-9]+]]=, 0($pop1)
40 ; CHECK: i64.load $[[L2:[0-9]+]]=, 32($[[SP]])
41 ; CHECK: i32.const $push2=, 48
42 ; CHECK: i32.add $push3=, $[[SP]], $pop2
43 ; CHECK: i64.load $push4=, 0($pop3)
44 ; CHECK: i64.store 16($0), $pop4
45 ; CHECK: i64.store 0($0), $[[L2]]
46 ; CHECK: i64.store 8($0), $[[L1]]
47 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
48 %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 2
52 define i128 @test3() {
54 ; CHECK: call return_multi_multi
55 ; CHECK: i64.load $[[L1:[0-9]+]]=, 56($[[SP:[0-9]+]])
56 ; CHECK: i32.const $push0=, 64
57 ; CHECK: i32.add $push1=, $[[SP]], $pop0
58 ; CHECK: i64.load $push2=, 0($pop1)
59 ; CHECK: i64.store 8($0), $pop2
60 ; CHECK: i64.store 0($0), $[[L1]]
61 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
62 %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 3
68 ; CHECK: call return_multi_multi
69 ; CHECK: i64.load $[[L1:[0-9]+]]=, 72($[[SP:[0-9]+]])
70 ; CHECK: local.copy $push8=, $[[L1]]
71 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
72 %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 4
76 ; Test returning multiple values from @return_multi_multi.
78 define { i64, i128 } @test5() {
80 ; CHECK: call return_multi_multi
81 ; CHECK: i32.const $push0=, 24
82 ; CHECK: i32.add $push1=, $[[SP:[0-9]+]], $pop0
83 ; CHECK: i64.load $[[L1:[0-9]+]]=, 0($pop1)
84 ; CHECK: i64.load $[[L2:[0-9]+]]=, 8($[[SP]])
85 ; CHECK: i64.load $push2=, 16($[[SP]])
86 ; CHECK: i64.store 8($0), $pop2
87 ; CHECK: i64.store 16($0), $[[L1]]
88 ; CHECK: i64.store 0($0), $[[L2]]
89 ; CHECK: i32.const $push5=, 80
90 ; CHECK: i32.add $push6=, $3, $pop5
91 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
92 %r0 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
93 %r1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
94 %s0 = insertvalue { i64, i128 } undef, i64 %r0, 0
95 %s1 = insertvalue { i64, i128 } %s0, i128 %r1, 1
99 define { i128, i128 } @test6() {
100 ; CHECK-LABEL: test6:
101 ; CHECK: call return_multi_multi
102 ; CHECK: i32.const $push0=, 24
103 ; CHECK: i32.add $push1=, $[[SP:[0-9]+]], $pop0
104 ; CHECK: i64.load $[[L1:[0-9]+]]=, 0($pop1)
105 ; CHECK: i32.const $push2=, 64
106 ; CHECK: i32.add $push3=, $[[SP]], $pop2
107 ; CHECK: i64.load $[[L2:[0-9]+]]=, 0($pop3)
108 ; CHECK: i64.load $[[L3:[0-9]+]]=, 16($[[SP]])
109 ; CHECK: i64.load $push4=, 56($[[SP]])
110 ; CHECK: i64.store 16($0), $pop4
111 ; CHECK: i64.store 24($0), $[[L2]]
112 ; CHECK: i64.store 0($0), $[[L3]]
113 ; CHECK: i64.store 8($0), $[[L1]]
114 ; CHECK: i32.const $push7=, 80
115 ; CHECK: i32.add $push8=, $4, $pop7
116 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
117 %r1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
118 %r3 = extractvalue { i64, i128, i192, i128, i64 } %t0, 3
119 %s0 = insertvalue { i128, i128 } undef, i128 %r1, 0
120 %s1 = insertvalue { i128, i128 } %s0, i128 %r3, 1
121 ret { i128, i128 } %s1
124 define { i64, i192 } @test7() {
125 ; CHECK-LABEL: test7:
126 ; CHECK: call return_multi_multi
127 ; CHECK: i32.const $push0=, 40
128 ; CHECK: i32.add $push1=, $[[SP:[0-9]+]], $pop0
129 ; CHECK: i64.load $[[L1:[0-9]+]]=, 0($pop1)
130 ; CHECK: i64.load $[[L2:[0-9]+]]=, 8($[[SP]])
131 ; CHECK: i64.load $[[L3:[0-9]+]]=, 32($[[SP]])
132 ; CHECK: i32.const $push2=, 48
133 ; CHECK: i32.add $push3=, $[[SP]], $pop2
134 ; CHECK: i64.load $push4=, 0($pop3)
135 ; CHECK: i64.store 24($0), $pop4
136 ; CHECK: i64.store 8($0), $[[L3]]
137 ; CHECK: i64.store 16($0), $[[L1]]
138 ; CHECK: i64.store 0($0), $[[L2]]
139 ; CHECK: i32.const $push7=, 80
140 ; CHECK: i32.add $push8=, $4, $pop7
141 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
142 %r0 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
143 %r2 = extractvalue { i64, i128, i192, i128, i64 } %t0, 2
144 %s0 = insertvalue { i64, i192 } undef, i64 %r0, 0
145 %s1 = insertvalue { i64, i192 } %s0, i192 %r2, 1
146 ret { i64, i192 } %s1
149 define { i128, i192, i128, i64 } @test8() {
150 ; CHECK-LABEL: test8:
151 ; CHECK: call return_multi_multi
152 ; CHECK: i32.const $push0=, 64
153 ; CHECK: i32.add $push1=, $[[SP:[0-9]+]], $pop0
154 ; CHECK: i64.load $[[L1:[0-9]+]]=, 0($pop1)
155 ; CHECK: i32.const $push2=, 40
156 ; CHECK: i32.add $push3=, $[[SP]], $pop2
157 ; CHECK: i64.load $[[L2:[0-9]+]]=, 0($pop3)
158 ; CHECK: i32.const $push4=, 48
159 ; CHECK: i32.add $push5=, $[[SP]], $pop4
160 ; CHECK: i64.load $[[L3:[0-9]+]]=, 0($pop5)
161 ; CHECK: i32.const $push6=, 24
162 ; CHECK: i32.add $push7=, $[[SP]], $pop6
163 ; CHECK: i64.load $[[L4:[0-9]+]]=, 0($pop7)
164 ; CHECK: i64.load $[[L5:[0-9]+]]=, 8($[[SP]])
165 ; CHECK: i64.load $[[L6:[0-9]+]]=, 56($[[SP]])
166 ; CHECK: i64.load $[[L7:[0-9]+]]=, 32($[[SP]])
167 ; CHECK: i64.load $push8=, 16($[[SP]])
168 ; CHECK: i64.store 40($0), $pop8
169 ; CHECK: i64.store 48($0), $[[L4]]
170 ; CHECK: i64.store 32($0), $[[L3]]
171 ; CHECK: i64.store 16($0), $[[L7]]
172 ; CHECK: i64.store 24($0), $[[L2]]
173 ; CHECK: i64.store 0($0), $[[L6]]
174 ; CHECK: i64.store 8($0), $[[L1]]
175 ; CHECK: i64.store 56($0), $[[L5]]
176 ; CHECK: i32.const $push11=, 80
177 ; CHECK: i32.add $push12=, $8, $pop11
178 %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
179 %r0 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
180 %r1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
181 %r2 = extractvalue { i64, i128, i192, i128, i64 } %t0, 2
182 %r3 = extractvalue { i64, i128, i192, i128, i64 } %t0, 3
183 %s0 = insertvalue { i128, i192, i128, i64 } undef, i128 %r3, 0
184 %s1 = insertvalue { i128, i192, i128, i64 } %s0, i192 %r2, 1
185 %s2 = insertvalue { i128, i192, i128, i64 } %s1, i128 %r1, 2
186 %s3 = insertvalue { i128, i192, i128, i64 } %s2, i64 %r0, 3
187 ret { i128, i192, i128, i64 } %s3