18cfeeaf9SDan Gohman; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
28cfeeaf9SDan Gohman
38cfeeaf9SDan Gohmantarget triple = "wasm32-unknown-unknown"
48cfeeaf9SDan Gohman
58cfeeaf9SDan Gohman; Return multiple values, some of which will be legalized into multiple values.
68cfeeaf9SDan Gohmandeclare { i64, i128, i192, i128, i64 } @return_multi_multi()
78cfeeaf9SDan Gohman
88cfeeaf9SDan Gohman; Test returning a single value from @return_multi_multi.
98cfeeaf9SDan Gohman
108cfeeaf9SDan Gohmandefine i64 @test0() {
11*86cc731fSAlex Bradbury; CHECK-LABEL: test0:
128cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
13ff171acfSDerek Schuff; CHECK: i64.load	$[[RV:[0-9]+]]=, 8(${{[0-9]+}})
14ff171acfSDerek Schuff; CHECK: local.copy	$push8=, $[[RV]]
158cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
168cfeeaf9SDan Gohman  %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
178cfeeaf9SDan Gohman  ret i64 %t1
188cfeeaf9SDan Gohman}
198cfeeaf9SDan Gohman
208cfeeaf9SDan Gohmandefine i128 @test1() {
21*86cc731fSAlex Bradbury; CHECK-LABEL: test1:
228cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
23ff171acfSDerek Schuff; CHECK: i64.load	$[[RV:[0-9]+]]=, 16($[[SP:[0-9]+]])
248cfeeaf9SDan Gohman; CHECK: i32.const	$push0=, 24
25ff171acfSDerek Schuff; CHECK: i32.add 	$push1=, $[[SP]], $pop0
268cfeeaf9SDan Gohman; CHECK: i64.load	$push2=, 0($pop1)
278cfeeaf9SDan Gohman; CHECK: i64.store	8($0), $pop2
28ff171acfSDerek Schuff; CHECK: i64.store	0($0), $[[RV]]
298cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
308cfeeaf9SDan Gohman  %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
318cfeeaf9SDan Gohman  ret i128 %t1
328cfeeaf9SDan Gohman}
338cfeeaf9SDan Gohman
348cfeeaf9SDan Gohmandefine i192 @test2() {
35*86cc731fSAlex Bradbury; CHECK-LABEL: test2:
368cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
378cfeeaf9SDan Gohman; CHECK: i32.const	$push0=, 40
38ff171acfSDerek Schuff; CHECK: i32.add 	$push1=, $[[SP:[0-9]+]], $pop0
39ff171acfSDerek Schuff; CHECK: i64.load	$[[L1:[0-9]+]]=, 0($pop1)
40ff171acfSDerek Schuff; CHECK: i64.load	$[[L2:[0-9]+]]=, 32($[[SP]])
418cfeeaf9SDan Gohman; CHECK: i32.const	$push2=, 48
42ff171acfSDerek Schuff; CHECK: i32.add 	$push3=, $[[SP]], $pop2
438cfeeaf9SDan Gohman; CHECK: i64.load	$push4=, 0($pop3)
448cfeeaf9SDan Gohman; CHECK: i64.store	16($0), $pop4
45ff171acfSDerek Schuff; CHECK: i64.store	0($0), $[[L2]]
46ff171acfSDerek Schuff; CHECK: i64.store	8($0), $[[L1]]
478cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
488cfeeaf9SDan Gohman  %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 2
498cfeeaf9SDan Gohman  ret i192 %t1
508cfeeaf9SDan Gohman}
518cfeeaf9SDan Gohman
528cfeeaf9SDan Gohmandefine i128 @test3() {
53*86cc731fSAlex Bradbury; CHECK-LABEL: test3:
548cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
55ff171acfSDerek Schuff; CHECK: i64.load	$[[L1:[0-9]+]]=, 56($[[SP:[0-9]+]])
568cfeeaf9SDan Gohman; CHECK: i32.const	$push0=, 64
57ff171acfSDerek Schuff; CHECK: i32.add 	$push1=, $[[SP]], $pop0
588cfeeaf9SDan Gohman; CHECK: i64.load	$push2=, 0($pop1)
598cfeeaf9SDan Gohman; CHECK: i64.store	8($0), $pop2
60ff171acfSDerek Schuff; CHECK: i64.store	0($0), $[[L1]]
618cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
628cfeeaf9SDan Gohman  %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 3
638cfeeaf9SDan Gohman  ret i128 %t1
648cfeeaf9SDan Gohman}
658cfeeaf9SDan Gohman
668cfeeaf9SDan Gohmandefine i64 @test4() {
67*86cc731fSAlex Bradbury; CHECK-LABEL: test4:
688cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
69ff171acfSDerek Schuff; CHECK: i64.load	$[[L1:[0-9]+]]=, 72($[[SP:[0-9]+]])
70ff171acfSDerek Schuff; CHECK: local.copy	$push8=, $[[L1]]
718cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
728cfeeaf9SDan Gohman  %t1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 4
738cfeeaf9SDan Gohman  ret i64 %t1
748cfeeaf9SDan Gohman}
758cfeeaf9SDan Gohman
768cfeeaf9SDan Gohman; Test returning multiple values from @return_multi_multi.
778cfeeaf9SDan Gohman
788cfeeaf9SDan Gohmandefine { i64, i128 } @test5() {
79*86cc731fSAlex Bradbury; CHECK-LABEL: test5:
808cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
818cfeeaf9SDan Gohman; CHECK: i32.const	$push10=, 8
82ff171acfSDerek Schuff; CHECK: i32.add 	$push11=, $[[SP:[0-9]+]], $pop10
838cfeeaf9SDan Gohman; CHECK: i32.const	$push0=, 16
848cfeeaf9SDan Gohman; CHECK: i32.add 	$push1=, $pop11, $pop0
85ff171acfSDerek Schuff; CHECK: i64.load	$[[L1:[0-9]+]]=, 0($pop1)
86ff171acfSDerek Schuff; CHECK: i64.load	$[[L2:[0-9]+]]=, 8($[[SP]])
87ff171acfSDerek Schuff; CHECK: i64.load	$push2=, 16($[[SP]])
888cfeeaf9SDan Gohman; CHECK: i64.store	8($0), $pop2
89b0319ab7SFraser Cormack; CHECK: i64.store	0($0), $[[L2]]
908cfeeaf9SDan Gohman; CHECK: i32.const	$push12=, 16
918cfeeaf9SDan Gohman; CHECK: i32.add 	$push3=, $0, $pop12
92ff171acfSDerek Schuff; CHECK: i64.store	0($pop3), $[[L1]]
938cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
948cfeeaf9SDan Gohman  %r0 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
958cfeeaf9SDan Gohman  %r1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
968cfeeaf9SDan Gohman  %s0 = insertvalue { i64, i128 } undef, i64 %r0, 0
978cfeeaf9SDan Gohman  %s1 = insertvalue { i64, i128 } %s0, i128 %r1, 1
988cfeeaf9SDan Gohman  ret { i64, i128 } %s1
998cfeeaf9SDan Gohman}
1008cfeeaf9SDan Gohman
1018cfeeaf9SDan Gohmandefine { i128, i128 } @test6() {
102*86cc731fSAlex Bradbury; CHECK-LABEL: test6:
1038cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
104b0319ab7SFraser Cormack; CHECK: i32.const	$push0=, 64
105ff171acfSDerek Schuff; CHECK: i32.add 	$push1=, $[[SP:[0-9]+]], $pop0
106ff171acfSDerek Schuff; CHECK: i64.load	$[[L1:[0-9]+]]=, 0($pop1)
107b0319ab7SFraser Cormack; CHECK: i32.const	$push2=, 24
108ff171acfSDerek Schuff; CHECK: i32.add 	$push3=, $[[SP]], $pop2
109ff171acfSDerek Schuff; CHECK: i64.load	$[[L2:[0-9]+]]=, 0($pop3)
110ff171acfSDerek Schuff; CHECK: i64.load	$[[L3:[0-9]+]]=, 16($[[SP]])
111ff171acfSDerek Schuff; CHECK: i64.load	$push4=, 56($[[SP]])
1128cfeeaf9SDan Gohman; CHECK: i64.store	16($0), $pop4
113b0319ab7SFraser Cormack; CHECK: i64.store	0($0), $[[L3]]
114b0319ab7SFraser Cormack; CHECK: i64.store	8($0), $[[L2]]
1158cfeeaf9SDan Gohman; CHECK: i32.const	$push5=, 24
1168cfeeaf9SDan Gohman; CHECK: i32.add 	$push6=, $0, $pop5
117b0319ab7SFraser Cormack; CHECK: i64.store	0($pop6), $[[L1]]
1188cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
1198cfeeaf9SDan Gohman  %r1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
1208cfeeaf9SDan Gohman  %r3 = extractvalue { i64, i128, i192, i128, i64 } %t0, 3
1218cfeeaf9SDan Gohman  %s0 = insertvalue { i128, i128 } undef, i128 %r1, 0
1228cfeeaf9SDan Gohman  %s1 = insertvalue { i128, i128 } %s0, i128 %r3, 1
1238cfeeaf9SDan Gohman  ret { i128, i128 } %s1
1248cfeeaf9SDan Gohman}
1258cfeeaf9SDan Gohman
1268cfeeaf9SDan Gohmandefine { i64, i192 } @test7() {
127*86cc731fSAlex Bradbury; CHECK-LABEL: test7:
1288cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
129b0319ab7SFraser Cormack; CHECK: i32.const	$push0=, 40
130b0319ab7SFraser Cormack; CHECK: i32.add 	$push1=, $[[SP:[0-9]+]], $pop0
131b0319ab7SFraser Cormack; CHECK: i64.load	$[[L1:[0-9]+]]=, 0($pop1)
132b0319ab7SFraser Cormack; CHECK: i32.const	$push2=, 48
133b0319ab7SFraser Cormack; CHECK: i32.add 	$push3=, $[[SP]], $pop2
134b0319ab7SFraser Cormack; CHECK: i64.load	$[[L2:[0-9]+]]=, 0($pop3)
135b0319ab7SFraser Cormack; CHECK: i64.load	$[[L3:[0-9]+]]=, 8($[[SP]])
136b0319ab7SFraser Cormack; CHECK: i64.load	$push4=, 32($[[SP]])
137b0319ab7SFraser Cormack; CHECK: i64.store	8($0), $pop4
138b0319ab7SFraser Cormack; CHECK: i64.store	0($0), $[[L3]]
139b0319ab7SFraser Cormack; CHECK: i32.const	$push5=, 24
140b0319ab7SFraser Cormack; CHECK: i32.add 	$push6=, $0, $pop5
141b0319ab7SFraser Cormack; CHECK: i64.store	0($pop6), $[[L2]]
1428cfeeaf9SDan Gohman; CHECK: i32.const	$push7=, 16
1438cfeeaf9SDan Gohman; CHECK: i32.add 	$push8=, $0, $pop7
144ff171acfSDerek Schuff; CHECK: i64.store	0($pop8), $[[L1]]
1458cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
1468cfeeaf9SDan Gohman  %r0 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
1478cfeeaf9SDan Gohman  %r2 = extractvalue { i64, i128, i192, i128, i64 } %t0, 2
1488cfeeaf9SDan Gohman  %s0 = insertvalue { i64, i192 } undef, i64 %r0, 0
1498cfeeaf9SDan Gohman  %s1 = insertvalue { i64, i192 } %s0, i192 %r2, 1
1508cfeeaf9SDan Gohman  ret { i64, i192 } %s1
1518cfeeaf9SDan Gohman}
1528cfeeaf9SDan Gohman
1538cfeeaf9SDan Gohmandefine { i128, i192, i128, i64 } @test8() {
154*86cc731fSAlex Bradbury; CHECK-LABEL: test8:
1558cfeeaf9SDan Gohman; CHECK: call    	return_multi_multi
1568cfeeaf9SDan Gohman; CHECK: i32.const	$push20=, 8
157b0319ab7SFraser Cormack; CHECK: i32.add 	$push21=, $[[SP:[0-9]+]], $pop20
158b0319ab7SFraser Cormack; CHECK: i32.const	$push0=, 32
159b0319ab7SFraser Cormack; CHECK: i32.add 	$push1=, $pop21, $pop0
160b0319ab7SFraser Cormack; CHECK: i64.load	$[[L1:[0-9]+]]=, 0($pop1)
161b0319ab7SFraser Cormack; CHECK: i32.const	$push2=, 48
162b0319ab7SFraser Cormack; CHECK: i32.add 	$push3=, $[[SP]], $pop2
163ff171acfSDerek Schuff; CHECK: i64.load	$[[L2:[0-9]+]]=, 0($pop3)
164b0319ab7SFraser Cormack; CHECK: i32.const	$push4=, 24
165ff171acfSDerek Schuff; CHECK: i32.add 	$push5=, $[[SP]], $pop4
166ff171acfSDerek Schuff; CHECK: i64.load	$[[L3:[0-9]+]]=, 0($pop5)
167b0319ab7SFraser Cormack; CHECK: i32.const	$push6=, 64
168ff171acfSDerek Schuff; CHECK: i32.add 	$push7=, $[[SP]], $pop6
169ff171acfSDerek Schuff; CHECK: i64.load	$[[L4:[0-9]+]]=, 0($pop7)
170ff171acfSDerek Schuff; CHECK: i64.load	$[[L5:[0-9]+]]=, 8($[[SP]])
171ff171acfSDerek Schuff; CHECK: i64.load	$[[L6:[0-9]+]]=, 56($[[SP]])
172ff171acfSDerek Schuff; CHECK: i64.load	$[[L7:[0-9]+]]=, 32($[[SP]])
173ff171acfSDerek Schuff; CHECK: i64.load	$push8=, 16($[[SP]])
1748cfeeaf9SDan Gohman; CHECK: i64.store	40($0), $pop8
175b0319ab7SFraser Cormack; CHECK: i64.store	16($0), $[[L7]]
176b0319ab7SFraser Cormack; CHECK: i64.store	0($0), $[[L6]]
177b0319ab7SFraser Cormack; CHECK: i64.store	8($0), $[[L4]]
178b0319ab7SFraser Cormack; CHECK: i64.store	56($0), $[[L5]]
1798cfeeaf9SDan Gohman; CHECK: i32.const	$push9=, 48
1808cfeeaf9SDan Gohman; CHECK: i32.add 	$push10=, $0, $pop9
181b0319ab7SFraser Cormack; CHECK: i64.store	0($pop10), $[[L3]]
1828cfeeaf9SDan Gohman; CHECK: i32.const	$push22=, 32
1838cfeeaf9SDan Gohman; CHECK: i32.add 	$push11=, $0, $pop22
184b0319ab7SFraser Cormack; CHECK: i64.store	0($pop11), $[[L2]]
1858cfeeaf9SDan Gohman; CHECK: i32.const	$push12=, 24
1868cfeeaf9SDan Gohman; CHECK: i32.add 	$push13=, $0, $pop12
187b0319ab7SFraser Cormack; CHECK: i64.store	0($pop13), $[[L1]]
1888cfeeaf9SDan Gohman  %t0 = call { i64, i128, i192, i128, i64 } @return_multi_multi()
1898cfeeaf9SDan Gohman  %r0 = extractvalue { i64, i128, i192, i128, i64 } %t0, 0
1908cfeeaf9SDan Gohman  %r1 = extractvalue { i64, i128, i192, i128, i64 } %t0, 1
1918cfeeaf9SDan Gohman  %r2 = extractvalue { i64, i128, i192, i128, i64 } %t0, 2
1928cfeeaf9SDan Gohman  %r3 = extractvalue { i64, i128, i192, i128, i64 } %t0, 3
1938cfeeaf9SDan Gohman  %s0 = insertvalue { i128, i192, i128, i64 } undef, i128 %r3, 0
1948cfeeaf9SDan Gohman  %s1 = insertvalue { i128, i192, i128, i64 } %s0, i192 %r2, 1
1958cfeeaf9SDan Gohman  %s2 = insertvalue { i128, i192, i128, i64 } %s1, i128 %r1, 2
1968cfeeaf9SDan Gohman  %s3 = insertvalue { i128, i192, i128, i64 } %s2, i64 %r0, 3
1978cfeeaf9SDan Gohman  ret { i128, i192, i128, i64 } %s3
1988cfeeaf9SDan Gohman}
199