1; Test some floating point casting cases
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4define i8 @test1() {
5        %x = fptoui float 2.550000e+02 to i8            ; <i8> [#uses=1]
6        ret i8 %x
7; CHECK: ret i8 -1
8}
9
10define i8 @test2() {
11        %x = fptosi float -1.000000e+00 to i8           ; <i8> [#uses=1]
12        ret i8 %x
13; CHECK: ret i8 -1
14}
15
16; CHECK: test3
17define half @test3(float %a) {
18; CHECK: fptrunc
19; CHECK: llvm.fabs.f16
20  %b = call float @llvm.fabs.f32(float %a)
21  %c = fptrunc float %b to half
22  ret half %c
23}
24
25; CHECK: test4
26define half @test4(float %a) {
27; CHECK: fptrunc
28; CHECK: fsub
29  %b = fsub float -0.0, %a
30  %c = fptrunc float %b to half
31  ret half %c
32}
33
34; CHECK: test4-fast
35define half @test4-fast(float %a) {
36; CHECK: fptrunc
37; CHECK: fsub fast
38  %b = fsub fast float -0.0, %a
39  %c = fptrunc float %b to half
40  ret half %c
41}
42
43; CHECK: test5
44define half @test5(float %a, float %b, float %c) {
45; CHECK: fcmp ogt
46; CHECK: fptrunc
47; CHECK: select
48; CHECK: half 0xH3C00
49  %d = fcmp ogt float %a, %b
50  %e = select i1 %d, float %c, float 1.0
51  %f = fptrunc float %e to half
52  ret half %f
53}
54
55declare float @llvm.fabs.f32(float) nounwind readonly
56
57define <1 x float> @test6(<1 x double> %V) {
58  %frem = frem <1 x double> %V, %V
59  %trunc = fptrunc <1 x double> %frem to <1 x float>
60  ret <1 x float> %trunc
61; CHECK-LABEL: @test6
62; CHECK-NEXT: %[[frem:.*]]  = frem <1 x double> %V, %V
63; CHECK-NEXT: %[[trunc:.*]] = fptrunc <1 x double> %[[frem]] to <1 x float>
64; CHECK-NEXT: ret <1 x float> %trunc
65}
66
67define float @test7(double %V) {
68  %frem = frem double %V, 1.000000e+00
69  %trunc = fptrunc double %frem to float
70  ret float %trunc
71; CHECK-LABEL: @test7
72; CHECK-NEXT: %[[frem:.*]]  = frem double %V, 1.000000e+00
73; CHECK-NEXT: %[[trunc:.*]] = fptrunc double %frem to float
74; CHECK-NEXT: ret float %trunc
75}
76
77define float @test8(float %V) {
78  %fext = fpext float %V to double
79  %frem = frem double %fext, 1.000000e-01
80  %trunc = fptrunc double %frem to float
81  ret float %trunc
82; CHECK-LABEL: @test8
83; CHECK-NEXT: %[[fext:.*]]  = fpext float %V to double
84; CHECK-NEXT: %[[frem:.*]]  = frem double %fext, 1.000000e-01
85; CHECK-NEXT: %[[trunc:.*]] = fptrunc double %frem to float
86; CHECK-NEXT: ret float %trunc
87}
88
89; CHECK-LABEL: @test_fptrunc_fptrunc
90; CHECK-NOT: fptrunc double {{.*}} to half
91define half @test_fptrunc_fptrunc(double %V) {
92  %t1 = fptrunc double %V to float
93  %t2 = fptrunc float %t1 to half
94  ret half %t2
95}
96