1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+nontrapping-fptoint | FileCheck %s
3 ; Test that basic conversion operations assemble as expected.
5 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
8 ; CHECK-LABEL: i32_wrap_i64:
9 ; CHECK-NEXT: .functype i32_wrap_i64 (i64) -> (i32){{$}}
10 ; CHECK-NEXT: i32.wrap_i64 $push[[NUM:[0-9]+]]=, $0{{$}}
11 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
12 define i32 @i32_wrap_i64(i64 %x) {
13 %a = trunc i64 %x to i32
17 ; CHECK-LABEL: i64_extend_s_i32:
18 ; CHECK-NEXT: .functype i64_extend_s_i32 (i32) -> (i64){{$}}
19 ; CHECK-NEXT: i64.extend_i32_s $push[[NUM:[0-9]+]]=, $0{{$}}
20 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
21 define i64 @i64_extend_s_i32(i32 %x) {
22 %a = sext i32 %x to i64
26 ; CHECK-LABEL: i64_extend_u_i32:
27 ; CHECK-NEXT: .functype i64_extend_u_i32 (i32) -> (i64){{$}}
28 ; CHECK-NEXT: i64.extend_i32_u $push[[NUM:[0-9]+]]=, $0{{$}}
29 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
30 define i64 @i64_extend_u_i32(i32 %x) {
31 %a = zext i32 %x to i64
35 ; CHECK-LABEL: i32_trunc_s_f32:
36 ; CHECK-NEXT: .functype i32_trunc_s_f32 (f32) -> (i32){{$}}
37 ; CHECK-NEXT: i32.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
38 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
39 define i32 @i32_trunc_s_f32(float %x) {
40 %a = fptosi float %x to i32
44 ; CHECK-LABEL: i32_trunc_sat_s_f32:
45 ; CHECK-NEXT: .functype i32_trunc_sat_s_f32 (f32) -> (i32){{$}}
46 ; CHECK-NEXT: i32.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
47 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
48 declare i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float)
49 define i32 @i32_trunc_sat_s_f32(float %x) {
50 %a = call i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float %x)
54 ; CHECK-LABEL: i32_trunc_u_f32:
55 ; CHECK-NEXT: .functype i32_trunc_u_f32 (f32) -> (i32){{$}}
56 ; CHECK-NEXT: i32.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
57 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
58 define i32 @i32_trunc_u_f32(float %x) {
59 %a = fptoui float %x to i32
63 ; CHECK-LABEL: i32_trunc_sat_u_f32:
64 ; CHECK-NEXT: .functype i32_trunc_sat_u_f32 (f32) -> (i32){{$}}
65 ; CHECK-NEXT: i32.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
66 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
67 declare i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float)
68 define i32 @i32_trunc_sat_u_f32(float %x) {
69 %a = call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float %x)
73 ; CHECK-LABEL: i32_trunc_s_f64:
74 ; CHECK-NEXT: .functype i32_trunc_s_f64 (f64) -> (i32){{$}}
75 ; CHECK-NEXT: i32.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
76 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
77 define i32 @i32_trunc_s_f64(double %x) {
78 %a = fptosi double %x to i32
82 ; CHECK-LABEL: i32_trunc_sat_s_f64:
83 ; CHECK-NEXT: .functype i32_trunc_sat_s_f64 (f64) -> (i32){{$}}
84 ; CHECK-NEXT: i32.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
85 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
86 declare i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double)
87 define i32 @i32_trunc_sat_s_f64(double %x) {
88 %a = call i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double %x)
92 ; CHECK-LABEL: i32_trunc_u_f64:
93 ; CHECK-NEXT: .functype i32_trunc_u_f64 (f64) -> (i32){{$}}
94 ; CHECK-NEXT: i32.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
95 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
96 define i32 @i32_trunc_u_f64(double %x) {
97 %a = fptoui double %x to i32
101 ; CHECK-LABEL: i32_trunc_sat_u_f64:
102 ; CHECK-NEXT: .functype i32_trunc_sat_u_f64 (f64) -> (i32){{$}}
103 ; CHECK-NEXT: i32.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
104 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
105 declare i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double)
106 define i32 @i32_trunc_sat_u_f64(double %x) {
107 %a = call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double %x)
111 ; CHECK-LABEL: i64_trunc_s_f32:
112 ; CHECK-NEXT: .functype i64_trunc_s_f32 (f32) -> (i64){{$}}
113 ; CHECK-NEXT: i64.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
114 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
115 define i64 @i64_trunc_s_f32(float %x) {
116 %a = fptosi float %x to i64
120 ; CHECK-LABEL: i64_trunc_sat_s_f32:
121 ; CHECK-NEXT: .functype i64_trunc_sat_s_f32 (f32) -> (i64){{$}}
122 ; CHECK-NEXT: i64.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
123 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
124 declare i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float)
125 define i64 @i64_trunc_sat_s_f32(float %x) {
126 %a = call i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float %x)
130 ; CHECK-LABEL: i64_trunc_u_f32:
131 ; CHECK-NEXT: .functype i64_trunc_u_f32 (f32) -> (i64){{$}}
132 ; CHECK-NEXT: i64.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
133 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
134 define i64 @i64_trunc_u_f32(float %x) {
135 %a = fptoui float %x to i64
139 ; CHECK-LABEL: i64_trunc_sat_u_f32:
140 ; CHECK-NEXT: .functype i64_trunc_sat_u_f32 (f32) -> (i64){{$}}
141 ; CHECK-NEXT: i64.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
142 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
143 declare i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float)
144 define i64 @i64_trunc_sat_u_f32(float %x) {
145 %a = call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float %x)
149 ; CHECK-LABEL: i64_trunc_s_f64:
150 ; CHECK-NEXT: .functype i64_trunc_s_f64 (f64) -> (i64){{$}}
151 ; CHECK-NEXT: i64.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
152 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
153 define i64 @i64_trunc_s_f64(double %x) {
154 %a = fptosi double %x to i64
158 ; CHECK-LABEL: i64_trunc_sat_s_f64:
159 ; CHECK-NEXT: .functype i64_trunc_sat_s_f64 (f64) -> (i64){{$}}
160 ; CHECK-NEXT: i64.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
161 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
162 declare i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double)
163 define i64 @i64_trunc_sat_s_f64(double %x) {
164 %a = call i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double %x)
168 ; CHECK-LABEL: i64_trunc_u_f64:
169 ; CHECK-NEXT: .functype i64_trunc_u_f64 (f64) -> (i64){{$}}
170 ; CHECK-NEXT: i64.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
171 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
172 define i64 @i64_trunc_u_f64(double %x) {
173 %a = fptoui double %x to i64
177 ; CHECK-LABEL: i64_trunc_sat_u_f64:
178 ; CHECK-NEXT: .functype i64_trunc_sat_u_f64 (f64) -> (i64){{$}}
179 ; CHECK-NEXT: i64.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
180 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
181 declare i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double)
182 define i64 @i64_trunc_sat_u_f64(double %x) {
183 %a = call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double %x)
187 ; CHECK-LABEL: f32_convert_s_i32:
188 ; CHECK-NEXT: .functype f32_convert_s_i32 (i32) -> (f32){{$}}
189 ; CHECK-NEXT: f32.convert_i32_s $push[[NUM:[0-9]+]]=, $0{{$}}
190 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
191 define float @f32_convert_s_i32(i32 %x) {
192 %a = sitofp i32 %x to float
196 ; CHECK-LABEL: f32_convert_u_i32:
197 ; CHECK-NEXT: .functype f32_convert_u_i32 (i32) -> (f32){{$}}
198 ; CHECK-NEXT: f32.convert_i32_u $push[[NUM:[0-9]+]]=, $0{{$}}
199 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
200 define float @f32_convert_u_i32(i32 %x) {
201 %a = uitofp i32 %x to float
205 ; CHECK-LABEL: f64_convert_s_i32:
206 ; CHECK-NEXT: .functype f64_convert_s_i32 (i32) -> (f64){{$}}
207 ; CHECK-NEXT: f64.convert_i32_s $push[[NUM:[0-9]+]]=, $0{{$}}
208 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
209 define double @f64_convert_s_i32(i32 %x) {
210 %a = sitofp i32 %x to double
214 ; CHECK-LABEL: f64_convert_u_i32:
215 ; CHECK-NEXT: .functype f64_convert_u_i32 (i32) -> (f64){{$}}
216 ; CHECK-NEXT: f64.convert_i32_u $push[[NUM:[0-9]+]]=, $0{{$}}
217 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
218 define double @f64_convert_u_i32(i32 %x) {
219 %a = uitofp i32 %x to double
223 ; CHECK-LABEL: f32_convert_s_i64:
224 ; CHECK-NEXT: .functype f32_convert_s_i64 (i64) -> (f32){{$}}
225 ; CHECK-NEXT: f32.convert_i64_s $push[[NUM:[0-9]+]]=, $0{{$}}
226 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
227 define float @f32_convert_s_i64(i64 %x) {
228 %a = sitofp i64 %x to float
232 ; CHECK-LABEL: f32_convert_u_i64:
233 ; CHECK-NEXT: .functype f32_convert_u_i64 (i64) -> (f32){{$}}
234 ; CHECK-NEXT: f32.convert_i64_u $push[[NUM:[0-9]+]]=, $0{{$}}
235 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
236 define float @f32_convert_u_i64(i64 %x) {
237 %a = uitofp i64 %x to float
241 ; CHECK-LABEL: f64_convert_s_i64:
242 ; CHECK-NEXT: .functype f64_convert_s_i64 (i64) -> (f64){{$}}
243 ; CHECK-NEXT: f64.convert_i64_s $push[[NUM:[0-9]+]]=, $0{{$}}
244 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
245 define double @f64_convert_s_i64(i64 %x) {
246 %a = sitofp i64 %x to double
250 ; CHECK-LABEL: f64_convert_u_i64:
251 ; CHECK-NEXT: .functype f64_convert_u_i64 (i64) -> (f64){{$}}
252 ; CHECK-NEXT: f64.convert_i64_u $push[[NUM:[0-9]+]]=, $0{{$}}
253 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
254 define double @f64_convert_u_i64(i64 %x) {
255 %a = uitofp i64 %x to double
259 ; CHECK-LABEL: f64_promote_f32:
260 ; CHECK-NEXT: .functype f64_promote_f32 (f32) -> (f64){{$}}
261 ; CHECK-NEXT: f64.promote_f32 $push[[NUM:[0-9]+]]=, $0{{$}}
262 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
263 define double @f64_promote_f32(float %x) {
264 %a = fpext float %x to double
268 ; CHECK-LABEL: f32_demote_f64:
269 ; CHECK-NEXT: .functype f32_demote_f64 (f64) -> (f32){{$}}
270 ; CHECK-NEXT: f32.demote_f64 $push[[NUM:[0-9]+]]=, $0{{$}}
271 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
272 define float @f32_demote_f64(double %x) {
273 %a = fptrunc double %x to float
277 ; If the high its are unused, LLVM will optimize sext/zext into anyext, which
278 ; we need to patterm-match back to a specific instruction.
280 ; CHECK-LABEL: anyext:
281 ; CHECK: i64.extend_i32_u $push0=, $0{{$}}
282 define i64 @anyext(i32 %x) {
283 %y = sext i32 %x to i64
288 ; CHECK-LABEL: bitcast_i32_to_float:
289 ; CHECK: f32.reinterpret_i32 $push0=, $0{{$}}
290 define float @bitcast_i32_to_float(i32 %a) {
291 %t = bitcast i32 %a to float
295 ; CHECK-LABEL: bitcast_float_to_i32:
296 ; CHECK: i32.reinterpret_f32 $push0=, $0{{$}}
297 define i32 @bitcast_float_to_i32(float %a) {
298 %t = bitcast float %a to i32
302 ; CHECK-LABEL: bitcast_i64_to_double:
303 ; CHECK: f64.reinterpret_i64 $push0=, $0{{$}}
304 define double @bitcast_i64_to_double(i64 %a) {
305 %t = bitcast i64 %a to double
309 ; CHECK-LABEL: bitcast_double_to_i64:
310 ; CHECK: i64.reinterpret_f64 $push0=, $0{{$}}
311 define i64 @bitcast_double_to_i64(double %a) {
312 %t = bitcast double %a to i64