File: fpcast.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (434 lines) | stat: -rw-r--r-- 12,365 bytes parent folder | download | duplicates (3)
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Test some floating point casting cases
; RUN: opt < %s -passes=instcombine -S | FileCheck %s

define i8 @test1() {
; CHECK-LABEL: @test1(
; CHECK-NEXT:    ret i8 -1
;
  %x = fptoui float 2.550000e+02 to i8
  ret i8 %x
}

define i8 @test2() {
; CHECK-LABEL: @test2(
; CHECK-NEXT:    ret i8 -1
;
  %x = fptosi float -1.000000e+00 to i8
  ret i8 %x
}

define half @test3(float %a) {
; CHECK-LABEL: @test3(
; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
; CHECK-NEXT:    [[C:%.*]] = call half @llvm.fabs.f16(half [[TMP1]])
; CHECK-NEXT:    ret half [[C]]
;
  %b = call float @llvm.fabs.f32(float %a)
  %c = fptrunc float %b to half
  ret half %c
}

define half @fneg_fptrunc(float %a) {
; CHECK-LABEL: @fneg_fptrunc(
; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
; CHECK-NEXT:    [[C:%.*]] = fneg half [[TMP1]]
; CHECK-NEXT:    ret half [[C]]
;
  %b = fsub float -0.0, %a
  %c = fptrunc float %b to half
  ret half %c
}

define half @unary_fneg_fptrunc(float %a) {
; CHECK-LABEL: @unary_fneg_fptrunc(
; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
; CHECK-NEXT:    [[C:%.*]] = fneg half [[TMP1]]
; CHECK-NEXT:    ret half [[C]]
;
  %b = fneg float %a
  %c = fptrunc float %b to half
  ret half %c
}

define <2 x half> @fneg_fptrunc_vec_poison(<2 x float> %a) {
; CHECK-LABEL: @fneg_fptrunc_vec_poison(
; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
; CHECK-NEXT:    [[C:%.*]] = fneg <2 x half> [[TMP1]]
; CHECK-NEXT:    ret <2 x half> [[C]]
;
  %b = fsub <2 x float> <float -0.0, float poison>, %a
  %c = fptrunc <2 x float> %b to <2 x half>
  ret <2 x half> %c
}

define <2 x half> @unary_fneg_fptrunc_vec(<2 x float> %a) {
; CHECK-LABEL: @unary_fneg_fptrunc_vec(
; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
; CHECK-NEXT:    [[C:%.*]] = fneg <2 x half> [[TMP1]]
; CHECK-NEXT:    ret <2 x half> [[C]]
;
  %b = fneg <2 x float> %a
  %c = fptrunc <2 x float> %b to <2 x half>
  ret <2 x half> %c
}

define half @test4-fast(float %a) {
; CHECK-LABEL: @test4-fast(
; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
; CHECK-NEXT:    [[C:%.*]] = fneg fast half [[TMP1]]
; CHECK-NEXT:    ret half [[C]]
;
  %b = fsub fast float -0.0, %a
  %c = fptrunc float %b to half
  ret half %c
}

define half @test4_unary_fneg-fast(float %a) {
; CHECK-LABEL: @test4_unary_fneg-fast(
; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
; CHECK-NEXT:    [[C:%.*]] = fneg fast half [[TMP1]]
; CHECK-NEXT:    ret half [[C]]
;
  %b = fneg fast float %a
  %c = fptrunc float %b to half
  ret half %c
}

define half @test5(float %a, float %b, float %c) {
; CHECK-LABEL: @test5(
; CHECK-NEXT:    [[D:%.*]] = fcmp ogt float [[A:%.*]], [[B:%.*]]
; CHECK-NEXT:    [[E:%.*]] = select i1 [[D]], float [[C:%.*]], float 1.000000e+00
; CHECK-NEXT:    [[F:%.*]] = fptrunc float [[E]] to half
; CHECK-NEXT:    ret half [[F]]
;
  %d = fcmp ogt float %a, %b
  %e = select i1 %d, float %c, float 1.0
  %f = fptrunc float %e to half
  ret half %f
}

declare float @llvm.fabs.f32(float) nounwind readonly

define <1 x float> @test6(<1 x double> %V) {
; CHECK-LABEL: @test6(
; CHECK-NEXT:    [[FREM:%.*]] = frem <1 x double> [[V:%.*]], [[V]]
; CHECK-NEXT:    [[TRUNC:%.*]] = fptrunc <1 x double> [[FREM]] to <1 x float>
; CHECK-NEXT:    ret <1 x float> [[TRUNC]]
;
  %frem = frem <1 x double> %V, %V
  %trunc = fptrunc <1 x double> %frem to <1 x float>
  ret <1 x float> %trunc
}

define float @test7(double %V) {
; CHECK-LABEL: @test7(
; CHECK-NEXT:    [[FREM:%.*]] = frem double [[V:%.*]], 1.000000e+00
; CHECK-NEXT:    [[TRUNC:%.*]] = fptrunc double [[FREM]] to float
; CHECK-NEXT:    ret float [[TRUNC]]
;
  %frem = frem double %V, 1.000000e+00
  %trunc = fptrunc double %frem to float
  ret float %trunc
}

define float @test8(float %V) {
; CHECK-LABEL: @test8(
; CHECK-NEXT:    [[FEXT:%.*]] = fpext float [[V:%.*]] to double
; CHECK-NEXT:    [[FREM:%.*]] = frem double [[FEXT]], 1.000000e-01
; CHECK-NEXT:    [[TRUNC:%.*]] = fptrunc double [[FREM]] to float
; CHECK-NEXT:    ret float [[TRUNC]]
;
  %fext = fpext float %V to double
  %frem = frem double %fext, 1.000000e-01
  %trunc = fptrunc double %frem to float
  ret float %trunc
}

define half @test_fptrunc_fptrunc(double %V) {
; CHECK-LABEL: @test_fptrunc_fptrunc(
; CHECK-NEXT:    [[T1:%.*]] = fptrunc double [[V:%.*]] to float
; CHECK-NEXT:    [[T2:%.*]] = fptrunc float [[T1]] to half
; CHECK-NEXT:    ret half [[T2]]
;
  %t1 = fptrunc double %V to float
  %t2 = fptrunc float %t1 to half
  ret half %t2
}

define half @sint_to_fptrunc(i32 %x) {
; CHECK-LABEL: @sint_to_fptrunc(
; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[X:%.*]] to float
; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %f = sitofp i32 %x to float
  %r = fptrunc float %f to half
  ret half %r
}

define half @masked_sint_to_fptrunc1(i32 %x) {
; CHECK-LABEL: @masked_sint_to_fptrunc1(
; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %m = and i32 %x, 16777215
  %f = sitofp i32 %m to float
  %r = fptrunc float %f to half
  ret half %r
}

define half @masked_sint_to_fptrunc2(i32 %x) {
; CHECK-LABEL: @masked_sint_to_fptrunc2(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %m = lshr i32 %x, 8
  %f = sitofp i32 %m to float
  %r = fptrunc float %f to half
  ret half %r
}

define half @masked_sint_to_fptrunc3(i32 %x) {
; CHECK-LABEL: @masked_sint_to_fptrunc3(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
; CHECK-NEXT:    [[F:%.*]] = uitofp nneg i32 [[M]] to float
; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %m = lshr i32 %x, 7
  %f = sitofp i32 %m to float
  %r = fptrunc float %f to half
  ret half %r
}

define double @sint_to_fpext(i32 %x) {
; CHECK-LABEL: @sint_to_fpext(
; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[X:%.*]] to float
; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %f = sitofp i32 %x to float
  %r = fpext float %f to double
  ret double %r
}

define double @masked_sint_to_fpext1(i32 %x) {
; CHECK-LABEL: @masked_sint_to_fpext1(
; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %m = and i32 %x, 16777215
  %f = sitofp i32 %m to float
  %r = fpext float %f to double
  ret double %r
}

define double @masked_sint_to_fpext2(i32 %x) {
; CHECK-LABEL: @masked_sint_to_fpext2(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %m = lshr i32 %x, 8
  %f = sitofp i32 %m to float
  %r = fpext float %f to double
  ret double %r
}

define double @masked_sint_to_fpext3(i32 %x) {
; CHECK-LABEL: @masked_sint_to_fpext3(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
; CHECK-NEXT:    [[F:%.*]] = uitofp nneg i32 [[M]] to float
; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %m = lshr i32 %x, 7
  %f = sitofp i32 %m to float
  %r = fpext float %f to double
  ret double %r
}

define half @uint_to_fptrunc(i32 %x) {
; CHECK-LABEL: @uint_to_fptrunc(
; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[X:%.*]] to float
; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %f = uitofp i32 %x to float
  %r = fptrunc float %f to half
  ret half %r
}

define half @masked_uint_to_fptrunc1(i32 %x) {
; CHECK-LABEL: @masked_uint_to_fptrunc1(
; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %m = and i32 %x, 16777215
  %f = uitofp i32 %m to float
  %r = fptrunc float %f to half
  ret half %r
}

define half @masked_uint_to_fptrunc2(i32 %x) {
; CHECK-LABEL: @masked_uint_to_fptrunc2(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %m = lshr i32 %x, 8
  %f = uitofp i32 %m to float
  %r = fptrunc float %f to half
  ret half %r
}

define half @masked_uint_to_fptrunc3(i32 %x) {
; CHECK-LABEL: @masked_uint_to_fptrunc3(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
; CHECK-NEXT:    [[F:%.*]] = uitofp nneg i32 [[M]] to float
; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
; CHECK-NEXT:    ret half [[R]]
;
  %m = lshr i32 %x, 7
  %f = uitofp i32 %m to float
  %r = fptrunc float %f to half
  ret half %r
}

define double @uint_to_fpext(i32 %x) {
; CHECK-LABEL: @uint_to_fpext(
; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[X:%.*]] to float
; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %f = uitofp i32 %x to float
  %r = fpext float %f to double
  ret double %r
}

define double @masked_uint_to_fpext1(i32 %x) {
; CHECK-LABEL: @masked_uint_to_fpext1(
; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %m = and i32 %x, 16777215
  %f = uitofp i32 %m to float
  %r = fpext float %f to double
  ret double %r
}

define double @masked_uint_to_fpext2(i32 %x) {
; CHECK-LABEL: @masked_uint_to_fpext2(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[M]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %m = lshr i32 %x, 8
  %f = uitofp i32 %m to float
  %r = fpext float %f to double
  ret double %r
}

define double @masked_uint_to_fpext3(i32 %x) {
; CHECK-LABEL: @masked_uint_to_fpext3(
; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
; CHECK-NEXT:    [[F:%.*]] = uitofp nneg i32 [[M]] to float
; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %m = lshr i32 %x, 7
  %f = uitofp i32 %m to float
  %r = fpext float %f to double
  ret double %r
}

define i32 @fptosi_nonnorm(float nofpclass(norm) %x) {
; CHECK-LABEL: @fptosi_nonnorm(
; CHECK-NEXT:    ret i32 0
;
  %ret = fptosi float %x to i32
  ret i32 %ret
}

define i32 @fptoui_nonnorm(float nofpclass(pnorm) %x) {
; CHECK-LABEL: @fptoui_nonnorm(
; CHECK-NEXT:    ret i32 0
;
  %ret = fptoui float %x to i32
  ret i32 %ret
}

define i32 @fptosi_nonnnorm(float nofpclass(nnorm) %x) {
; CHECK-LABEL: @fptosi_nonnnorm(
; CHECK-NEXT:    [[RET:%.*]] = fptosi float [[X:%.*]] to i32
; CHECK-NEXT:    ret i32 [[RET]]
;
  %ret = fptosi float %x to i32
  ret i32 %ret
}

define i32 @fptoui_nonnnorm(float nofpclass(nnorm) %x) {
; CHECK-LABEL: @fptoui_nonnnorm(
; CHECK-NEXT:    [[RET:%.*]] = fptoui float [[X:%.*]] to i32
; CHECK-NEXT:    ret i32 [[RET]]
;
  %ret = fptoui float %x to i32
  ret i32 %ret
}

define i32 @fptosi_nonnorm_copysign(float %x) {
; CHECK-LABEL: @fptosi_nonnorm_copysign(
; CHECK-NEXT:    ret i32 0
;
  %val = call float @llvm.copysign.f32(float 0.0, float %x)
  %ret = fptosi float %val to i32
  ret i32 %ret
}

define <2 x i32> @fptosi_nonnorm_copysign_vec(<2 x float> %x) {
; CHECK-LABEL: @fptosi_nonnorm_copysign_vec(
; CHECK-NEXT:    ret <2 x i32> zeroinitializer
;
  %val = call <2 x float> @llvm.copysign.v2f32(<2 x float> zeroinitializer, <2 x float> %x)
  %ret = fptosi <2 x float> %val to <2 x i32>
  ret <2 x i32> %ret
}

define i32 @fptosi_nonnorm_fmul(float %x) {
; CHECK-LABEL: @fptosi_nonnorm_fmul(
; CHECK-NEXT:    [[SEL:%.*]] = fmul float [[X:%.*]], 0.000000e+00
; CHECK-NEXT:    [[RET:%.*]] = fptosi float [[SEL]] to i32
; CHECK-NEXT:    ret i32 [[RET]]
;
  %sel = fmul float %x, 0.000000e+00
  %ret = fptosi float %sel to i32
  ret i32 %ret
}

define i32 @fptosi_select(i1 %cond) {
; CHECK-LABEL: @fptosi_select(
; CHECK-NEXT:    [[RET:%.*]] = select i1 [[COND:%.*]], i32 1, i32 -1
; CHECK-NEXT:    ret i32 [[RET]]
;
  %sel = select i1 %cond, float 1.0, float -1.0
  %ret = fptosi float %sel to i32
  ret i32 %ret
}

define i32 @mul_pos_zero_convert(i32 %a) {
; CHECK-LABEL: @mul_pos_zero_convert(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    ret i32 0
;
entry:
  %fp = sitofp i32 %a to float
  %ret = fmul float %fp, 0.000000e+00
  %conv = fptosi float %ret to i32
  ret i32 %conv
}