1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define float @test(float %x) nounwind {
7 ; CHECK-NEXT: [[TMP34:%.*]] = fadd float [[X:%.*]], 0.000000e+00
8 ; CHECK-NEXT: ret float [[TMP34]]
11 %tmp1 = fpext float %x to double
12 %tmp3 = fadd double %tmp1, 0.000000e+00
13 %tmp34 = fptrunc double %tmp3 to float
17 define float @test2(float %x, float %y) nounwind {
18 ; CHECK-LABEL: @test2(
20 ; CHECK-NEXT: [[TMP56:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
21 ; CHECK-NEXT: ret float [[TMP56]]
24 %tmp1 = fpext float %x to double
25 %tmp23 = fpext float %y to double
26 %tmp5 = fmul double %tmp1, %tmp23
27 %tmp56 = fptrunc double %tmp5 to float
31 define float @test3(float %x, float %y) nounwind {
32 ; CHECK-LABEL: @test3(
34 ; CHECK-NEXT: [[TMP56:%.*]] = fdiv float [[X:%.*]], [[Y:%.*]]
35 ; CHECK-NEXT: ret float [[TMP56]]
38 %tmp1 = fpext float %x to double
39 %tmp23 = fpext float %y to double
40 %tmp5 = fdiv double %tmp1, %tmp23
41 %tmp56 = fptrunc double %tmp5 to float
45 define float @test4(float %x) nounwind {
46 ; CHECK-LABEL: @test4(
48 ; CHECK-NEXT: [[TMP34:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
49 ; CHECK-NEXT: ret float [[TMP34]]
52 %tmp1 = fpext float %x to double
53 %tmp2 = fsub double -0.000000e+00, %tmp1
54 %tmp34 = fptrunc double %tmp2 to float
58 define float @test4_unary_fneg(float %x) nounwind {
59 ; CHECK-LABEL: @test4_unary_fneg(
61 ; CHECK-NEXT: [[TMP34:%.*]] = fneg float [[X:%.*]]
62 ; CHECK-NEXT: ret float [[TMP34]]
65 %tmp1 = fpext float %x to double
66 %tmp2 = fneg double %tmp1
67 %tmp34 = fptrunc double %tmp2 to float
71 ; Test with vector splat constant
72 define <2 x float> @test5(<2 x float> %x) nounwind {
73 ; CHECK-LABEL: @test5(
75 ; CHECK-NEXT: [[TMP34:%.*]] = fadd <2 x float> [[X:%.*]], zeroinitializer
76 ; CHECK-NEXT: ret <2 x float> [[TMP34]]
79 %tmp1 = fpext <2 x float> %x to <2 x double>
80 %tmp3 = fadd <2 x double> %tmp1, <double 0.000000e+00, double 0.000000e+00>
81 %tmp34 = fptrunc <2 x double> %tmp3 to <2 x float>
82 ret <2 x float> %tmp34
85 ; Test with a non-splat constant
86 define <2 x float> @test6(<2 x float> %x) nounwind {
87 ; CHECK-LABEL: @test6(
89 ; CHECK-NEXT: [[TMP34:%.*]] = fadd <2 x float> [[X:%.*]], <float 0.000000e+00, float -0.000000e+00>
90 ; CHECK-NEXT: ret <2 x float> [[TMP34]]
93 %tmp1 = fpext <2 x float> %x to <2 x double>
94 %tmp3 = fadd <2 x double> %tmp1, <double 0.000000e+00, double -0.000000e+00>
95 %tmp34 = fptrunc <2 x double> %tmp3 to <2 x float>
96 ret <2 x float> %tmp34
99 ; Test with an undef element
100 ; TODO: Support undef elements.
101 define <2 x float> @test6_undef(<2 x float> %x) nounwind {
102 ; CHECK-LABEL: @test6_undef(
104 ; CHECK-NEXT: [[TMP1:%.*]] = fpext <2 x float> [[X:%.*]] to <2 x double>
105 ; CHECK-NEXT: [[TMP3:%.*]] = fadd <2 x double> [[TMP1]], <double 0.000000e+00, double undef>
106 ; CHECK-NEXT: [[TMP34:%.*]] = fptrunc <2 x double> [[TMP3]] to <2 x float>
107 ; CHECK-NEXT: ret <2 x float> [[TMP34]]
110 %tmp1 = fpext <2 x float> %x to <2 x double>
111 %tmp3 = fadd <2 x double> %tmp1, <double 0.000000e+00, double undef>
112 %tmp34 = fptrunc <2 x double> %tmp3 to <2 x float>
113 ret <2 x float> %tmp34
116 define <2 x float> @not_half_shrinkable(<2 x float> %x) {
117 ; CHECK-LABEL: @not_half_shrinkable(
118 ; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], <float 0.000000e+00, float 2.049000e+03>
119 ; CHECK-NEXT: ret <2 x float> [[R]]
121 %ext = fpext <2 x float> %x to <2 x double>
122 %add = fadd <2 x double> %ext, <double 0.0, double 2049.0>
123 %r = fptrunc <2 x double> %add to <2 x float>
127 define half @test7(float %a) nounwind {
128 ; CHECK-LABEL: @test7(
129 ; CHECK-NEXT: [[Z:%.*]] = fptrunc float [[A:%.*]] to half
130 ; CHECK-NEXT: ret half [[Z]]
132 %y = fpext float %a to double
133 %z = fptrunc double %y to half
137 define float @test8(half %a) nounwind {
138 ; CHECK-LABEL: @test8(
139 ; CHECK-NEXT: [[Z:%.*]] = fpext half [[A:%.*]] to float
140 ; CHECK-NEXT: ret float [[Z]]
142 %y = fpext half %a to double
143 %z = fptrunc double %y to float
147 define float @test9(half %x, half %y) nounwind {
148 ; CHECK-LABEL: @test9(
150 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[X:%.*]] to float
151 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[Y:%.*]] to float
152 ; CHECK-NEXT: [[TMP56:%.*]] = fmul float [[TMP0]], [[TMP1]]
153 ; CHECK-NEXT: ret float [[TMP56]]
156 %tmp1 = fpext half %x to double
157 %tmp23 = fpext half %y to double
158 %tmp5 = fmul double %tmp1, %tmp23
159 %tmp56 = fptrunc double %tmp5 to float
163 define float @test10(half %x, float %y) nounwind {
164 ; CHECK-LABEL: @test10(
166 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[X:%.*]] to float
167 ; CHECK-NEXT: [[TMP56:%.*]] = fmul float [[TMP0]], [[Y:%.*]]
168 ; CHECK-NEXT: ret float [[TMP56]]
171 %tmp1 = fpext half %x to double
172 %tmp23 = fpext float %y to double
173 %tmp5 = fmul double %tmp1, %tmp23
174 %tmp56 = fptrunc double %tmp5 to float
178 define float @test11(half %x) nounwind {
179 ; CHECK-LABEL: @test11(
181 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[X:%.*]] to float
182 ; CHECK-NEXT: [[TMP34:%.*]] = fadd float [[TMP0]], 0.000000e+00
183 ; CHECK-NEXT: ret float [[TMP34]]
186 %tmp1 = fpext half %x to double
187 %tmp3 = fadd double %tmp1, 0.000000e+00
188 %tmp34 = fptrunc double %tmp3 to float
192 define float @test12(float %x, half %y) nounwind {
193 ; CHECK-LABEL: @test12(
195 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[Y:%.*]] to float
196 ; CHECK-NEXT: [[TMP34:%.*]] = fadd float [[TMP0]], [[X:%.*]]
197 ; CHECK-NEXT: ret float [[TMP34]]
200 %tmp1 = fpext float %x to double
201 %tmp2 = fpext half %y to double
202 %tmp3 = fadd double %tmp1, %tmp2
203 %tmp34 = fptrunc double %tmp3 to float
207 define float @test13(half %x, float %y) nounwind {
208 ; CHECK-LABEL: @test13(
210 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[X:%.*]] to float
211 ; CHECK-NEXT: [[TMP56:%.*]] = fdiv float [[TMP0]], [[Y:%.*]]
212 ; CHECK-NEXT: ret float [[TMP56]]
215 %tmp1 = fpext half %x to double
216 %tmp23 = fpext float %y to double
217 %tmp5 = fdiv double %tmp1, %tmp23
218 %tmp56 = fptrunc double %tmp5 to float
222 define float @test14(float %x, half %y) nounwind {
223 ; CHECK-LABEL: @test14(
225 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[Y:%.*]] to float
226 ; CHECK-NEXT: [[TMP56:%.*]] = fdiv float [[X:%.*]], [[TMP0]]
227 ; CHECK-NEXT: ret float [[TMP56]]
230 %tmp1 = fpext float %x to double
231 %tmp23 = fpext half %y to double
232 %tmp5 = fdiv double %tmp1, %tmp23
233 %tmp56 = fptrunc double %tmp5 to float
237 define float @test15(half %x, half %y) nounwind {
238 ; CHECK-LABEL: @test15(
240 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[X:%.*]] to float
241 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[Y:%.*]] to float
242 ; CHECK-NEXT: [[TMP56:%.*]] = fdiv float [[TMP0]], [[TMP1]]
243 ; CHECK-NEXT: ret float [[TMP56]]
246 %tmp1 = fpext half %x to double
247 %tmp23 = fpext half %y to double
248 %tmp5 = fdiv double %tmp1, %tmp23
249 %tmp56 = fptrunc double %tmp5 to float
253 define float @test16(half %x, float %y) nounwind {
254 ; CHECK-LABEL: @test16(
256 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[X:%.*]] to float
257 ; CHECK-NEXT: [[TMP1:%.*]] = frem float [[TMP0]], [[Y:%.*]]
258 ; CHECK-NEXT: ret float [[TMP1]]
261 %tmp1 = fpext half %x to double
262 %tmp23 = fpext float %y to double
263 %tmp5 = frem double %tmp1, %tmp23
264 %tmp56 = fptrunc double %tmp5 to float
268 define float @test17(float %x, half %y) nounwind {
269 ; CHECK-LABEL: @test17(
271 ; CHECK-NEXT: [[TMP0:%.*]] = fpext half [[Y:%.*]] to float
272 ; CHECK-NEXT: [[TMP1:%.*]] = frem float [[X:%.*]], [[TMP0]]
273 ; CHECK-NEXT: ret float [[TMP1]]
276 %tmp1 = fpext float %x to double
277 %tmp23 = fpext half %y to double
278 %tmp5 = frem double %tmp1, %tmp23
279 %tmp56 = fptrunc double %tmp5 to float
283 define float @test18(half %x, half %y) nounwind {
284 ; CHECK-LABEL: @test18(
286 ; CHECK-NEXT: [[TMP0:%.*]] = frem half [[X:%.*]], [[Y:%.*]]
287 ; CHECK-NEXT: [[TMP56:%.*]] = fpext half [[TMP0]] to float
288 ; CHECK-NEXT: ret float [[TMP56]]
291 %tmp1 = fpext half %x to double
292 %tmp23 = fpext half %y to double
293 %tmp5 = frem double %tmp1, %tmp23
294 %tmp56 = fptrunc double %tmp5 to float