rdar://12753946
[oota-llvm.git] / test / Transforms / InstCombine / fast-math.ll
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2
3 ; testing-case "float fold(float a) { return 1.2f * a * 2.3f; }"
4 ; 1.2f and 2.3f is supposed to be fold.
5 define float @fold(float %a) {
6   %mul = fmul fast float %a, 0x3FF3333340000000
7   %mul1 = fmul fast float %mul, 0x4002666660000000
8   ret float %mul1
9 ; CHECK: @fold
10 ; CHECK: fmul float %a, 0x4006147AE0000000
11 }
12
13 ; Same testing-case as the one used in fold() except that the operators have
14 ; fixed FP mode.
15 define float @notfold(float %a) {
16 ; CHECK: @notfold
17 ; CHECK: %mul = fmul fast float %a, 0x3FF3333340000000
18   %mul = fmul fast float %a, 0x3FF3333340000000
19   %mul1 = fmul float %mul, 0x4002666660000000
20   ret float %mul1
21 }
22
23 define float @fold2(float %a) {
24 ; CHECK: @fold2
25 ; CHECK: fmul float %a, 0x4006147AE0000000
26   %mul = fmul float %a, 0x3FF3333340000000
27   %mul1 = fmul fast float %mul, 0x4002666660000000
28   ret float %mul1
29 }
30
31 ; rdar://12753946:  x * cond ? 1.0 : 0.0 => cond ? x : 0.0
32 define double @select1(i32 %cond, double %x, double %y) {
33   %tobool = icmp ne i32 %cond, 0
34   %cond1 = select i1 %tobool, double 1.000000e+00, double 0.000000e+00
35   %mul = fmul nnan nsz double %cond1, %x
36   %add = fadd double %mul, %y
37   ret double %add
38 ; CHECK: @select1
39 ; CHECK: select i1 %tobool, double %x, double 0.000000e+00
40 }
41
42 define double @select2(i32 %cond, double %x, double %y) {
43   %tobool = icmp ne i32 %cond, 0
44   %cond1 = select i1 %tobool, double 0.000000e+00, double 1.000000e+00
45   %mul = fmul nnan nsz double %cond1, %x
46   %add = fadd double %mul, %y
47   ret double %add
48 ; CHECK: @select2
49 ; CHECK: select i1 %tobool, double 0.000000e+00, double %x
50 }
51
52 define double @select3(i32 %cond, double %x, double %y) {
53   %tobool = icmp ne i32 %cond, 0
54   %cond1 = select i1 %tobool, double 0.000000e+00, double 2.000000e+00
55   %mul = fmul nnan nsz double %cond1, %x
56   %add = fadd double %mul, %y
57   ret double %add
58 ; CHECK: @select3
59 ; CHECK: fmul nnan nsz double %cond1, %x
60 }