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 {
6 ; CHECK-NEXT: [[T34:%.*]] = fadd float [[X:%.*]], 0.000000e+00
7 ; CHECK-NEXT: ret float [[T34]]
9 %t1 = fpext float %x to double
10 %t3 = fadd double %t1, 0.000000e+00
11 %t34 = fptrunc double %t3 to float
15 define float @test2(float %x, float %y) nounwind {
16 ; CHECK-LABEL: @test2(
17 ; CHECK-NEXT: [[T56:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
18 ; CHECK-NEXT: ret float [[T56]]
20 %t1 = fpext float %x to double
21 %t23 = fpext float %y to double
22 %t5 = fmul double %t1, %t23
23 %t56 = fptrunc double %t5 to float
27 define float @test3(float %x, float %y) nounwind {
28 ; CHECK-LABEL: @test3(
29 ; CHECK-NEXT: [[T56:%.*]] = fdiv float [[X:%.*]], [[Y:%.*]]
30 ; CHECK-NEXT: ret float [[T56]]
32 %t1 = fpext float %x to double
33 %t23 = fpext float %y to double
34 %t5 = fdiv double %t1, %t23
35 %t56 = fptrunc double %t5 to float
39 define float @test4(float %x) nounwind {
40 ; CHECK-LABEL: @test4(
41 ; CHECK-NEXT: [[T34:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
42 ; CHECK-NEXT: ret float [[T34]]
44 %t1 = fpext float %x to double
45 %t2 = fsub double -0.000000e+00, %t1
46 %t34 = fptrunc double %t2 to float
50 define float @test4_unary_fneg(float %x) nounwind {
51 ; CHECK-LABEL: @test4_unary_fneg(
52 ; CHECK-NEXT: [[T34:%.*]] = fneg float [[X:%.*]]
53 ; CHECK-NEXT: ret float [[T34]]
55 %t1 = fpext float %x to double
57 %t34 = fptrunc double %t2 to float
61 ; Test with vector splat constant
62 define <2 x float> @test5(<2 x float> %x) nounwind {
63 ; CHECK-LABEL: @test5(
64 ; CHECK-NEXT: [[T34:%.*]] = fadd <2 x float> [[X:%.*]], zeroinitializer
65 ; CHECK-NEXT: ret <2 x float> [[T34]]
67 %t1 = fpext <2 x float> %x to <2 x double>
68 %t3 = fadd <2 x double> %t1, <double 0.000000e+00, double 0.000000e+00>
69 %t34 = fptrunc <2 x double> %t3 to <2 x float>
73 ; Test with a non-splat constant
74 define <2 x float> @test6(<2 x float> %x) nounwind {
75 ; CHECK-LABEL: @test6(
76 ; CHECK-NEXT: [[T34:%.*]] = fadd <2 x float> [[X:%.*]], <float 0.000000e+00, float -0.000000e+00>
77 ; CHECK-NEXT: ret <2 x float> [[T34]]
79 %t1 = fpext <2 x float> %x to <2 x double>
80 %t3 = fadd <2 x double> %t1, <double 0.000000e+00, double -0.000000e+00>
81 %t34 = fptrunc <2 x double> %t3 to <2 x float>
85 ; Test with an undef element
86 ; TODO: Support undef elements.
87 define <2 x float> @test6_undef(<2 x float> %x) nounwind {
88 ; CHECK-LABEL: @test6_undef(
89 ; CHECK-NEXT: [[T1:%.*]] = fpext <2 x float> [[X:%.*]] to <2 x double>
90 ; CHECK-NEXT: [[T3:%.*]] = fadd <2 x double> [[T1]], <double 0.000000e+00, double undef>
91 ; CHECK-NEXT: [[T34:%.*]] = fptrunc <2 x double> [[T3]] to <2 x float>
92 ; CHECK-NEXT: ret <2 x float> [[T34]]
94 %t1 = fpext <2 x float> %x to <2 x double>
95 %t3 = fadd <2 x double> %t1, <double 0.000000e+00, double undef>
96 %t34 = fptrunc <2 x double> %t3 to <2 x float>
100 define <2 x float> @not_half_shrinkable(<2 x float> %x) {
101 ; CHECK-LABEL: @not_half_shrinkable(
102 ; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], <float 0.000000e+00, float 2.049000e+03>
103 ; CHECK-NEXT: ret <2 x float> [[R]]
105 %ext = fpext <2 x float> %x to <2 x double>
106 %add = fadd <2 x double> %ext, <double 0.0, double 2049.0>
107 %r = fptrunc <2 x double> %add to <2 x float>
111 define half @test7(float %a) nounwind {
112 ; CHECK-LABEL: @test7(
113 ; CHECK-NEXT: [[Z:%.*]] = fptrunc float [[A:%.*]] to half
114 ; CHECK-NEXT: ret half [[Z]]
116 %y = fpext float %a to double
117 %z = fptrunc double %y to half
121 define float @test8(half %a) nounwind {
122 ; CHECK-LABEL: @test8(
123 ; CHECK-NEXT: [[Z:%.*]] = fpext half [[A:%.*]] to float
124 ; CHECK-NEXT: ret float [[Z]]
126 %y = fpext half %a to double
127 %z = fptrunc double %y to float
131 define float @test9(half %x, half %y) nounwind {
132 ; CHECK-LABEL: @test9(
133 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[X:%.*]] to float
134 ; CHECK-NEXT: [[TMP2:%.*]] = fpext half [[Y:%.*]] to float
135 ; CHECK-NEXT: [[T56:%.*]] = fmul float [[TMP1]], [[TMP2]]
136 ; CHECK-NEXT: ret float [[T56]]
138 %t1 = fpext half %x to double
139 %t23 = fpext half %y to double
140 %t5 = fmul double %t1, %t23
141 %t56 = fptrunc double %t5 to float
145 define float @test10(half %x, float %y) nounwind {
146 ; CHECK-LABEL: @test10(
147 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[X:%.*]] to float
148 ; CHECK-NEXT: [[T56:%.*]] = fmul float [[TMP1]], [[Y:%.*]]
149 ; CHECK-NEXT: ret float [[T56]]
151 %t1 = fpext half %x to double
152 %t23 = fpext float %y to double
153 %t5 = fmul double %t1, %t23
154 %t56 = fptrunc double %t5 to float
158 define float @test11(half %x) nounwind {
159 ; CHECK-LABEL: @test11(
160 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[X:%.*]] to float
161 ; CHECK-NEXT: [[T34:%.*]] = fadd float [[TMP1]], 0.000000e+00
162 ; CHECK-NEXT: ret float [[T34]]
164 %t1 = fpext half %x to double
165 %t3 = fadd double %t1, 0.000000e+00
166 %t34 = fptrunc double %t3 to float
170 define float @test12(float %x, half %y) nounwind {
171 ; CHECK-LABEL: @test12(
172 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[Y:%.*]] to float
173 ; CHECK-NEXT: [[T34:%.*]] = fadd float [[TMP1]], [[X:%.*]]
174 ; CHECK-NEXT: ret float [[T34]]
176 %t1 = fpext float %x to double
177 %t2 = fpext half %y to double
178 %t3 = fadd double %t1, %t2
179 %t34 = fptrunc double %t3 to float
183 define float @test13(half %x, float %y) nounwind {
184 ; CHECK-LABEL: @test13(
185 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[X:%.*]] to float
186 ; CHECK-NEXT: [[T56:%.*]] = fdiv float [[TMP1]], [[Y:%.*]]
187 ; CHECK-NEXT: ret float [[T56]]
189 %t1 = fpext half %x to double
190 %t23 = fpext float %y to double
191 %t5 = fdiv double %t1, %t23
192 %t56 = fptrunc double %t5 to float
196 define float @test14(float %x, half %y) nounwind {
197 ; CHECK-LABEL: @test14(
198 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[Y:%.*]] to float
199 ; CHECK-NEXT: [[T56:%.*]] = fdiv float [[X:%.*]], [[TMP1]]
200 ; CHECK-NEXT: ret float [[T56]]
202 %t1 = fpext float %x to double
203 %t23 = fpext half %y to double
204 %t5 = fdiv double %t1, %t23
205 %t56 = fptrunc double %t5 to float
209 define float @test15(half %x, half %y) nounwind {
210 ; CHECK-LABEL: @test15(
211 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[X:%.*]] to float
212 ; CHECK-NEXT: [[TMP2:%.*]] = fpext half [[Y:%.*]] to float
213 ; CHECK-NEXT: [[T56:%.*]] = fdiv float [[TMP1]], [[TMP2]]
214 ; CHECK-NEXT: ret float [[T56]]
216 %t1 = fpext half %x to double
217 %t23 = fpext half %y to double
218 %t5 = fdiv double %t1, %t23
219 %t56 = fptrunc double %t5 to float
223 define float @test16(half %x, float %y) nounwind {
224 ; CHECK-LABEL: @test16(
225 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[X:%.*]] to float
226 ; CHECK-NEXT: [[TMP2:%.*]] = frem float [[TMP1]], [[Y:%.*]]
227 ; CHECK-NEXT: ret float [[TMP2]]
229 %t1 = fpext half %x to double
230 %t23 = fpext float %y to double
231 %t5 = frem double %t1, %t23
232 %t56 = fptrunc double %t5 to float
236 define float @test17(float %x, half %y) nounwind {
237 ; CHECK-LABEL: @test17(
238 ; CHECK-NEXT: [[TMP1:%.*]] = fpext half [[Y:%.*]] to float
239 ; CHECK-NEXT: [[TMP2:%.*]] = frem float [[X:%.*]], [[TMP1]]
240 ; CHECK-NEXT: ret float [[TMP2]]
242 %t1 = fpext float %x to double
243 %t23 = fpext half %y to double
244 %t5 = frem double %t1, %t23
245 %t56 = fptrunc double %t5 to float
249 define float @test18(half %x, half %y) nounwind {
250 ; CHECK-LABEL: @test18(
251 ; CHECK-NEXT: [[TMP1:%.*]] = frem half [[X:%.*]], [[Y:%.*]]
252 ; CHECK-NEXT: [[T56:%.*]] = fpext half [[TMP1]] to float
253 ; CHECK-NEXT: ret float [[T56]]
255 %t1 = fpext half %x to double
256 %t23 = fpext half %y to double
257 %t5 = frem double %t1, %t23
258 %t56 = fptrunc double %t5 to float