[InstCombine] Signed saturation patterns
[llvm-complete.git] / test / CodeGen / WebAssembly / call.ll
blob18d8ec2e65416cbcc198caa57ca84cf1de158854
1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -mattr=+sign-ext,+simd128 | FileCheck --check-prefixes=CHECK,NO-TAIL,SLOW-NO-TAIL %s
2 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -fast-isel -fast-isel-abort=1 -mattr=+sign-ext,+simd128 | FileCheck --check-prefixes=CHECK,NO-TAIL,FAST,FAST-NO-TAIL %s
3 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -mattr=+sign-ext,+simd128,+tail-call | FileCheck --check-prefixes=CHECK,TAIL,SLOW-TAIL %s
4 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -fast-isel -fast-isel-abort=1 -mattr=+sign-ext,+simd128,+tail-call | FileCheck --check-prefixes=CHECK,TAIL,FAST-TAIL %s
6 ; Test that basic call operations assemble as expected.
8 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
9 target triple = "wasm32-unknown-unknown"
11 declare i32 @i32_nullary()
12 declare i32 @i32_unary(i32)
13 declare i32 @i32_binary(i32, i32)
14 declare i64 @i64_nullary()
15 declare float @float_nullary()
16 declare double @double_nullary()
17 declare <16 x i8> @v128_nullary()
18 declare void @void_nullary()
20 ; CHECK-LABEL: call_i32_nullary:
21 ; CHECK-NEXT: .functype call_i32_nullary () -> (i32){{$}}
22 ; CHECK-NEXT: {{^}} i32.call $push[[NUM:[0-9]+]]=, i32_nullary{{$}}
23 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
24 define i32 @call_i32_nullary() {
25   %r = call i32 @i32_nullary()
26   ret i32 %r
29 ; CHECK-LABEL: call_i64_nullary:
30 ; CHECK-NEXT: .functype call_i64_nullary () -> (i64){{$}}
31 ; CHECK-NEXT: {{^}} i64.call $push[[NUM:[0-9]+]]=, i64_nullary{{$}}
32 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
33 define i64 @call_i64_nullary() {
34   %r = call i64 @i64_nullary()
35   ret i64 %r
38 ; CHECK-LABEL: call_float_nullary:
39 ; CHECK-NEXT: .functype call_float_nullary () -> (f32){{$}}
40 ; CHECK-NEXT: {{^}} f32.call $push[[NUM:[0-9]+]]=, float_nullary{{$}}
41 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
42 define float @call_float_nullary() {
43   %r = call float @float_nullary()
44   ret float %r
47 ; CHECK-LABEL: call_double_nullary:
48 ; CHECK-NEXT: .functype call_double_nullary () -> (f64){{$}}
49 ; CHECK-NEXT: {{^}} f64.call $push[[NUM:[0-9]+]]=, double_nullary{{$}}
50 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
51 define double @call_double_nullary() {
52   %r = call double @double_nullary()
53   ret double %r
56 ; CHECK-LABEL: call_v128_nullary:
57 ; CHECK-NEXT: .functype call_v128_nullary () -> (v128){{$}}
58 ; CHECK-NEXT: {{^}} v128.call $push[[NUM:[0-9]+]]=, v128_nullary{{$}}
59 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
60 define <16 x i8> @call_v128_nullary() {
61   %r = call <16 x i8> @v128_nullary()
62   ret <16 x i8> %r
65 ; CHECK-LABEL: call_void_nullary:
66 ; CHECK-NEXT: .functype call_void_nullary () -> (){{$}}
67 ; CHECK-NEXT: {{^}} call void_nullary{{$}}
68 ; CHECK-NEXT: return{{$}}
69 define void @call_void_nullary() {
70   call void @void_nullary()
71   ret void
74 ; CHECK-LABEL: call_i32_unary:
75 ; CHECK-NEXT: .functype call_i32_unary (i32) -> (i32){{$}}
76 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
77 ; CHECK-NEXT: {{^}} i32.call $push[[NUM:[0-9]+]]=, i32_unary, $pop[[L0]]{{$}}
78 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
79 define i32 @call_i32_unary(i32 %a) {
80   %r = call i32 @i32_unary(i32 %a)
81   ret i32 %r
84 ; CHECK-LABEL: call_i32_binary:
85 ; CHECK-NEXT: .functype call_i32_binary (i32, i32) -> (i32){{$}}
86 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
87 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
88 ; CHECK-NEXT: {{^}} i32.call $push[[NUM:[0-9]+]]=, i32_binary, $pop[[L0]], $pop[[L1]]{{$}}
89 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
90 define i32 @call_i32_binary(i32 %a, i32 %b) {
91   %r = call i32 @i32_binary(i32 %a, i32 %b)
92   ret i32 %r
95 ; CHECK-LABEL: call_indirect_void:
96 ; CHECK-NEXT: .functype call_indirect_void (i32) -> (){{$}}
97 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
98 ; CHECK-NEXT: {{^}} call_indirect $pop[[L0]]{{$}}
99 ; CHECK-NEXT: return{{$}}
100 define void @call_indirect_void(void ()* %callee) {
101   call void %callee()
102   ret void
105 ; CHECK-LABEL: call_indirect_i32:
106 ; CHECK-NEXT: .functype call_indirect_i32 (i32) -> (i32){{$}}
107 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
108 ; CHECK-NEXT: {{^}} i32.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
109 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
110 define i32 @call_indirect_i32(i32 ()* %callee) {
111   %t = call i32 %callee()
112   ret i32 %t
115 ; CHECK-LABEL: call_indirect_i64:
116 ; CHECK-NEXT: .functype call_indirect_i64 (i32) -> (i64){{$}}
117 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
118 ; CHECK-NEXT: {{^}} i64.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
119 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
120 define i64 @call_indirect_i64(i64 ()* %callee) {
121   %t = call i64 %callee()
122   ret i64 %t
125 ; CHECK-LABEL: call_indirect_float:
126 ; CHECK-NEXT: .functype call_indirect_float (i32) -> (f32){{$}}
127 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
128 ; CHECK-NEXT: {{^}} f32.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
129 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
130 define float @call_indirect_float(float ()* %callee) {
131   %t = call float %callee()
132   ret float %t
135 ; CHECK-LABEL: call_indirect_double:
136 ; CHECK-NEXT: .functype call_indirect_double (i32) -> (f64){{$}}
137 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
138 ; CHECK-NEXT: {{^}} f64.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
139 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
140 define double @call_indirect_double(double ()* %callee) {
141   %t = call double %callee()
142   ret double %t
145 ; CHECK-LABEL: call_indirect_v128:
146 ; CHECK-NEXT: .functype call_indirect_v128 (i32) -> (v128){{$}}
147 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
148 ; CHECK-NEXT: {{^}} v128.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]]{{$}}
149 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
150 define <16 x i8> @call_indirect_v128(<16 x i8> ()* %callee) {
151   %t = call <16 x i8> %callee()
152   ret <16 x i8> %t
155 ; CHECK-LABEL: call_indirect_arg:
156 ; CHECK-NEXT: .functype call_indirect_arg (i32, i32) -> (){{$}}
157 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 1{{$}}
158 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 0{{$}}
159 ; CHECK-NEXT: {{^}} call_indirect $pop[[L0]], $pop[[L1]]{{$}}
160 ; CHECK-NEXT: return{{$}}
161 define void @call_indirect_arg(void (i32)* %callee, i32 %arg) {
162   call void %callee(i32 %arg)
163   ret void
166 ; CHECK-LABEL: call_indirect_arg_2:
167 ; CHECK-NEXT: .functype call_indirect_arg_2 (i32, i32, i32) -> (){{$}}
168 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 1{{$}}
169 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 2{{$}}
170 ; CHECK-NEXT: local.get $push[[L2:[0-9]+]]=, 0{{$}}
171 ; CHECK-NEXT: {{^}} i32.call_indirect $push[[NUM:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $pop[[L2]]{{$}}
172 ; CHECK-NEXT: drop $pop[[NUM]]{{$}}
173 ; CHECK-NEXT: return{{$}}
174 define void @call_indirect_arg_2(i32 (i32, i32)* %callee, i32 %arg, i32 %arg2) {
175   call i32 %callee(i32 %arg, i32 %arg2)
176   ret void
179 ; CHECK-LABEL: tail_call_void_nullary:
180 ; CHECK-NEXT: .functype tail_call_void_nullary () -> (){{$}}
181 ; NO-TAIL-NEXT: {{^}} call void_nullary{{$}}
182 ; NO-TAIL-NEXT: return{{$}}
183 ; SLOW-TAIL-NEXT: {{^}} return_call void_nullary{{$}}
184 ; FAST-TAIL-NEXT: {{^}} call void_nullary{{$}}
185 ; FAST-TAIL-NEXT: return{{$}}
186 define void @tail_call_void_nullary() {
187   tail call void @void_nullary()
188   ret void
191 ; CHECK-LABEL: fastcc_tail_call_void_nullary:
192 ; CHECK-NEXT: .functype fastcc_tail_call_void_nullary () -> (){{$}}
193 ; NO-TAIL-NEXT: {{^}} call void_nullary{{$}}
194 ; NO-TAIL-NEXT: return{{$}}
195 ; SLOW-TAIL-NEXT: {{^}} return_call void_nullary{{$}}
196 ; FAST-TAIL-NEXT: {{^}} call void_nullary{{$}}
197 ; FAST-TAIL-NEXT: return{{$}}
198 define void @fastcc_tail_call_void_nullary() {
199   tail call fastcc void @void_nullary()
200   ret void
203 ; CHECK-LABEL: coldcc_tail_call_void_nullary:
204 ; CHECK-NEXT: .functype coldcc_tail_call_void_nullary () -> (){{$}}
205 ; NO-TAIL-NEXT: {{^}} call void_nullary{{$}}
206 ; NO-TAIL-NEXT: return{{$}}
207 ; SLOW-TAIL-NEXT: {{^}} return_call void_nullary{{$}}
208 ; FAST-TAIL-NEXT: {{^}} call void_nullary{{$}}
209 ; FAST-TAIL-NEXT: return{{$}}
210 define void @coldcc_tail_call_void_nullary() {
211   tail call coldcc void @void_nullary()
212   ret void
215 ; CHECK-LABEL: call_constexpr:
216 ; CHECK-NEXT: .functype call_constexpr () -> (){{$}}
217 ; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 2{{$}}
218 ; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 3{{$}}
219 ; CHECK-NEXT: call .Lvararg_func_bitcast, $pop[[L0]], $pop[[L1]]{{$}}
220 ; CHECK-NEXT: call other_void_nullary{{$}}
221 ; CHECK-NEXT: call void_nullary{{$}}
222 ; CHECK-NEXT: return{{$}}
223 declare void @vararg_func(...)
224 declare void @other_void_nullary()
225 define void @call_constexpr() {
226 bb0:
227   call void bitcast (void (...)* @vararg_func to void (i32, i32)*)(i32 2, i32 3)
228   br label %bb1
229 bb1:
230   call void select (i1 0, void ()* @void_nullary, void ()* @other_void_nullary)()
231   br label %bb2
232 bb2:
233   call void inttoptr (i32 ptrtoint (void ()* @void_nullary to i32) to void ()*)()
234   ret void
237 ; TODO: test the following:
238 ;  - More argument combinations.
239 ;  - Tail call.
240 ;  - Interesting returns (struct, multiple).
241 ;  - Vararg.