1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test some floating point casting cases
3 ; RUN: opt < %s -instcombine -S | FileCheck %s
7 ; CHECK-NEXT: ret i8 -1
9 %x = fptoui float 2.550000e+02 to i8
14 ; CHECK-LABEL: @test2(
15 ; CHECK-NEXT: ret i8 -1
17 %x = fptosi float -1.000000e+00 to i8
21 define half @test3(float %a) {
22 ; CHECK-LABEL: @test3(
23 ; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
24 ; CHECK-NEXT: [[C:%.*]] = call half @llvm.fabs.f16(half [[TMP1]])
25 ; CHECK-NEXT: ret half [[C]]
27 %b = call float @llvm.fabs.f32(float %a)
28 %c = fptrunc float %b to half
32 define half @fneg_fptrunc(float %a) {
33 ; CHECK-LABEL: @fneg_fptrunc(
34 ; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
35 ; CHECK-NEXT: [[C:%.*]] = fsub half 0xH8000, [[TMP1]]
36 ; CHECK-NEXT: ret half [[C]]
38 %b = fsub float -0.0, %a
39 %c = fptrunc float %b to half
43 define half @unary_fneg_fptrunc(float %a) {
44 ; CHECK-LABEL: @unary_fneg_fptrunc(
45 ; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
46 ; CHECK-NEXT: [[C:%.*]] = fneg half [[TMP1]]
47 ; CHECK-NEXT: ret half [[C]]
50 %c = fptrunc float %b to half
54 define <2 x half> @fneg_fptrunc_vec_undef(<2 x float> %a) {
55 ; CHECK-LABEL: @fneg_fptrunc_vec_undef(
56 ; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
57 ; CHECK-NEXT: [[C:%.*]] = fsub <2 x half> <half 0xH8000, half 0xH8000>, [[TMP1]]
58 ; CHECK-NEXT: ret <2 x half> [[C]]
60 %b = fsub <2 x float> <float -0.0, float undef>, %a
61 %c = fptrunc <2 x float> %b to <2 x half>
65 define <2 x half> @unary_fneg_fptrunc_vec(<2 x float> %a) {
66 ; CHECK-LABEL: @unary_fneg_fptrunc_vec(
67 ; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
68 ; CHECK-NEXT: [[C:%.*]] = fneg <2 x half> [[TMP1]]
69 ; CHECK-NEXT: ret <2 x half> [[C]]
71 %b = fneg <2 x float> %a
72 %c = fptrunc <2 x float> %b to <2 x half>
76 define half @test4-fast(float %a) {
77 ; CHECK-LABEL: @test4-fast(
78 ; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
79 ; CHECK-NEXT: [[C:%.*]] = fsub fast half 0xH8000, [[TMP1]]
80 ; CHECK-NEXT: ret half [[C]]
82 %b = fsub fast float -0.0, %a
83 %c = fptrunc float %b to half
87 define half @test4_unary_fneg-fast(float %a) {
88 ; CHECK-LABEL: @test4_unary_fneg-fast(
89 ; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
90 ; CHECK-NEXT: [[C:%.*]] = fneg fast half [[TMP1]]
91 ; CHECK-NEXT: ret half [[C]]
93 %b = fneg fast float %a
94 %c = fptrunc float %b to half
98 define half @test5(float %a, float %b, float %c) {
99 ; CHECK-LABEL: @test5(
100 ; CHECK-NEXT: [[D:%.*]] = fcmp ogt float [[A:%.*]], [[B:%.*]]
101 ; CHECK-NEXT: [[E:%.*]] = select i1 [[D]], float [[C:%.*]], float 1.000000e+00
102 ; CHECK-NEXT: [[F:%.*]] = fptrunc float [[E]] to half
103 ; CHECK-NEXT: ret half [[F]]
105 %d = fcmp ogt float %a, %b
106 %e = select i1 %d, float %c, float 1.0
107 %f = fptrunc float %e to half
111 declare float @llvm.fabs.f32(float) nounwind readonly
113 define <1 x float> @test6(<1 x double> %V) {
114 ; CHECK-LABEL: @test6(
115 ; CHECK-NEXT: [[FREM:%.*]] = frem <1 x double> [[V:%.*]], [[V]]
116 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc <1 x double> [[FREM]] to <1 x float>
117 ; CHECK-NEXT: ret <1 x float> [[TRUNC]]
119 %frem = frem <1 x double> %V, %V
120 %trunc = fptrunc <1 x double> %frem to <1 x float>
121 ret <1 x float> %trunc
124 define float @test7(double %V) {
125 ; CHECK-LABEL: @test7(
126 ; CHECK-NEXT: [[FREM:%.*]] = frem double [[V:%.*]], 1.000000e+00
127 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc double [[FREM]] to float
128 ; CHECK-NEXT: ret float [[TRUNC]]
130 %frem = frem double %V, 1.000000e+00
131 %trunc = fptrunc double %frem to float
135 define float @test8(float %V) {
136 ; CHECK-LABEL: @test8(
137 ; CHECK-NEXT: [[FEXT:%.*]] = fpext float [[V:%.*]] to double
138 ; CHECK-NEXT: [[FREM:%.*]] = frem double [[FEXT]], 1.000000e-01
139 ; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc double [[FREM]] to float
140 ; CHECK-NEXT: ret float [[TRUNC]]
142 %fext = fpext float %V to double
143 %frem = frem double %fext, 1.000000e-01
144 %trunc = fptrunc double %frem to float
148 define half @test_fptrunc_fptrunc(double %V) {
149 ; CHECK-LABEL: @test_fptrunc_fptrunc(
150 ; CHECK-NEXT: [[T1:%.*]] = fptrunc double [[V:%.*]] to float
151 ; CHECK-NEXT: [[T2:%.*]] = fptrunc float [[T1]] to half
152 ; CHECK-NEXT: ret half [[T2]]
154 %t1 = fptrunc double %V to float
155 %t2 = fptrunc float %t1 to half