1; RUN: opt -instsimplify -S < %s | FileCheck %s
2
3; Fixes PR20832
4; Make sure that we correctly fold a fused multiply-add where operands
5; are all finite constants and addend is zero.
6
7declare double @llvm.fma.f64(double, double, double)
8
9
10define double @PR20832()  {
11  %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0.0)
12  ret double %1
13}
14; CHECK-LABEL: @PR20832(
15; CHECK: ret double 5.600000e+01
16
17; Test builtin fma with all finite non-zero constants.
18define double @test_all_finite()  {
19  %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 5.0)
20  ret double %1
21}
22; CHECK-LABEL: @test_all_finite(
23; CHECK: ret double 6.100000e+01
24
25; Test builtin fma with a +/-NaN addend.
26define double @test_NaN_addend()  {
27  %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0x7FF8000000000000)
28  ret double %1
29}
30; CHECK-LABEL: @test_NaN_addend(
31; CHECK: ret double 0x7FF8000000000000
32
33define double @test_NaN_addend_2()  {
34  %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0xFFF8000000000000)
35  ret double %1
36}
37; CHECK-LABEL: @test_NaN_addend_2(
38; CHECK: ret double 0xFFF8000000000000
39
40; Test builtin fma with a +/-Inf addend.
41define double @test_Inf_addend()  {
42  %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0x7FF0000000000000)
43  ret double %1
44}
45; CHECK-LABEL: @test_Inf_addend(
46; CHECK: ret double 0x7FF0000000000000
47
48define double @test_Inf_addend_2()  {
49  %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0xFFF0000000000000)
50  ret double %1
51}
52; CHECK-LABEL: @test_Inf_addend_2(
53; CHECK: ret double 0xFFF0000000000000
54
55; Test builtin fma with one of the operands to the multiply being +/-NaN.
56define double @test_NaN_1()  {
57  %1 = call double @llvm.fma.f64(double 0x7FF8000000000000, double 8.0, double 0.0)
58  ret double %1
59}
60; CHECK-LABEL: @test_NaN_1(
61; CHECK: ret double 0x7FF8000000000000
62
63
64define double @test_NaN_2()  {
65  %1 = call double @llvm.fma.f64(double 7.0, double 0x7FF8000000000000, double 0.0)
66  ret double %1
67}
68; CHECK-LABEL: @test_NaN_2(
69; CHECK: ret double 0x7FF8000000000000
70
71
72define double @test_NaN_3()  {
73  %1 = call double @llvm.fma.f64(double 0xFFF8000000000000, double 8.0, double 0.0)
74  ret double %1
75}
76; CHECK-LABEL: @test_NaN_3(
77; CHECK: ret double 0x7FF8000000000000
78
79
80define double @test_NaN_4()  {
81  %1 = call double @llvm.fma.f64(double 7.0, double 0xFFF8000000000000, double 0.0)
82  ret double %1
83}
84; CHECK-LABEL: @test_NaN_4(
85; CHECK: ret double 0x7FF8000000000000
86
87
88; Test builtin fma with one of the operands to the multiply being +/-Inf.
89define double @test_Inf_1()  {
90  %1 = call double @llvm.fma.f64(double 0x7FF0000000000000, double 8.0, double 0.0)
91  ret double %1
92}
93; CHECK-LABEL: @test_Inf_1(
94; CHECK: ret double 0x7FF0000000000000
95
96
97define double @test_Inf_2()  {
98  %1 = call double @llvm.fma.f64(double 7.0, double 0x7FF0000000000000, double 0.0)
99  ret double %1
100}
101; CHECK-LABEL: @test_Inf_2(
102; CHECK: ret double 0x7FF0000000000000
103
104
105define double @test_Inf_3()  {
106  %1 = call double @llvm.fma.f64(double 0xFFF0000000000000, double 8.0, double 0.0)
107  ret double %1
108}
109; CHECK-LABEL: @test_Inf_3(
110; CHECK: ret double 0xFFF0000000000000
111
112
113define double @test_Inf_4()  {
114  %1 = call double @llvm.fma.f64(double 7.0, double 0xFFF0000000000000, double 0.0)
115  ret double %1
116}
117; CHECK-LABEL: @test_Inf_4(
118; CHECK: ret double 0xFFF0000000000000
119
120