1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare void @use(float)
6 define float @fneg_fneg(float %a) {
8 ; CHECK-LABEL: @fneg_fneg(
9 ; CHECK-NEXT: ret float [[A:%.*]]
16 ; -(X * C) --> X * (-C)
18 define float @fmul_fsub(float %x) {
19 ; CHECK-LABEL: @fmul_fsub(
20 ; CHECK-NEXT: [[R:%.*]] = fmul float [[X:%.*]], -4.200000e+01
21 ; CHECK-NEXT: ret float [[R]]
23 %m = fmul float %x, 42.0
24 %r = fsub float -0.0, %m
28 define float @fmul_fneg(float %x) {
29 ; CHECK-LABEL: @fmul_fneg(
30 ; CHECK-NEXT: [[R:%.*]] = fmul float [[X:%.*]], -4.200000e+01
31 ; CHECK-NEXT: ret float [[R]]
33 %m = fmul float %x, 42.0
38 ; Fast math is not required, but it should be propagated.
40 define float @fmul_fsub_fmf(float %x) {
41 ; CHECK-LABEL: @fmul_fsub_fmf(
42 ; CHECK-NEXT: [[R:%.*]] = fmul reassoc nsz float [[X:%.*]], -4.200000e+01
43 ; CHECK-NEXT: ret float [[R]]
45 %m = fmul float %x, 42.0
46 %r = fsub reassoc nsz float -0.0, %m
50 define float @fmul_fneg_fmf(float %x) {
51 ; CHECK-LABEL: @fmul_fneg_fmf(
52 ; CHECK-NEXT: [[R:%.*]] = fmul reassoc nsz float [[X:%.*]], -4.200000e+01
53 ; CHECK-NEXT: ret float [[R]]
55 %m = fmul float %x, 42.0
56 %r = fneg reassoc nsz float %m
60 ; Extra use prevents the fold. We don't want to replace the fneg with an fmul.
62 define float @fmul_fsub_extra_use(float %x) {
63 ; CHECK-LABEL: @fmul_fsub_extra_use(
64 ; CHECK-NEXT: [[M:%.*]] = fmul float [[X:%.*]], 4.200000e+01
65 ; CHECK-NEXT: [[R:%.*]] = fneg float [[M]]
66 ; CHECK-NEXT: call void @use(float [[M]])
67 ; CHECK-NEXT: ret float [[R]]
69 %m = fmul float %x, 42.0
70 %r = fsub float -0.0, %m
71 call void @use(float %m)
75 define float @fmul_fneg_extra_use(float %x) {
76 ; CHECK-LABEL: @fmul_fneg_extra_use(
77 ; CHECK-NEXT: [[M:%.*]] = fmul float [[X:%.*]], 4.200000e+01
78 ; CHECK-NEXT: [[R:%.*]] = fneg float [[M]]
79 ; CHECK-NEXT: call void @use(float [[M]])
80 ; CHECK-NEXT: ret float [[R]]
82 %m = fmul float %x, 42.0
84 call void @use(float %m)
88 ; Try a vector. Use special constants (NaN, INF, undef) because they don't change anything.
90 define <4 x double> @fmul_fsub_vec(<4 x double> %x) {
91 ; CHECK-LABEL: @fmul_fsub_vec(
92 ; CHECK-NEXT: [[R:%.*]] = fmul <4 x double> [[X:%.*]], <double -4.200000e+01, double 0xFFF8000000000000, double 0xFFF0000000000000, double undef>
93 ; CHECK-NEXT: ret <4 x double> [[R]]
95 %m = fmul <4 x double> %x, <double 42.0, double 0x7FF8000000000000, double 0x7FF0000000000000, double undef>
96 %r = fsub <4 x double> <double -0.0, double -0.0, double -0.0, double -0.0>, %m
100 define <4 x double> @fmul_fneg_vec(<4 x double> %x) {
101 ; CHECK-LABEL: @fmul_fneg_vec(
102 ; CHECK-NEXT: [[R:%.*]] = fmul <4 x double> [[X:%.*]], <double -4.200000e+01, double 0xFFF8000000000000, double 0xFFF0000000000000, double undef>
103 ; CHECK-NEXT: ret <4 x double> [[R]]
105 %m = fmul <4 x double> %x, <double 42.0, double 0x7FF8000000000000, double 0x7FF0000000000000, double undef>
106 %r = fneg <4 x double> %m
110 ; -(X / C) --> X / (-C)
112 define float @fdiv_op1_constant_fsub(float %x) {
113 ; CHECK-LABEL: @fdiv_op1_constant_fsub(
114 ; CHECK-NEXT: [[R:%.*]] = fdiv float [[X:%.*]], 4.200000e+01
115 ; CHECK-NEXT: ret float [[R]]
117 %d = fdiv float %x, -42.0
118 %r = fsub float -0.0, %d
122 define float @fdiv_op1_constant_fneg(float %x) {
123 ; CHECK-LABEL: @fdiv_op1_constant_fneg(
124 ; CHECK-NEXT: [[R:%.*]] = fdiv float [[X:%.*]], 4.200000e+01
125 ; CHECK-NEXT: ret float [[R]]
127 %d = fdiv float %x, -42.0
132 ; Fast math is not required, but it should be propagated.
134 define float @fdiv_op1_constant_fsub_fmf(float %x) {
135 ; CHECK-LABEL: @fdiv_op1_constant_fsub_fmf(
136 ; CHECK-NEXT: [[R:%.*]] = fdiv nnan float [[X:%.*]], 4.200000e+01
137 ; CHECK-NEXT: ret float [[R]]
139 %d = fdiv float %x, -42.0
140 %r = fsub nnan float -0.0, %d
144 define float @fdiv_op1_constant_fneg_fmf(float %x) {
145 ; CHECK-LABEL: @fdiv_op1_constant_fneg_fmf(
146 ; CHECK-NEXT: [[R:%.*]] = fdiv nnan float [[X:%.*]], 4.200000e+01
147 ; CHECK-NEXT: ret float [[R]]
149 %d = fdiv float %x, -42.0
150 %r = fneg nnan float %d
154 ; Extra use prevents the fold. We don't want to replace the fneg with an fdiv.
156 define float @fdiv_op1_constant_fsub_extra_use(float %x) {
157 ; CHECK-LABEL: @fdiv_op1_constant_fsub_extra_use(
158 ; CHECK-NEXT: [[D:%.*]] = fdiv float [[X:%.*]], 4.200000e+01
159 ; CHECK-NEXT: [[R:%.*]] = fneg float [[D]]
160 ; CHECK-NEXT: call void @use(float [[D]])
161 ; CHECK-NEXT: ret float [[R]]
163 %d = fdiv float %x, 42.0
164 %r = fsub float -0.0, %d
165 call void @use(float %d)
169 define float @fdiv_op1_constant_fneg_extra_use(float %x) {
170 ; CHECK-LABEL: @fdiv_op1_constant_fneg_extra_use(
171 ; CHECK-NEXT: [[D:%.*]] = fdiv float [[X:%.*]], 4.200000e+01
172 ; CHECK-NEXT: [[R:%.*]] = fneg float [[D]]
173 ; CHECK-NEXT: call void @use(float [[D]])
174 ; CHECK-NEXT: ret float [[R]]
176 %d = fdiv float %x, 42.0
178 call void @use(float %d)
182 ; Try a vector. Use special constants (NaN, INF, undef) because they don't change anything.
184 define <4 x double> @fdiv_op1_constant_fsub_vec(<4 x double> %x) {
185 ; CHECK-LABEL: @fdiv_op1_constant_fsub_vec(
186 ; CHECK-NEXT: [[R:%.*]] = fdiv <4 x double> [[X:%.*]], <double 4.200000e+01, double 0x7FF800000ABCD000, double 0x7FF0000000000000, double undef>
187 ; CHECK-NEXT: ret <4 x double> [[R]]
189 %d = fdiv <4 x double> %x, <double -42.0, double 0xFFF800000ABCD000, double 0xFFF0000000000000, double undef>
190 %r = fsub <4 x double> <double -0.0, double -0.0, double -0.0, double -0.0>, %d
194 define <4 x double> @fdiv_op1_constant_fneg_vec(<4 x double> %x) {
195 ; CHECK-LABEL: @fdiv_op1_constant_fneg_vec(
196 ; CHECK-NEXT: [[R:%.*]] = fdiv <4 x double> [[X:%.*]], <double 4.200000e+01, double 0x7FF800000ABCD000, double 0x7FF0000000000000, double undef>
197 ; CHECK-NEXT: ret <4 x double> [[R]]
199 %d = fdiv <4 x double> %x, <double -42.0, double 0xFFF800000ABCD000, double 0xFFF0000000000000, double undef>
200 %r = fneg <4 x double> %d
204 ; -(C / X) --> (-C) / X
206 define float @fdiv_op0_constant_fsub(float %x) {
207 ; CHECK-LABEL: @fdiv_op0_constant_fsub(
208 ; CHECK-NEXT: [[R:%.*]] = fdiv float -4.200000e+01, [[X:%.*]]
209 ; CHECK-NEXT: ret float [[R]]
211 %d = fdiv float 42.0, %x
212 %r = fsub float -0.0, %d
216 define float @fdiv_op0_constant_fneg(float %x) {
217 ; CHECK-LABEL: @fdiv_op0_constant_fneg(
218 ; CHECK-NEXT: [[R:%.*]] = fdiv float -4.200000e+01, [[X:%.*]]
219 ; CHECK-NEXT: ret float [[R]]
221 %d = fdiv float 42.0, %x
226 ; Fast math is not required, but it should be propagated.
228 define float @fdiv_op0_constant_fneg_fast_fast(float %x) {
229 ; CHECK-LABEL: @fdiv_op0_constant_fneg_fast_fast(
230 ; CHECK-NEXT: [[R:%.*]] = fdiv fast float -4.200000e+01, [[X:%.*]]
231 ; CHECK-NEXT: ret float [[R]]
233 %d = fdiv fast float 42.0, %x
234 %r = fneg fast float %d
238 define float @fdiv_op0_constant_fneg_fast(float %x) {
239 ; CHECK-LABEL: @fdiv_op0_constant_fneg_fast(
240 ; CHECK-NEXT: [[R:%.*]] = fdiv reassoc nnan arcp contract afn float -4.200000e+01, [[X:%.*]]
241 ; CHECK-NEXT: ret float [[R]]
243 %d = fdiv float 42.0, %x
244 %r = fneg fast float %d
248 define float @fdiv_op0_constant_fneg_nsz_nsz(float %x) {
249 ; CHECK-LABEL: @fdiv_op0_constant_fneg_nsz_nsz(
250 ; CHECK-NEXT: [[R:%.*]] = fdiv nsz float -4.200000e+01, [[X:%.*]]
251 ; CHECK-NEXT: ret float [[R]]
253 %d = fdiv nsz float 42.0, %x
254 %r = fneg nsz float %d
258 define float @fdiv_op0_constant_fneg_nsz(float %x) {
259 ; CHECK-LABEL: @fdiv_op0_constant_fneg_nsz(
260 ; CHECK-NEXT: [[R:%.*]] = fdiv float -4.200000e+01, [[X:%.*]]
261 ; CHECK-NEXT: ret float [[R]]
263 %d = fdiv float 42.0, %x
264 %r = fneg nsz float %d
268 define float @fdiv_op0_constant_fneg_ninf_ninf(float %x) {
269 ; CHECK-LABEL: @fdiv_op0_constant_fneg_ninf_ninf(
270 ; CHECK-NEXT: [[R:%.*]] = fdiv ninf float -4.200000e+01, [[X:%.*]]
271 ; CHECK-NEXT: ret float [[R]]
273 %d = fdiv ninf float 42.0, %x
274 %r = fneg ninf float %d
278 define float @fdiv_op0_constant_fneg_ninf(float %x) {
279 ; CHECK-LABEL: @fdiv_op0_constant_fneg_ninf(
280 ; CHECK-NEXT: [[R:%.*]] = fdiv float -4.200000e+01, [[X:%.*]]
281 ; CHECK-NEXT: ret float [[R]]
283 %d = fdiv float 42.0, %x
284 %r = fneg ninf float %d
288 define float @fdiv_op0_constant_fneg_nnan_nnan(float %x) {
289 ; CHECK-LABEL: @fdiv_op0_constant_fneg_nnan_nnan(
290 ; CHECK-NEXT: [[R:%.*]] = fdiv nnan float -4.200000e+01, [[X:%.*]]
291 ; CHECK-NEXT: ret float [[R]]
293 %d = fdiv nnan float 42.0, %x
294 %r = fneg nnan float %d
298 define float @fdiv_op0_constant_fneg_nnan(float %x) {
299 ; CHECK-LABEL: @fdiv_op0_constant_fneg_nnan(
300 ; CHECK-NEXT: [[R:%.*]] = fdiv nnan float -4.200000e+01, [[X:%.*]]
301 ; CHECK-NEXT: ret float [[R]]
303 %d = fdiv float 42.0, %x
304 %r = fneg nnan float %d
308 ; Extra use prevents the fold. We don't want to replace the fneg with an fdiv.
310 define float @fdiv_op0_constant_fsub_extra_use(float %x) {
311 ; CHECK-LABEL: @fdiv_op0_constant_fsub_extra_use(
312 ; CHECK-NEXT: [[D:%.*]] = fdiv float -4.200000e+01, [[X:%.*]]
313 ; CHECK-NEXT: [[R:%.*]] = fneg float [[D]]
314 ; CHECK-NEXT: call void @use(float [[D]])
315 ; CHECK-NEXT: ret float [[R]]
317 %d = fdiv float -42.0, %x
318 %r = fsub float -0.0, %d
319 call void @use(float %d)
323 define float @fdiv_op0_constant_fneg_extra_use(float %x) {
324 ; CHECK-LABEL: @fdiv_op0_constant_fneg_extra_use(
325 ; CHECK-NEXT: [[D:%.*]] = fdiv float -4.200000e+01, [[X:%.*]]
326 ; CHECK-NEXT: [[R:%.*]] = fneg float [[D]]
327 ; CHECK-NEXT: call void @use(float [[D]])
328 ; CHECK-NEXT: ret float [[R]]
330 %d = fdiv float -42.0, %x
332 call void @use(float %d)
336 ; Try a vector. Use special constants (NaN, INF, undef) because they don't change anything.
338 define <4 x double> @fdiv_op0_constant_fsub_vec(<4 x double> %x) {
339 ; CHECK-LABEL: @fdiv_op0_constant_fsub_vec(
340 ; CHECK-NEXT: [[R:%.*]] = fdiv <4 x double> <double 4.200000e+01, double 0xFFF8000000000000, double 0x7FF0000000000000, double undef>, [[X:%.*]]
341 ; CHECK-NEXT: ret <4 x double> [[R]]
343 %d = fdiv <4 x double> <double -42.0, double 0x7FF8000000000000, double 0xFFF0000000000000, double undef>, %x
344 %r = fsub <4 x double> <double -0.0, double -0.0, double -0.0, double -0.0>, %d
348 define <4 x double> @fdiv_op0_constant_fneg_vec(<4 x double> %x) {
349 ; CHECK-LABEL: @fdiv_op0_constant_fneg_vec(
350 ; CHECK-NEXT: [[R:%.*]] = fdiv <4 x double> <double 4.200000e+01, double 0xFFF8000000000000, double 0x7FF0000000000000, double undef>, [[X:%.*]]
351 ; CHECK-NEXT: ret <4 x double> [[R]]
353 %d = fdiv <4 x double> <double -42.0, double 0x7FF8000000000000, double 0xFFF0000000000000, double undef>, %x
354 %r = fneg <4 x double> %d
358 ; Sink FP negation through a select:
359 ; c ? -x : -y --> -(c ? x : y)
361 define <2 x double> @fneg_fneg_sel(<2 x double> %x, <2 x double> %y, i1 %cond) {
362 ; CHECK-LABEL: @fneg_fneg_sel(
363 ; CHECK-NEXT: [[SEL_V:%.*]] = select i1 [[COND:%.*]], <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]
364 ; CHECK-NEXT: [[SEL:%.*]] = fneg <2 x double> [[SEL_V]]
365 ; CHECK-NEXT: ret <2 x double> [[SEL]]
367 %n1 = fneg <2 x double> %x
368 %n2 = fneg <2 x double> %y
369 %sel = select i1 %cond, <2 x double> %n1, <2 x double> %n2
370 ret <2 x double> %sel
373 ; An extra use is allowed.
375 define float @fneg_fneg_sel_extra_use1(float %x, float %y, i1 %cond) {
376 ; CHECK-LABEL: @fneg_fneg_sel_extra_use1(
377 ; CHECK-NEXT: [[N1:%.*]] = fneg float [[X:%.*]]
378 ; CHECK-NEXT: call void @use(float [[N1]])
379 ; CHECK-NEXT: [[SEL_V:%.*]] = select i1 [[COND:%.*]], float [[X]], float [[Y:%.*]]
380 ; CHECK-NEXT: [[SEL:%.*]] = fneg float [[SEL_V]]
381 ; CHECK-NEXT: ret float [[SEL]]
384 call void @use(float %n1)
386 %sel = select i1 %cond, float %n1, float %n2
390 define float @fneg_fneg_sel_extra_use2(float %x, float %y, i1 %cond) {
391 ; CHECK-LABEL: @fneg_fneg_sel_extra_use2(
392 ; CHECK-NEXT: [[N2:%.*]] = fneg float [[Y:%.*]]
393 ; CHECK-NEXT: call void @use(float [[N2]])
394 ; CHECK-NEXT: [[SEL_V:%.*]] = select i1 [[COND:%.*]], float [[X:%.*]], float [[Y]]
395 ; CHECK-NEXT: [[SEL:%.*]] = fneg float [[SEL_V]]
396 ; CHECK-NEXT: ret float [[SEL]]
400 call void @use(float %n2)
401 %sel = select i1 %cond, float %n1, float %n2
405 ; Legacy form of fneg should work too.
407 define float @fsub_fsub_sel_extra_use1(float %x, float %y, i1 %cond) {
408 ; CHECK-LABEL: @fsub_fsub_sel_extra_use1(
409 ; CHECK-NEXT: [[N1:%.*]] = fneg float [[X:%.*]]
410 ; CHECK-NEXT: call void @use(float [[N1]])
411 ; CHECK-NEXT: [[SEL_V:%.*]] = select i1 [[COND:%.*]], float [[X]], float [[Y:%.*]]
412 ; CHECK-NEXT: [[SEL:%.*]] = fneg float [[SEL_V]]
413 ; CHECK-NEXT: ret float [[SEL]]
415 %n1 = fsub float -0.0, %x
416 call void @use(float %n1)
417 %n2 = fsub float -0.0, %y
418 %sel = select i1 %cond, float %n1, float %n2
422 ; Negative test: but 2 extra uses would require an extra instruction.
424 define float @fneg_fneg_sel_extra_use3(float %x, float %y, i1 %cond) {
425 ; CHECK-LABEL: @fneg_fneg_sel_extra_use3(
426 ; CHECK-NEXT: [[N1:%.*]] = fneg float [[X:%.*]]
427 ; CHECK-NEXT: call void @use(float [[N1]])
428 ; CHECK-NEXT: [[N2:%.*]] = fneg float [[Y:%.*]]
429 ; CHECK-NEXT: call void @use(float [[N2]])
430 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float [[N1]], float [[N2]]
431 ; CHECK-NEXT: ret float [[SEL]]
434 call void @use(float %n1)
436 call void @use(float %n2)
437 %sel = select i1 %cond, float %n1, float %n2
441 define double @fneg_fneg_sel_fmf1(double %x, double %y, i1 %cond) {
442 ; CHECK-LABEL: @fneg_fneg_sel_fmf1(
443 ; CHECK-NEXT: [[SEL_V:%.*]] = select i1 [[COND:%.*]], double [[X:%.*]], double [[Y:%.*]]
444 ; CHECK-NEXT: [[SEL:%.*]] = fneg double [[SEL_V]]
445 ; CHECK-NEXT: ret double [[SEL]]
447 %n1 = fneg nnan double %x
448 %n2 = fneg ninf double %y
449 %sel = select i1 %cond, double %n1, double %n2
453 define double @fneg_fneg_sel_fmf2(double %x, double %y, i1 %cond) {
454 ; CHECK-LABEL: @fneg_fneg_sel_fmf2(
455 ; CHECK-NEXT: [[SEL_V:%.*]] = select ninf i1 [[COND:%.*]], double [[X:%.*]], double [[Y:%.*]]
456 ; CHECK-NEXT: [[SEL:%.*]] = fneg ninf double [[SEL_V]]
457 ; CHECK-NEXT: ret double [[SEL]]
459 %n1 = fneg nnan ninf double %x
460 %n2 = fneg ninf double %y
461 %sel = select i1 %cond, double %n1, double %n2
465 define double @fneg_fneg_sel_fmf3(double %x, double %y, i1 %cond) {
466 ; CHECK-LABEL: @fneg_fneg_sel_fmf3(
467 ; CHECK-NEXT: [[SEL_V:%.*]] = select ninf i1 [[COND:%.*]], double [[X:%.*]], double [[Y:%.*]]
468 ; CHECK-NEXT: [[SEL:%.*]] = fneg ninf double [[SEL_V]]
469 ; CHECK-NEXT: ret double [[SEL]]
471 %n1 = fneg nnan ninf double %x
472 %n2 = fneg ninf double %y
473 %sel = select ninf i1 %cond, double %n1, double %n2
477 define double @fneg_fneg_sel_fmf4(double %x, double %y, i1 %cond) {
478 ; CHECK-LABEL: @fneg_fneg_sel_fmf4(
479 ; CHECK-NEXT: [[SEL_V:%.*]] = select nnan ninf nsz i1 [[COND:%.*]], double [[X:%.*]], double [[Y:%.*]]
480 ; CHECK-NEXT: [[SEL:%.*]] = fneg nnan ninf nsz double [[SEL_V]]
481 ; CHECK-NEXT: ret double [[SEL]]
483 %n1 = fneg nnan double %x
484 %n2 = fneg ninf double %y
485 %sel = select nsz nnan ninf i1 %cond, double %n1, double %n2
491 define float @fneg_fadd_constant(float %x) {
492 ; CHECK-LABEL: @fneg_fadd_constant(
493 ; CHECK-NEXT: [[A:%.*]] = fadd float [[X:%.*]], 4.200000e+01
494 ; CHECK-NEXT: [[R:%.*]] = fneg float [[A]]
495 ; CHECK-NEXT: ret float [[R]]
497 %a = fadd float %x, 42.0
504 define float @fake_nsz_fadd_constant(float %x) {
505 ; CHECK-LABEL: @fake_nsz_fadd_constant(
506 ; CHECK-NEXT: [[A:%.*]] = fadd float [[X:%.*]], 4.200000e+01
507 ; CHECK-NEXT: [[R:%.*]] = fneg float [[A]]
508 ; CHECK-NEXT: ret float [[R]]
510 %a = fadd float %x, 42.0
511 %r = fsub float -0.0, %a
515 ; -(X + C) --> -C - X
517 define float @fneg_nsz_fadd_constant(float %x) {
518 ; CHECK-LABEL: @fneg_nsz_fadd_constant(
519 ; CHECK-NEXT: [[R:%.*]] = fsub nsz float -4.200000e+01, [[X:%.*]]
520 ; CHECK-NEXT: ret float [[R]]
522 %a = fadd float %x, 42.0
523 %r = fneg nsz float %a
527 ; -(X + C) --> -C - X
529 define float @fake_fneg_nsz_fadd_constant(float %x) {
530 ; CHECK-LABEL: @fake_fneg_nsz_fadd_constant(
531 ; CHECK-NEXT: [[R:%.*]] = fsub fast float -4.200000e+01, [[X:%.*]]
532 ; CHECK-NEXT: ret float [[R]]
534 %a = fadd float %x, 42.0
535 %r = fsub fast float -0.0, %a
541 define float @fneg_nsz_fadd_constant_extra_use(float %x) {
542 ; CHECK-LABEL: @fneg_nsz_fadd_constant_extra_use(
543 ; CHECK-NEXT: [[A:%.*]] = fadd float [[X:%.*]], 4.200000e+01
544 ; CHECK-NEXT: call void @use(float [[A]])
545 ; CHECK-NEXT: [[R:%.*]] = fneg nsz float [[A]]
546 ; CHECK-NEXT: ret float [[R]]
548 %a = fadd float %x, 42.0
549 call void @use(float %a)
550 %r = fneg nsz float %a
556 define float @fake_fneg_nsz_fadd_constant_extra_use(float %x) {
557 ; CHECK-LABEL: @fake_fneg_nsz_fadd_constant_extra_use(
558 ; CHECK-NEXT: [[A:%.*]] = fadd float [[X:%.*]], 4.200000e+01
559 ; CHECK-NEXT: call void @use(float [[A]])
560 ; CHECK-NEXT: [[R:%.*]] = fneg fast float [[A]]
561 ; CHECK-NEXT: ret float [[R]]
563 %a = fadd float %x, 42.0
564 call void @use(float %a)
565 %r = fsub fast float -0.0, %a
569 ; -(X + C) --> -C - X
571 define <2 x float> @fneg_nsz_fadd_constant_vec(<2 x float> %x) {
572 ; CHECK-LABEL: @fneg_nsz_fadd_constant_vec(
573 ; CHECK-NEXT: [[R:%.*]] = fsub reassoc nnan nsz <2 x float> <float -4.200000e+01, float -4.300000e+01>, [[X:%.*]]
574 ; CHECK-NEXT: ret <2 x float> [[R]]
576 %a = fadd <2 x float> %x, <float 42.0, float 43.0>
577 %r = fneg nsz nnan reassoc <2 x float> %a
581 ; -(X + C) --> -C - X
583 define <2 x float> @fake_fneg_nsz_fadd_constant_vec(<2 x float> %x) {
584 ; CHECK-LABEL: @fake_fneg_nsz_fadd_constant_vec(
585 ; CHECK-NEXT: [[R:%.*]] = fsub nsz <2 x float> <float -4.200000e+01, float undef>, [[X:%.*]]
586 ; CHECK-NEXT: ret <2 x float> [[R]]
588 %a = fadd <2 x float> %x, <float 42.0, float undef>
589 %r = fsub nsz <2 x float> <float undef, float -0.0>, %a
593 @g = external global i16, align 1
595 define float @fneg_nsz_fadd_constant_expr(float %x) {
596 ; CHECK-LABEL: @fneg_nsz_fadd_constant_expr(
597 ; CHECK-NEXT: [[R:%.*]] = fsub nsz float fneg (float bitcast (i32 ptrtoint (i16* @g to i32) to float)), [[X:%.*]]
598 ; CHECK-NEXT: ret float [[R]]
600 %a = fadd float %x, bitcast (i32 ptrtoint (i16* @g to i32) to float)
601 %r = fneg nsz float %a
605 define float @fake_fneg_nsz_fadd_constant_expr(float %x) {
606 ; CHECK-LABEL: @fake_fneg_nsz_fadd_constant_expr(
607 ; CHECK-NEXT: [[R:%.*]] = fsub nsz float fneg (float bitcast (i32 ptrtoint (i16* @g to i32) to float)), [[X:%.*]]
608 ; CHECK-NEXT: ret float [[R]]
610 %a = fadd float %x, bitcast (i32 ptrtoint (i16* @g to i32) to float)
611 %r = fsub nsz float -0.0, %a
615 define float @select_fneg_true(float %x, float %y, i1 %b) {
616 ; CHECK-LABEL: @select_fneg_true(
617 ; CHECK-NEXT: [[Y_NEG:%.*]] = fneg float [[Y:%.*]]
618 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], float [[X:%.*]], float [[Y_NEG]]
619 ; CHECK-NEXT: ret float [[R]]
622 %s = select i1 %b, float %nx, float %y
627 define <2 x float> @select_fneg_false(<2 x float> %x, <2 x float> %y, <2 x i1> %b) {
628 ; CHECK-LABEL: @select_fneg_false(
629 ; CHECK-NEXT: [[X_NEG:%.*]] = fneg nnan nsz <2 x float> [[X:%.*]]
630 ; CHECK-NEXT: [[R:%.*]] = select nnan <2 x i1> [[B:%.*]], <2 x float> [[X_NEG]], <2 x float> [[Y:%.*]]
631 ; CHECK-NEXT: ret <2 x float> [[R]]
633 %ny = fneg nnan <2 x float> %y
634 %s = select ninf <2 x i1> %b, <2 x float> %x, <2 x float> %ny
635 %r = fneg nsz nnan <2 x float> %s
639 define float @select_fneg_false_no_nsz(float %x, float %y, i1 %b) {
640 ; CHECK-LABEL: @select_fneg_false_no_nsz(
641 ; CHECK-NEXT: [[X_NEG:%.*]] = fneg nnan ninf nsz float [[X:%.*]]
642 ; CHECK-NEXT: [[R:%.*]] = select nnan ninf i1 [[B:%.*]], float [[X_NEG]], float [[Y:%.*]]
643 ; CHECK-NEXT: ret float [[R]]
646 %s = select i1 %b, float %x, float %ny
647 %r = fneg ninf nnan nsz float %s
651 define float @select_fneg_false_nsz(float %x, float %y, i1 %b) {
652 ; CHECK-LABEL: @select_fneg_false_nsz(
653 ; CHECK-NEXT: [[X_NEG:%.*]] = fneg nnan ninf nsz float [[X:%.*]]
654 ; CHECK-NEXT: [[R:%.*]] = select nnan ninf nsz i1 [[B:%.*]], float [[X_NEG]], float [[Y:%.*]]
655 ; CHECK-NEXT: ret float [[R]]
658 %s = select nsz i1 %b, float %x, float %ny
659 %r = fneg ninf nnan nsz float %s
663 define float @select_fneg_both(float %x, float %y, i1 %b) {
664 ; CHECK-LABEL: @select_fneg_both(
665 ; CHECK-NEXT: [[S_V:%.*]] = select i1 [[B:%.*]], float [[X:%.*]], float [[Y:%.*]]
666 ; CHECK-NEXT: ret float [[S_V]]
670 %s = select i1 %b, float %nx, float %ny
675 define float @select_fneg_use1(float %x, float %y, i1 %b) {
676 ; CHECK-LABEL: @select_fneg_use1(
677 ; CHECK-NEXT: [[NX:%.*]] = fneg ninf float [[X:%.*]]
678 ; CHECK-NEXT: call void @use(float [[NX]])
679 ; CHECK-NEXT: [[Y_NEG:%.*]] = fneg float [[Y:%.*]]
680 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], float [[X]], float [[Y_NEG]]
681 ; CHECK-NEXT: ret float [[R]]
683 %nx = fneg ninf float %x
684 call void @use(float %nx)
685 %s = select fast i1 %b, float %nx, float %y
690 define float @select_fneg_use2(float %x, float %y, i1 %b) {
691 ; CHECK-LABEL: @select_fneg_use2(
692 ; CHECK-NEXT: call void @use(float [[Y:%.*]])
693 ; CHECK-NEXT: [[Y_NEG:%.*]] = fneg fast float [[Y]]
694 ; CHECK-NEXT: [[R:%.*]] = select reassoc nnan ninf arcp contract afn i1 [[B:%.*]], float [[X:%.*]], float [[Y_NEG]]
695 ; CHECK-NEXT: ret float [[R]]
697 call void @use(float %y)
698 %nx = fneg nsz float %x
699 %s = select ninf i1 %b, float %nx, float %y
700 %r = fneg fast float %s
706 define float @select_fneg_use3(float %x, float %y, i1 %b) {
707 ; CHECK-LABEL: @select_fneg_use3(
708 ; CHECK-NEXT: [[NX:%.*]] = fneg float [[X:%.*]]
709 ; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], float [[NX]], float [[Y:%.*]]
710 ; CHECK-NEXT: call void @use(float [[S]])
711 ; CHECK-NEXT: [[R:%.*]] = fneg float [[S]]
712 ; CHECK-NEXT: ret float [[R]]
715 %s = select i1 %b, float %nx, float %y
716 call void @use(float %s)