conv.ll
10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+nontrapping-fptoint | FileCheck %s
; Test that basic conversion operations assemble as expected.
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown"
; CHECK-LABEL: i32_wrap_i64:
; CHECK-NEXT: .functype i32_wrap_i64 (i64) -> (i32){{$}}
; CHECK-NEXT: i32.wrap_i64 $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i32 @i32_wrap_i64(i64 %x) {
%a = trunc i64 %x to i32
ret i32 %a
}
; CHECK-LABEL: i64_extend_s_i32:
; CHECK-NEXT: .functype i64_extend_s_i32 (i32) -> (i64){{$}}
; CHECK-NEXT: i64.extend_i32_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @i64_extend_s_i32(i32 %x) {
%a = sext i32 %x to i64
ret i64 %a
}
; CHECK-LABEL: i64_extend_u_i32:
; CHECK-NEXT: .functype i64_extend_u_i32 (i32) -> (i64){{$}}
; CHECK-NEXT: i64.extend_i32_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @i64_extend_u_i32(i32 %x) {
%a = zext i32 %x to i64
ret i64 %a
}
; CHECK-LABEL: i32_trunc_s_f32:
; CHECK-NEXT: .functype i32_trunc_s_f32 (f32) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i32 @i32_trunc_s_f32(float %x) {
%a = fptosi float %x to i32
ret i32 %a
}
; CHECK-LABEL: i32_trunc_sat_s_f32:
; CHECK-NEXT: .functype i32_trunc_sat_s_f32 (f32) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float)
define i32 @i32_trunc_sat_s_f32(float %x) {
%a = call i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float %x)
ret i32 %a
}
; CHECK-LABEL: i32_trunc_u_f32:
; CHECK-NEXT: .functype i32_trunc_u_f32 (f32) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i32 @i32_trunc_u_f32(float %x) {
%a = fptoui float %x to i32
ret i32 %a
}
; CHECK-LABEL: i32_trunc_sat_u_f32:
; CHECK-NEXT: .functype i32_trunc_sat_u_f32 (f32) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float)
define i32 @i32_trunc_sat_u_f32(float %x) {
%a = call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float %x)
ret i32 %a
}
; CHECK-LABEL: i32_trunc_s_f64:
; CHECK-NEXT: .functype i32_trunc_s_f64 (f64) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i32 @i32_trunc_s_f64(double %x) {
%a = fptosi double %x to i32
ret i32 %a
}
; CHECK-LABEL: i32_trunc_sat_s_f64:
; CHECK-NEXT: .functype i32_trunc_sat_s_f64 (f64) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double)
define i32 @i32_trunc_sat_s_f64(double %x) {
%a = call i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double %x)
ret i32 %a
}
; CHECK-LABEL: i32_trunc_u_f64:
; CHECK-NEXT: .functype i32_trunc_u_f64 (f64) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i32 @i32_trunc_u_f64(double %x) {
%a = fptoui double %x to i32
ret i32 %a
}
; CHECK-LABEL: i32_trunc_sat_u_f64:
; CHECK-NEXT: .functype i32_trunc_sat_u_f64 (f64) -> (i32){{$}}
; CHECK-NEXT: i32.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double)
define i32 @i32_trunc_sat_u_f64(double %x) {
%a = call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double %x)
ret i32 %a
}
; CHECK-LABEL: i64_trunc_s_f32:
; CHECK-NEXT: .functype i64_trunc_s_f32 (f32) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @i64_trunc_s_f32(float %x) {
%a = fptosi float %x to i64
ret i64 %a
}
; CHECK-LABEL: i64_trunc_sat_s_f32:
; CHECK-NEXT: .functype i64_trunc_sat_s_f32 (f32) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f32_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float)
define i64 @i64_trunc_sat_s_f32(float %x) {
%a = call i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float %x)
ret i64 %a
}
; CHECK-LABEL: i64_trunc_u_f32:
; CHECK-NEXT: .functype i64_trunc_u_f32 (f32) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @i64_trunc_u_f32(float %x) {
%a = fptoui float %x to i64
ret i64 %a
}
; CHECK-LABEL: i64_trunc_sat_u_f32:
; CHECK-NEXT: .functype i64_trunc_sat_u_f32 (f32) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f32_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float)
define i64 @i64_trunc_sat_u_f32(float %x) {
%a = call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float %x)
ret i64 %a
}
; CHECK-LABEL: i64_trunc_s_f64:
; CHECK-NEXT: .functype i64_trunc_s_f64 (f64) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @i64_trunc_s_f64(double %x) {
%a = fptosi double %x to i64
ret i64 %a
}
; CHECK-LABEL: i64_trunc_sat_s_f64:
; CHECK-NEXT: .functype i64_trunc_sat_s_f64 (f64) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f64_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double)
define i64 @i64_trunc_sat_s_f64(double %x) {
%a = call i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double %x)
ret i64 %a
}
; CHECK-LABEL: i64_trunc_u_f64:
; CHECK-NEXT: .functype i64_trunc_u_f64 (f64) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @i64_trunc_u_f64(double %x) {
%a = fptoui double %x to i64
ret i64 %a
}
; CHECK-LABEL: i64_trunc_sat_u_f64:
; CHECK-NEXT: .functype i64_trunc_sat_u_f64 (f64) -> (i64){{$}}
; CHECK-NEXT: i64.trunc_sat_f64_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
declare i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double)
define i64 @i64_trunc_sat_u_f64(double %x) {
%a = call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double %x)
ret i64 %a
}
; CHECK-LABEL: f32_convert_s_i32:
; CHECK-NEXT: .functype f32_convert_s_i32 (i32) -> (f32){{$}}
; CHECK-NEXT: f32.convert_i32_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define float @f32_convert_s_i32(i32 %x) {
%a = sitofp i32 %x to float
ret float %a
}
; CHECK-LABEL: f32_convert_u_i32:
; CHECK-NEXT: .functype f32_convert_u_i32 (i32) -> (f32){{$}}
; CHECK-NEXT: f32.convert_i32_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define float @f32_convert_u_i32(i32 %x) {
%a = uitofp i32 %x to float
ret float %a
}
; CHECK-LABEL: f64_convert_s_i32:
; CHECK-NEXT: .functype f64_convert_s_i32 (i32) -> (f64){{$}}
; CHECK-NEXT: f64.convert_i32_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define double @f64_convert_s_i32(i32 %x) {
%a = sitofp i32 %x to double
ret double %a
}
; CHECK-LABEL: f64_convert_u_i32:
; CHECK-NEXT: .functype f64_convert_u_i32 (i32) -> (f64){{$}}
; CHECK-NEXT: f64.convert_i32_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define double @f64_convert_u_i32(i32 %x) {
%a = uitofp i32 %x to double
ret double %a
}
; CHECK-LABEL: f32_convert_s_i64:
; CHECK-NEXT: .functype f32_convert_s_i64 (i64) -> (f32){{$}}
; CHECK-NEXT: f32.convert_i64_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define float @f32_convert_s_i64(i64 %x) {
%a = sitofp i64 %x to float
ret float %a
}
; CHECK-LABEL: f32_convert_u_i64:
; CHECK-NEXT: .functype f32_convert_u_i64 (i64) -> (f32){{$}}
; CHECK-NEXT: f32.convert_i64_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define float @f32_convert_u_i64(i64 %x) {
%a = uitofp i64 %x to float
ret float %a
}
; CHECK-LABEL: f64_convert_s_i64:
; CHECK-NEXT: .functype f64_convert_s_i64 (i64) -> (f64){{$}}
; CHECK-NEXT: f64.convert_i64_s $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define double @f64_convert_s_i64(i64 %x) {
%a = sitofp i64 %x to double
ret double %a
}
; CHECK-LABEL: f64_convert_u_i64:
; CHECK-NEXT: .functype f64_convert_u_i64 (i64) -> (f64){{$}}
; CHECK-NEXT: f64.convert_i64_u $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define double @f64_convert_u_i64(i64 %x) {
%a = uitofp i64 %x to double
ret double %a
}
; CHECK-LABEL: f64_promote_f32:
; CHECK-NEXT: .functype f64_promote_f32 (f32) -> (f64){{$}}
; CHECK-NEXT: f64.promote_f32 $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define double @f64_promote_f32(float %x) {
%a = fpext float %x to double
ret double %a
}
; CHECK-LABEL: f32_demote_f64:
; CHECK-NEXT: .functype f32_demote_f64 (f64) -> (f32){{$}}
; CHECK-NEXT: f32.demote_f64 $push[[NUM:[0-9]+]]=, $0{{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define float @f32_demote_f64(double %x) {
%a = fptrunc double %x to float
ret float %a
}
; If the high its are unused, LLVM will optimize sext/zext into anyext, which
; we need to patterm-match back to a specific instruction.
; CHECK-LABEL: anyext:
; CHECK: i64.extend_i32_u $push0=, $0{{$}}
define i64 @anyext(i32 %x) {
%y = sext i32 %x to i64
%w = shl i64 %y, 32
ret i64 %w
}
; CHECK-LABEL: bitcast_i32_to_float:
; CHECK: f32.reinterpret_i32 $push0=, $0{{$}}
define float @bitcast_i32_to_float(i32 %a) {
%t = bitcast i32 %a to float
ret float %t
}
; CHECK-LABEL: bitcast_float_to_i32:
; CHECK: i32.reinterpret_f32 $push0=, $0{{$}}
define i32 @bitcast_float_to_i32(float %a) {
%t = bitcast float %a to i32
ret i32 %t
}
; CHECK-LABEL: bitcast_i64_to_double:
; CHECK: f64.reinterpret_i64 $push0=, $0{{$}}
define double @bitcast_i64_to_double(i64 %a) {
%t = bitcast i64 %a to double
ret double %t
}
; CHECK-LABEL: bitcast_double_to_i64:
; CHECK: i64.reinterpret_f64 $push0=, $0{{$}}
define i64 @bitcast_double_to_i64(double %a) {
%t = bitcast double %a to i64
ret i64 %t
}