1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 ; (-0.0 - X) * C => X * -C
5 define float @neg_constant(float %x) {
6 ; CHECK-LABEL: @neg_constant(
7 ; CHECK-NEXT: [[MUL:%.*]] = fmul ninf float [[X:%.*]], -2.000000e+01
8 ; CHECK-NEXT: ret float [[MUL]]
10 %sub = fsub float -0.0, %x
11 %mul = fmul ninf float %sub, 2.0e+1
15 define float @unary_neg_constant(float %x) {
16 ; CHECK-LABEL: @unary_neg_constant(
17 ; CHECK-NEXT: [[MUL:%.*]] = fmul ninf float [[X:%.*]], -2.000000e+01
18 ; CHECK-NEXT: ret float [[MUL]]
21 %mul = fmul ninf float %sub, 2.0e+1
25 define <2 x float> @neg_constant_vec(<2 x float> %x) {
26 ; CHECK-LABEL: @neg_constant_vec(
27 ; CHECK-NEXT: [[MUL:%.*]] = fmul ninf <2 x float> [[X:%.*]], <float -2.000000e+00, float -3.000000e+00>
28 ; CHECK-NEXT: ret <2 x float> [[MUL]]
30 %sub = fsub <2 x float> <float -0.0, float -0.0>, %x
31 %mul = fmul ninf <2 x float> %sub, <float 2.0, float 3.0>
35 define <2 x float> @unary_neg_constant_vec(<2 x float> %x) {
36 ; CHECK-LABEL: @unary_neg_constant_vec(
37 ; CHECK-NEXT: [[MUL:%.*]] = fmul ninf <2 x float> [[X:%.*]], <float -2.000000e+00, float -3.000000e+00>
38 ; CHECK-NEXT: ret <2 x float> [[MUL]]
40 %sub = fneg <2 x float> %x
41 %mul = fmul ninf <2 x float> %sub, <float 2.0, float 3.0>
45 define <2 x float> @neg_constant_vec_undef(<2 x float> %x) {
46 ; CHECK-LABEL: @neg_constant_vec_undef(
47 ; CHECK-NEXT: [[MUL:%.*]] = fmul ninf <2 x float> [[X:%.*]], <float -2.000000e+00, float -3.000000e+00>
48 ; CHECK-NEXT: ret <2 x float> [[MUL]]
50 %sub = fsub <2 x float> <float undef, float -0.0>, %x
51 %mul = fmul ninf <2 x float> %sub, <float 2.0, float 3.0>
55 ; (0.0 - X) * C => X * -C
56 define float @neg_nsz_constant(float %x) {
57 ; CHECK-LABEL: @neg_nsz_constant(
58 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan float [[X:%.*]], -2.000000e+01
59 ; CHECK-NEXT: ret float [[MUL]]
61 %sub = fsub nsz float 0.0, %x
62 %mul = fmul nnan float %sub, 2.0e+1
66 define float @unary_neg_nsz_constant(float %x) {
67 ; CHECK-LABEL: @unary_neg_nsz_constant(
68 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan float [[X:%.*]], -2.000000e+01
69 ; CHECK-NEXT: ret float [[MUL]]
71 %sub = fneg nsz float %x
72 %mul = fmul nnan float %sub, 2.0e+1
76 ; (-0.0 - X) * (-0.0 - Y) => X * Y
77 define float @neg_neg(float %x, float %y) {
78 ; CHECK-LABEL: @neg_neg(
79 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp float [[X:%.*]], [[Y:%.*]]
80 ; CHECK-NEXT: ret float [[MUL]]
82 %sub1 = fsub float -0.0, %x
83 %sub2 = fsub float -0.0, %y
84 %mul = fmul arcp float %sub1, %sub2
88 define float @unary_neg_unary_neg(float %x, float %y) {
89 ; CHECK-LABEL: @unary_neg_unary_neg(
90 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp float [[X:%.*]], [[Y:%.*]]
91 ; CHECK-NEXT: ret float [[MUL]]
95 %mul = fmul arcp float %sub1, %sub2
99 define float @unary_neg_neg(float %x, float %y) {
100 ; CHECK-LABEL: @unary_neg_neg(
101 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp float [[X:%.*]], [[Y:%.*]]
102 ; CHECK-NEXT: ret float [[MUL]]
104 %sub1 = fneg float %x
105 %sub2 = fsub float -0.0, %y
106 %mul = fmul arcp float %sub1, %sub2
110 define float @neg_unary_neg(float %x, float %y) {
111 ; CHECK-LABEL: @neg_unary_neg(
112 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp float [[X:%.*]], [[Y:%.*]]
113 ; CHECK-NEXT: ret float [[MUL]]
115 %sub1 = fsub float -0.0, %x
116 %sub2 = fneg float %y
117 %mul = fmul arcp float %sub1, %sub2
121 define <2 x float> @neg_neg_vec(<2 x float> %x, <2 x float> %y) {
122 ; CHECK-LABEL: @neg_neg_vec(
123 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
124 ; CHECK-NEXT: ret <2 x float> [[MUL]]
126 %sub1 = fsub <2 x float> <float -0.0, float -0.0>, %x
127 %sub2 = fsub <2 x float> <float -0.0, float -0.0>, %y
128 %mul = fmul arcp <2 x float> %sub1, %sub2
132 define <2 x float> @unary_neg_unary_neg_vec(<2 x float> %x, <2 x float> %y) {
133 ; CHECK-LABEL: @unary_neg_unary_neg_vec(
134 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
135 ; CHECK-NEXT: ret <2 x float> [[MUL]]
137 %sub1 = fneg <2 x float> %x
138 %sub2 = fneg <2 x float> %y
139 %mul = fmul arcp <2 x float> %sub1, %sub2
143 define <2 x float> @unary_neg_neg_vec(<2 x float> %x, <2 x float> %y) {
144 ; CHECK-LABEL: @unary_neg_neg_vec(
145 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
146 ; CHECK-NEXT: ret <2 x float> [[MUL]]
148 %sub1 = fneg <2 x float> %x
149 %sub2 = fsub <2 x float> <float -0.0, float -0.0>, %y
150 %mul = fmul arcp <2 x float> %sub1, %sub2
154 define <2 x float> @neg_unary_neg_vec(<2 x float> %x, <2 x float> %y) {
155 ; CHECK-LABEL: @neg_unary_neg_vec(
156 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
157 ; CHECK-NEXT: ret <2 x float> [[MUL]]
159 %sub1 = fsub <2 x float> <float -0.0, float -0.0>, %x
160 %sub2 = fneg <2 x float> %y
161 %mul = fmul arcp <2 x float> %sub1, %sub2
165 define <2 x float> @neg_neg_vec_undef(<2 x float> %x, <2 x float> %y) {
166 ; CHECK-LABEL: @neg_neg_vec_undef(
167 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
168 ; CHECK-NEXT: ret <2 x float> [[MUL]]
170 %sub1 = fsub <2 x float> <float -0.0, float undef>, %x
171 %sub2 = fsub <2 x float> <float undef, float -0.0>, %y
172 %mul = fmul arcp <2 x float> %sub1, %sub2
176 define <2 x float> @unary_neg_neg_vec_undef(<2 x float> %x, <2 x float> %y) {
177 ; CHECK-LABEL: @unary_neg_neg_vec_undef(
178 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
179 ; CHECK-NEXT: ret <2 x float> [[MUL]]
181 %neg = fneg <2 x float> %x
182 %sub = fsub <2 x float> <float undef, float -0.0>, %y
183 %mul = fmul arcp <2 x float> %neg, %sub
187 define <2 x float> @neg_unary_neg_vec_undef(<2 x float> %x, <2 x float> %y) {
188 ; CHECK-LABEL: @neg_unary_neg_vec_undef(
189 ; CHECK-NEXT: [[MUL:%.*]] = fmul arcp <2 x float> [[X:%.*]], [[Y:%.*]]
190 ; CHECK-NEXT: ret <2 x float> [[MUL]]
192 %sub = fsub <2 x float> <float -0.0, float undef>, %x
193 %neg = fneg <2 x float> %y
194 %mul = fmul arcp <2 x float> %sub, %neg
198 ; (0.0 - X) * (0.0 - Y) => X * Y
199 define float @neg_neg_nsz(float %x, float %y) {
200 ; CHECK-LABEL: @neg_neg_nsz(
201 ; CHECK-NEXT: [[MUL:%.*]] = fmul afn float [[X:%.*]], [[Y:%.*]]
202 ; CHECK-NEXT: ret float [[MUL]]
204 %sub1 = fsub nsz float 0.0, %x
205 %sub2 = fsub nsz float 0.0, %y
206 %mul = fmul afn float %sub1, %sub2
210 declare void @use_f32(float)
212 define float @neg_neg_multi_use(float %x, float %y) {
213 ; CHECK-LABEL: @neg_neg_multi_use(
214 ; CHECK-NEXT: [[NX:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
215 ; CHECK-NEXT: [[NY:%.*]] = fsub float -0.000000e+00, [[Y:%.*]]
216 ; CHECK-NEXT: [[MUL:%.*]] = fmul afn float [[X]], [[Y]]
217 ; CHECK-NEXT: call void @use_f32(float [[NX]])
218 ; CHECK-NEXT: call void @use_f32(float [[NY]])
219 ; CHECK-NEXT: ret float [[MUL]]
221 %nx = fsub float -0.0, %x
222 %ny = fsub float -0.0, %y
223 %mul = fmul afn float %nx, %ny
224 call void @use_f32(float %nx)
225 call void @use_f32(float %ny)
229 define float @unary_neg_unary_neg_multi_use(float %x, float %y) {
230 ; CHECK-LABEL: @unary_neg_unary_neg_multi_use(
231 ; CHECK-NEXT: [[NX:%.*]] = fneg float [[X:%.*]]
232 ; CHECK-NEXT: [[NY:%.*]] = fneg float [[Y:%.*]]
233 ; CHECK-NEXT: [[MUL:%.*]] = fmul afn float [[X]], [[Y]]
234 ; CHECK-NEXT: call void @use_f32(float [[NX]])
235 ; CHECK-NEXT: call void @use_f32(float [[NY]])
236 ; CHECK-NEXT: ret float [[MUL]]
240 %mul = fmul afn float %nx, %ny
241 call void @use_f32(float %nx)
242 call void @use_f32(float %ny)
246 define float @unary_neg_neg_multi_use(float %x, float %y) {
247 ; CHECK-LABEL: @unary_neg_neg_multi_use(
248 ; CHECK-NEXT: [[NX:%.*]] = fneg float [[X:%.*]]
249 ; CHECK-NEXT: [[NY:%.*]] = fsub float -0.000000e+00, [[Y:%.*]]
250 ; CHECK-NEXT: [[MUL:%.*]] = fmul afn float [[X]], [[Y]]
251 ; CHECK-NEXT: call void @use_f32(float [[NX]])
252 ; CHECK-NEXT: call void @use_f32(float [[NY]])
253 ; CHECK-NEXT: ret float [[MUL]]
256 %ny = fsub float -0.0, %y
257 %mul = fmul afn float %nx, %ny
258 call void @use_f32(float %nx)
259 call void @use_f32(float %ny)
263 define float @neg_unary_neg_multi_use(float %x, float %y) {
264 ; CHECK-LABEL: @neg_unary_neg_multi_use(
265 ; CHECK-NEXT: [[NX:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
266 ; CHECK-NEXT: [[NY:%.*]] = fneg float [[Y:%.*]]
267 ; CHECK-NEXT: [[MUL:%.*]] = fmul afn float [[X]], [[Y]]
268 ; CHECK-NEXT: call void @use_f32(float [[NX]])
269 ; CHECK-NEXT: call void @use_f32(float [[NY]])
270 ; CHECK-NEXT: ret float [[MUL]]
272 %nx = fsub float -0.0, %x
274 %mul = fmul afn float %nx, %ny
275 call void @use_f32(float %nx)
276 call void @use_f32(float %ny)
280 ; (-0.0 - X) * Y => -0.0 - (X * Y)
281 define float @neg_sink(float %x, float %y) {
282 ; CHECK-LABEL: @neg_sink(
283 ; CHECK-NEXT: [[TMP1:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
284 ; CHECK-NEXT: [[MUL:%.*]] = fsub float -0.000000e+00, [[TMP1]]
285 ; CHECK-NEXT: ret float [[MUL]]
287 %sub = fsub float -0.0, %x
288 %mul = fmul float %sub, %y
292 define float @unary_neg_sink(float %x, float %y) {
293 ; CHECK-LABEL: @unary_neg_sink(
294 ; CHECK-NEXT: [[TMP1:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
295 ; CHECK-NEXT: [[MUL:%.*]] = fsub float -0.000000e+00, [[TMP1]]
296 ; CHECK-NEXT: ret float [[MUL]]
299 %mul = fmul float %neg, %y
303 define <2 x float> @neg_sink_vec(<2 x float> %x, <2 x float> %y) {
304 ; CHECK-LABEL: @neg_sink_vec(
305 ; CHECK-NEXT: [[TMP1:%.*]] = fmul <2 x float> [[X:%.*]], [[Y:%.*]]
306 ; CHECK-NEXT: [[MUL:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
307 ; CHECK-NEXT: ret <2 x float> [[MUL]]
309 %sub = fsub <2 x float> <float -0.0, float -0.0>, %x
310 %mul = fmul <2 x float> %sub, %y
314 ; FIXME: Should generate a unary FNeg.
315 define <2 x float> @unary_neg_sink_vec(<2 x float> %x, <2 x float> %y) {
316 ; CHECK-LABEL: @unary_neg_sink_vec(
317 ; CHECK-NEXT: [[TMP1:%.*]] = fmul <2 x float> [[X:%.*]], [[Y:%.*]]
318 ; CHECK-NEXT: [[MUL:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
319 ; CHECK-NEXT: ret <2 x float> [[MUL]]
321 %sub = fneg <2 x float> %x
322 %mul = fmul <2 x float> %sub, %y
326 define <2 x float> @neg_sink_vec_undef(<2 x float> %x, <2 x float> %y) {
327 ; CHECK-LABEL: @neg_sink_vec_undef(
328 ; CHECK-NEXT: [[TMP1:%.*]] = fmul <2 x float> [[X:%.*]], [[Y:%.*]]
329 ; CHECK-NEXT: [[MUL:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
330 ; CHECK-NEXT: ret <2 x float> [[MUL]]
332 %sub = fsub <2 x float> <float undef, float -0.0>, %x
333 %mul = fmul <2 x float> %sub, %y
337 ; (0.0 - X) * Y => 0.0 - (X * Y)
338 define float @neg_sink_nsz(float %x, float %y) {
339 ; CHECK-LABEL: @neg_sink_nsz(
340 ; CHECK-NEXT: [[TMP1:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
341 ; CHECK-NEXT: [[MUL:%.*]] = fsub float -0.000000e+00, [[TMP1]]
342 ; CHECK-NEXT: ret float [[MUL]]
344 %sub1 = fsub nsz float 0.0, %x
345 %mul = fmul float %sub1, %y
349 ; "(-0.0 - X) * Y => -0.0 - (X * Y)" is disabled if expression "-0.0 - X"
351 define float @neg_sink_multi_use(float %x, float %y) {
352 ; CHECK-LABEL: @neg_sink_multi_use(
353 ; CHECK-NEXT: [[SUB1:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
354 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[SUB1]], [[Y:%.*]]
355 ; CHECK-NEXT: [[MUL2:%.*]] = fmul float [[MUL]], [[SUB1]]
356 ; CHECK-NEXT: ret float [[MUL2]]
358 %sub1 = fsub float -0.0, %x
359 %mul = fmul float %sub1, %y
360 %mul2 = fmul float %mul, %sub1
364 define float @unary_neg_sink_multi_use(float %x, float %y) {
365 ; CHECK-LABEL: @unary_neg_sink_multi_use(
366 ; CHECK-NEXT: [[SUB1:%.*]] = fneg float [[X:%.*]]
367 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[SUB1]], [[Y:%.*]]
368 ; CHECK-NEXT: [[MUL2:%.*]] = fmul float [[MUL]], [[SUB1]]
369 ; CHECK-NEXT: ret float [[MUL2]]
371 %sub1 = fneg float %x
372 %mul = fmul float %sub1, %y
373 %mul2 = fmul float %mul, %sub1
377 ; Don't crash when attempting to cast a constant FMul to an instruction.
378 define void @test8(i32* %inout) {
379 ; CHECK-LABEL: @test8(
381 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
383 ; CHECK-NEXT: [[LOCAL_VAR_7_0:%.*]] = phi <4 x float> [ <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, [[ENTRY:%.*]] ], [ [[TMP0:%.*]], [[FOR_BODY:%.*]] ]
384 ; CHECK-NEXT: br i1 undef, label [[FOR_BODY]], label [[FOR_END:%.*]]
386 ; CHECK-NEXT: [[TMP0]] = insertelement <4 x float> [[LOCAL_VAR_7_0]], float 0.000000e+00, i32 2
387 ; CHECK-NEXT: br label [[FOR_COND]]
389 ; CHECK-NEXT: ret void
392 %0 = load i32, i32* %inout, align 4
393 %conv = uitofp i32 %0 to float
394 %vecinit = insertelement <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float undef>, float %conv, i32 3
395 %sub = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %vecinit
396 %1 = shufflevector <4 x float> %sub, <4 x float> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
397 %mul = fmul <4 x float> zeroinitializer, %1
400 for.cond: ; preds = %for.body, %entry
401 %local_var_7.0 = phi <4 x float> [ %mul, %entry ], [ %2, %for.body ]
402 br i1 undef, label %for.body, label %for.end
404 for.body: ; preds = %for.cond
405 %2 = insertelement <4 x float> %local_var_7.0, float 0.000000e+00, i32 2
408 for.end: ; preds = %for.cond
412 ; X * -1.0 => -0.0 - X
413 define float @test9(float %x) {
414 ; CHECK-LABEL: @test9(
415 ; CHECK-NEXT: [[MUL:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
416 ; CHECK-NEXT: ret float [[MUL]]
418 %mul = fmul float %x, -1.0
423 define <4 x float> @test10(<4 x float> %x) {
424 ; CHECK-LABEL: @test10(
425 ; CHECK-NEXT: [[MUL:%.*]] = fsub arcp afn <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
426 ; CHECK-NEXT: ret <4 x float> [[MUL]]
428 %mul = fmul arcp afn <4 x float> %x, <float -1.0, float -1.0, float -1.0, float -1.0>
432 define float @test11(float %x, float %y) {
433 ; CHECK-LABEL: @test11(
434 ; CHECK-NEXT: [[B:%.*]] = fadd fast float [[X:%.*]], [[Y:%.*]]
435 ; CHECK-NEXT: [[C:%.*]] = fadd fast float [[B]], 3.000000e+00
436 ; CHECK-NEXT: ret float [[C]]
438 %a = fadd fast float %x, 1.0
439 %b = fadd fast float %y, 2.0
440 %c = fadd fast float %a, %b
444 declare double @llvm.sqrt.f64(double)
446 ; With unsafe/fast math, sqrt(X) * sqrt(X) is just X,
447 ; but make sure another use of the sqrt is intact.
448 ; Note that the remaining fmul is altered but is not 'fast'
449 ; itself because it was not marked 'fast' originally.
450 ; Thus, we have an overall fast result, but no more indication of
451 ; 'fast'ness in the code.
452 define double @sqrt_squared2(double %f) {
453 ; CHECK-LABEL: @sqrt_squared2(
454 ; CHECK-NEXT: [[SQRT:%.*]] = call double @llvm.sqrt.f64(double [[F:%.*]])
455 ; CHECK-NEXT: [[MUL2:%.*]] = fmul double [[SQRT]], [[F]]
456 ; CHECK-NEXT: ret double [[MUL2]]
458 %sqrt = call double @llvm.sqrt.f64(double %f)
459 %mul1 = fmul fast double %sqrt, %sqrt
460 %mul2 = fmul double %mul1, %sqrt
464 declare float @llvm.fabs.f32(float) nounwind readnone
466 define float @fabs_squared(float %x) {
467 ; CHECK-LABEL: @fabs_squared(
468 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X:%.*]], [[X]]
469 ; CHECK-NEXT: ret float [[MUL]]
471 %x.fabs = call float @llvm.fabs.f32(float %x)
472 %mul = fmul float %x.fabs, %x.fabs
476 define float @fabs_squared_fast(float %x) {
477 ; CHECK-LABEL: @fabs_squared_fast(
478 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[X:%.*]], [[X]]
479 ; CHECK-NEXT: ret float [[MUL]]
481 %x.fabs = call float @llvm.fabs.f32(float %x)
482 %mul = fmul fast float %x.fabs, %x.fabs
486 define float @fabs_x_fabs(float %x, float %y) {
487 ; CHECK-LABEL: @fabs_x_fabs(
488 ; CHECK-NEXT: [[X_FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
489 ; CHECK-NEXT: [[Y_FABS:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
490 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X_FABS]], [[Y_FABS]]
491 ; CHECK-NEXT: ret float [[MUL]]
493 %x.fabs = call float @llvm.fabs.f32(float %x)
494 %y.fabs = call float @llvm.fabs.f32(float %y)
495 %mul = fmul float %x.fabs, %y.fabs
499 ; (X*Y) * X => (X*X) * Y
500 ; The transform only requires 'reassoc', but test other FMF in
501 ; the commuted variants to make sure FMF propagates as expected.
503 define float @reassoc_common_operand1(float %x, float %y) {
504 ; CHECK-LABEL: @reassoc_common_operand1(
505 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[X:%.*]], [[X]]
506 ; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc float [[TMP1]], [[Y:%.*]]
507 ; CHECK-NEXT: ret float [[MUL2]]
509 %mul1 = fmul float %x, %y
510 %mul2 = fmul reassoc float %mul1, %x
514 ; (Y*X) * X => (X*X) * Y
516 define float @reassoc_common_operand2(float %x, float %y) {
517 ; CHECK-LABEL: @reassoc_common_operand2(
518 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], [[X]]
519 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
520 ; CHECK-NEXT: ret float [[MUL2]]
522 %mul1 = fmul float %y, %x
523 %mul2 = fmul fast float %mul1, %x
527 ; X * (X*Y) => (X*X) * Y
529 define float @reassoc_common_operand3(float %x1, float %y) {
530 ; CHECK-LABEL: @reassoc_common_operand3(
531 ; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
532 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc nnan float [[X]], [[X]]
533 ; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc nnan float [[TMP1]], [[Y:%.*]]
534 ; CHECK-NEXT: ret float [[MUL2]]
536 %x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
537 %mul1 = fmul float %x, %y
538 %mul2 = fmul reassoc nnan float %x, %mul1
542 ; X * (Y*X) => (X*X) * Y
544 define float @reassoc_common_operand4(float %x1, float %y) {
545 ; CHECK-LABEL: @reassoc_common_operand4(
546 ; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
547 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc ninf float [[X]], [[X]]
548 ; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc ninf float [[TMP1]], [[Y:%.*]]
549 ; CHECK-NEXT: ret float [[MUL2]]
551 %x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
552 %mul1 = fmul float %y, %x
553 %mul2 = fmul reassoc ninf float %x, %mul1
557 ; No change if the first fmul has another use.
559 define float @reassoc_common_operand_multi_use(float %x, float %y) {
560 ; CHECK-LABEL: @reassoc_common_operand_multi_use(
561 ; CHECK-NEXT: [[MUL1:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
562 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[MUL1]], [[X]]
563 ; CHECK-NEXT: call void @use_f32(float [[MUL1]])
564 ; CHECK-NEXT: ret float [[MUL2]]
566 %mul1 = fmul float %x, %y
567 %mul2 = fmul fast float %mul1, %x
568 call void @use_f32(float %mul1)
572 declare float @llvm.log2.f32(float)
574 ; log2(Y * 0.5) * X = log2(Y) * X - X
576 define float @log2half(float %x, float %y) {
577 ; CHECK-LABEL: @log2half(
578 ; CHECK-NEXT: [[LOG2:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
579 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[LOG2]], [[X:%.*]]
580 ; CHECK-NEXT: [[MUL:%.*]] = fsub fast float [[TMP1]], [[X]]
581 ; CHECK-NEXT: ret float [[MUL]]
583 %halfy = fmul float %y, 0.5
584 %log2 = call float @llvm.log2.f32(float %halfy)
585 %mul = fmul fast float %log2, %x
589 define float @log2half_commute(float %x1, float %y) {
590 ; CHECK-LABEL: @log2half_commute(
591 ; CHECK-NEXT: [[LOG2:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
592 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[LOG2]], [[X1:%.*]]
593 ; CHECK-NEXT: [[TMP2:%.*]] = fsub fast float [[TMP1]], [[X1]]
594 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[TMP2]], 0x3FC24924A0000000
595 ; CHECK-NEXT: ret float [[MUL]]
597 %x = fdiv float %x1, 7.0 ; thwart complexity-based canonicalization
598 %halfy = fmul float %y, 0.5
599 %log2 = call float @llvm.log2.f32(float %halfy)
600 %mul = fmul fast float %x, %log2
604 ; C1/X * C2 => (C1*C2) / X
606 define float @fdiv_constant_numerator_fmul(float %x) {
607 ; CHECK-LABEL: @fdiv_constant_numerator_fmul(
608 ; CHECK-NEXT: [[T3:%.*]] = fdiv reassoc float 1.200000e+07, [[X:%.*]]
609 ; CHECK-NEXT: ret float [[T3]]
611 %t1 = fdiv float 2.0e+3, %x
612 %t3 = fmul reassoc float %t1, 6.0e+3
616 ; C1/X * C2 => (C1*C2) / X is disabled if C1/X has multiple uses
618 @fmul2_external = external global float
620 define float @fdiv_constant_numerator_fmul_extra_use(float %x) {
621 ; CHECK-LABEL: @fdiv_constant_numerator_fmul_extra_use(
622 ; CHECK-NEXT: [[DIV:%.*]] = fdiv fast float 1.000000e+00, [[X:%.*]]
623 ; CHECK-NEXT: store float [[DIV]], float* @fmul2_external, align 4
624 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[DIV]], 2.000000e+00
625 ; CHECK-NEXT: ret float [[MUL]]
627 %div = fdiv fast float 1.0, %x
628 store float %div, float* @fmul2_external
629 %mul = fmul fast float %div, 2.0
633 ; X/C1 * C2 => X * (C2/C1) (if C2/C1 is normal FP)
635 define float @fdiv_constant_denominator_fmul(float %x) {
636 ; CHECK-LABEL: @fdiv_constant_denominator_fmul(
637 ; CHECK-NEXT: [[T3:%.*]] = fmul reassoc float [[X:%.*]], 3.000000e+00
638 ; CHECK-NEXT: ret float [[T3]]
640 %t1 = fdiv float %x, 2.0e+3
641 %t3 = fmul reassoc float %t1, 6.0e+3
645 define <4 x float> @fdiv_constant_denominator_fmul_vec(<4 x float> %x) {
646 ; CHECK-LABEL: @fdiv_constant_denominator_fmul_vec(
647 ; CHECK-NEXT: [[T3:%.*]] = fmul reassoc <4 x float> [[X:%.*]], <float 3.000000e+00, float 2.000000e+00, float 1.000000e+00, float 1.000000e+00>
648 ; CHECK-NEXT: ret <4 x float> [[T3]]
650 %t1 = fdiv <4 x float> %x, <float 2.0e+3, float 3.0e+3, float 2.0e+3, float 1.0e+3>
651 %t3 = fmul reassoc <4 x float> %t1, <float 6.0e+3, float 6.0e+3, float 2.0e+3, float 1.0e+3>
655 ; Make sure fmul with constant expression doesn't assert.
657 define <4 x float> @fdiv_constant_denominator_fmul_vec_constexpr(<4 x float> %x) {
658 ; CHECK-LABEL: @fdiv_constant_denominator_fmul_vec_constexpr(
659 ; CHECK-NEXT: [[T3:%.*]] = fmul reassoc <4 x float> [[X:%.*]], <float 3.000000e+00, float 2.000000e+00, float 1.000000e+00, float 1.000000e+00>
660 ; CHECK-NEXT: ret <4 x float> [[T3]]
662 %constExprMul = bitcast i128 trunc (i160 bitcast (<5 x float> <float 6.0e+3, float 6.0e+3, float 2.0e+3, float 1.0e+3, float undef> to i160) to i128) to <4 x float>
663 %t1 = fdiv <4 x float> %x, <float 2.0e+3, float 3.0e+3, float 2.0e+3, float 1.0e+3>
664 %t3 = fmul reassoc <4 x float> %t1, %constExprMul
668 ; This shows that at least part of instcombine does not check constant
669 ; values to see if it is creating denorms (0x3800000000000000 is a denorm
670 ; for 32-bit float), so protecting against denorms in other parts is
671 ; probably not doing the intended job.
673 define float @fmul_constant_reassociation(float %x) {
674 ; CHECK-LABEL: @fmul_constant_reassociation(
675 ; CHECK-NEXT: [[R:%.*]] = fmul reassoc nsz float [[X:%.*]], 0x3800000000000000
676 ; CHECK-NEXT: ret float [[R]]
678 %mul_flt_min = fmul reassoc nsz float %x, 0x3810000000000000
679 %r = fmul reassoc nsz float %mul_flt_min, 0.5
683 ; Canonicalization "X/C1 * C2 => X * (C2/C1)" still applies if C2/C1 is denormal
684 ; (otherwise, we should not have allowed the reassociation in the previous test).
685 ; 0x3810000000000000 == FLT_MIN
687 define float @fdiv_constant_denominator_fmul_denorm(float %x) {
688 ; CHECK-LABEL: @fdiv_constant_denominator_fmul_denorm(
689 ; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[X:%.*]], 0x3760620000000000
690 ; CHECK-NEXT: ret float [[T3]]
692 %t1 = fdiv float %x, 2.0e+3
693 %t3 = fmul fast float %t1, 0x3810000000000000
697 ; X / C1 * C2 => X / (C2/C1) if C1/C2 is abnormal, but C2/C1 is a normal value.
698 ; TODO: We don't convert the fast fdiv to fmul because that would be multiplication
699 ; by a denormal, but we could do better when we know that denormals are not a problem.
701 define float @fdiv_constant_denominator_fmul_denorm_try_harder(float %x) {
702 ; CHECK-LABEL: @fdiv_constant_denominator_fmul_denorm_try_harder(
703 ; CHECK-NEXT: [[T3:%.*]] = fdiv reassoc float [[X:%.*]], 0x47E8000000000000
704 ; CHECK-NEXT: ret float [[T3]]
706 %t1 = fdiv float %x, 3.0
707 %t3 = fmul reassoc float %t1, 0x3810000000000000
711 ; Negative test: we should not have 2 divisions instead of the 1 we started with.
713 define float @fdiv_constant_denominator_fmul_denorm_try_harder_extra_use(float %x) {
714 ; CHECK-LABEL: @fdiv_constant_denominator_fmul_denorm_try_harder_extra_use(
715 ; CHECK-NEXT: [[T1:%.*]] = fdiv float [[X:%.*]], 3.000000e+00
716 ; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[T1]], 0x3810000000000000
717 ; CHECK-NEXT: [[R:%.*]] = fadd float [[T1]], [[T3]]
718 ; CHECK-NEXT: ret float [[R]]
720 %t1 = fdiv float %x, 3.0e+0
721 %t3 = fmul fast float %t1, 0x3810000000000000
722 %r = fadd float %t1, %t3
726 ; (X + C1) * C2 --> (X * C2) + C1*C2
728 define float @fmul_fadd_distribute(float %x) {
729 ; CHECK-LABEL: @fmul_fadd_distribute(
730 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[X:%.*]], 3.000000e+00
731 ; CHECK-NEXT: [[T3:%.*]] = fadd reassoc float [[TMP1]], 6.000000e+00
732 ; CHECK-NEXT: ret float [[T3]]
734 %t2 = fadd float %x, 2.0
735 %t3 = fmul reassoc float %t2, 3.0
739 ; (X - C1) * C2 --> (X * C2) - C1*C2
741 define float @fmul_fsub_distribute1(float %x) {
742 ; CHECK-LABEL: @fmul_fsub_distribute1(
743 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[X:%.*]], 3.000000e+00
744 ; CHECK-NEXT: [[T3:%.*]] = fadd reassoc float [[TMP1]], -6.000000e+00
745 ; CHECK-NEXT: ret float [[T3]]
747 %t2 = fsub float %x, 2.0
748 %t3 = fmul reassoc float %t2, 3.0
752 ; (C1 - X) * C2 --> C1*C2 - (X * C2)
754 define float @fmul_fsub_distribute2(float %x) {
755 ; CHECK-LABEL: @fmul_fsub_distribute2(
756 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[X:%.*]], 3.000000e+00
757 ; CHECK-NEXT: [[T3:%.*]] = fsub reassoc float 6.000000e+00, [[TMP1]]
758 ; CHECK-NEXT: ret float [[T3]]
760 %t2 = fsub float 2.0, %x
761 %t3 = fmul reassoc float %t2, 3.0
765 ; FIXME: This should only need 'reassoc'.
766 ; ((X*C1) + C2) * C3 => (X * (C1*C3)) + (C2*C3)
768 define float @fmul_fadd_fmul_distribute(float %x) {
769 ; CHECK-LABEL: @fmul_fadd_fmul_distribute(
770 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], 3.000000e+01
771 ; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[TMP1]], 1.000000e+01
772 ; CHECK-NEXT: ret float [[T3]]
774 %t1 = fmul float %x, 6.0
775 %t2 = fadd float %t1, 2.0
776 %t3 = fmul fast float %t2, 5.0
780 define float @fmul_fadd_distribute_extra_use(float %x) {
781 ; CHECK-LABEL: @fmul_fadd_distribute_extra_use(
782 ; CHECK-NEXT: [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
783 ; CHECK-NEXT: [[T2:%.*]] = fadd float [[T1]], 2.000000e+00
784 ; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
785 ; CHECK-NEXT: call void @use_f32(float [[T2]])
786 ; CHECK-NEXT: ret float [[T3]]
788 %t1 = fmul float %x, 6.0
789 %t2 = fadd float %t1, 2.0
790 %t3 = fmul fast float %t2, 5.0
791 call void @use_f32(float %t2)
795 ; (X/C1 + C2) * C3 => X/(C1/C3) + C2*C3
796 ; 0x10000000000000 = DBL_MIN
797 ; TODO: We don't convert the fast fdiv to fmul because that would be multiplication
798 ; by a denormal, but we could do better when we know that denormals are not a problem.
800 define double @fmul_fadd_fdiv_distribute2(double %x) {
801 ; CHECK-LABEL: @fmul_fadd_fdiv_distribute2(
802 ; CHECK-NEXT: [[TMP1:%.*]] = fdiv reassoc double [[X:%.*]], 0x7FE8000000000000
803 ; CHECK-NEXT: [[T3:%.*]] = fadd reassoc double [[TMP1]], 0x34000000000000
804 ; CHECK-NEXT: ret double [[T3]]
806 %t1 = fdiv double %x, 3.0
807 %t2 = fadd double %t1, 5.0
808 %t3 = fmul reassoc double %t2, 0x10000000000000
812 ; 5.0e-1 * DBL_MIN yields denormal, so "(f1*3.0 + 5.0e-1) * DBL_MIN" cannot
813 ; be simplified into f1 * (3.0*DBL_MIN) + (5.0e-1*DBL_MIN)
815 define double @fmul_fadd_fdiv_distribute3(double %x) {
816 ; CHECK-LABEL: @fmul_fadd_fdiv_distribute3(
817 ; CHECK-NEXT: [[TMP1:%.*]] = fdiv reassoc double [[X:%.*]], 0x7FE8000000000000
818 ; CHECK-NEXT: [[T3:%.*]] = fadd reassoc double [[TMP1]], 0x34000000000000
819 ; CHECK-NEXT: ret double [[T3]]
821 %t1 = fdiv double %x, 3.0
822 %t2 = fadd double %t1, 5.0
823 %t3 = fmul reassoc double %t2, 0x10000000000000
827 ; FIXME: This should only need 'reassoc'.
828 ; (C2 - (X*C1)) * C3 => (C2*C3) - (X * (C1*C3))
830 define float @fmul_fsub_fmul_distribute(float %x) {
831 ; CHECK-LABEL: @fmul_fsub_fmul_distribute(
832 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], 3.000000e+01
833 ; CHECK-NEXT: [[T3:%.*]] = fsub fast float 1.000000e+01, [[TMP1]]
834 ; CHECK-NEXT: ret float [[T3]]
836 %t1 = fmul float %x, 6.0
837 %t2 = fsub float 2.0, %t1
838 %t3 = fmul fast float %t2, 5.0
842 define float @fmul_fsub_fmul_distribute_extra_use(float %x) {
843 ; CHECK-LABEL: @fmul_fsub_fmul_distribute_extra_use(
844 ; CHECK-NEXT: [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
845 ; CHECK-NEXT: [[T2:%.*]] = fsub float 2.000000e+00, [[T1]]
846 ; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
847 ; CHECK-NEXT: call void @use_f32(float [[T2]])
848 ; CHECK-NEXT: ret float [[T3]]
850 %t1 = fmul float %x, 6.0
851 %t2 = fsub float 2.0, %t1
852 %t3 = fmul fast float %t2, 5.0
853 call void @use_f32(float %t2)
857 ; FIXME: This should only need 'reassoc'.
858 ; ((X*C1) - C2) * C3 => (X * (C1*C3)) - C2*C3
860 define float @fmul_fsub_fmul_distribute2(float %x) {
861 ; CHECK-LABEL: @fmul_fsub_fmul_distribute2(
862 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], 3.000000e+01
863 ; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[TMP1]], -1.000000e+01
864 ; CHECK-NEXT: ret float [[T3]]
866 %t1 = fmul float %x, 6.0
867 %t2 = fsub float %t1, 2.0
868 %t3 = fmul fast float %t2, 5.0
872 define float @fmul_fsub_fmul_distribute2_extra_use(float %x) {
873 ; CHECK-LABEL: @fmul_fsub_fmul_distribute2_extra_use(
874 ; CHECK-NEXT: [[T1:%.*]] = fmul float [[X:%.*]], 6.000000e+00
875 ; CHECK-NEXT: [[T2:%.*]] = fsub float 2.000000e+00, [[T1]]
876 ; CHECK-NEXT: [[T3:%.*]] = fmul fast float [[T2]], 5.000000e+00
877 ; CHECK-NEXT: call void @use_f32(float [[T2]])
878 ; CHECK-NEXT: ret float [[T3]]
880 %t1 = fmul float %x, 6.0
881 %t2 = fsub float 2.0, %t1
882 %t3 = fmul fast float %t2, 5.0
883 call void @use_f32(float %t2)
887 ; "(X*Y) * X => (X*X) * Y" is disabled if "X*Y" has multiple uses
889 define float @common_factor(float %x, float %y) {
890 ; CHECK-LABEL: @common_factor(
891 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
892 ; CHECK-NEXT: [[MUL1:%.*]] = fmul fast float [[MUL]], [[X]]
893 ; CHECK-NEXT: [[ADD:%.*]] = fadd float [[MUL1]], [[MUL]]
894 ; CHECK-NEXT: ret float [[ADD]]
896 %mul = fmul float %x, %y
897 %mul1 = fmul fast float %mul, %x
898 %add = fadd float %mul1, %mul
902 define double @fmul_fdiv_factor_squared(double %x, double %y) {
903 ; CHECK-LABEL: @fmul_fdiv_factor_squared(
904 ; CHECK-NEXT: [[DIV:%.*]] = fdiv fast double [[X:%.*]], [[Y:%.*]]
905 ; CHECK-NEXT: [[SQUARED:%.*]] = fmul fast double [[DIV]], [[DIV]]
906 ; CHECK-NEXT: ret double [[SQUARED]]
908 %div = fdiv fast double %x, %y
909 %squared = fmul fast double %div, %div
913 define double @fmul_fdivs_factor_common_denominator(double %x, double %y, double %z) {
914 ; CHECK-LABEL: @fmul_fdivs_factor_common_denominator(
915 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast double [[Y:%.*]], [[X:%.*]]
916 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast double [[Z:%.*]], [[Z]]
917 ; CHECK-NEXT: [[MUL:%.*]] = fdiv fast double [[TMP1]], [[TMP2]]
918 ; CHECK-NEXT: ret double [[MUL]]
920 %div1 = fdiv double %x, %z
921 %div2 = fdiv double %y, %z
922 %mul = fmul fast double %div1, %div2
926 define double @fmul_fdivs_factor(double %x, double %y, double %z, double %w) {
927 ; CHECK-LABEL: @fmul_fdivs_factor(
928 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc double [[Z:%.*]], [[X:%.*]]
929 ; CHECK-NEXT: [[TMP2:%.*]] = fdiv reassoc double [[TMP1]], [[W:%.*]]
930 ; CHECK-NEXT: [[MUL:%.*]] = fdiv reassoc double [[TMP2]], [[Y:%.*]]
931 ; CHECK-NEXT: ret double [[MUL]]
933 %div1 = fdiv double %x, %y
934 %div2 = fdiv double %z, %w
935 %mul = fmul reassoc double %div1, %div2
939 define double @fmul_fdiv_factor(double %x, double %y, double %z) {
940 ; CHECK-LABEL: @fmul_fdiv_factor(
941 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc double [[X:%.*]], [[Z:%.*]]
942 ; CHECK-NEXT: [[MUL:%.*]] = fdiv reassoc double [[TMP1]], [[Y:%.*]]
943 ; CHECK-NEXT: ret double [[MUL]]
945 %div = fdiv double %x, %y
946 %mul = fmul reassoc double %div, %z
950 define double @fmul_fdiv_factor_constant1(double %x, double %y) {
951 ; CHECK-LABEL: @fmul_fdiv_factor_constant1(
952 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc double [[X:%.*]], 4.200000e+01
953 ; CHECK-NEXT: [[MUL:%.*]] = fdiv reassoc double [[TMP1]], [[Y:%.*]]
954 ; CHECK-NEXT: ret double [[MUL]]
956 %div = fdiv double %x, %y
957 %mul = fmul reassoc double %div, 42.0
961 define <2 x float> @fmul_fdiv_factor_constant2(<2 x float> %x, <2 x float> %y) {
962 ; CHECK-LABEL: @fmul_fdiv_factor_constant2(
963 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc <2 x float> [[X:%.*]], [[Y:%.*]]
964 ; CHECK-NEXT: [[MUL:%.*]] = fdiv reassoc <2 x float> [[TMP1]], <float 4.200000e+01, float 1.200000e+01>
965 ; CHECK-NEXT: ret <2 x float> [[MUL]]
967 %div = fdiv <2 x float> %x, <float 42.0, float 12.0>
968 %mul = fmul reassoc <2 x float> %div, %y
972 define float @fmul_fdiv_factor_extra_use(float %x, float %y) {
973 ; CHECK-LABEL: @fmul_fdiv_factor_extra_use(
974 ; CHECK-NEXT: [[DIV:%.*]] = fdiv float [[X:%.*]], 4.200000e+01
975 ; CHECK-NEXT: call void @use_f32(float [[DIV]])
976 ; CHECK-NEXT: [[MUL:%.*]] = fmul reassoc float [[DIV]], [[Y:%.*]]
977 ; CHECK-NEXT: ret float [[MUL]]
979 %div = fdiv float %x, 42.0
980 call void @use_f32(float %div)
981 %mul = fmul reassoc float %div, %y
985 ; Avoid infinite looping by moving negation out of a constant expression.
987 @g = external global {[2 x i8*]}, align 1
989 define double @fmul_negated_constant_expression(double %x) {
990 ; CHECK-LABEL: @fmul_negated_constant_expression(
991 ; CHECK-NEXT: [[R:%.*]] = fmul double [[X:%.*]], fsub (double -0.000000e+00, double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double))
992 ; CHECK-NEXT: ret double [[R]]
994 %r = fmul double %x, fsub (double -0.000000e+00, double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double))