1; RUN: opt < %s -constprop -S | FileCheck %s
2; RUN: opt < %s -constprop -disable-simplify-libcalls -S | FileCheck %s --check-prefix=FNOBUILTIN
3
4declare double @cos(double)
5
6declare double @sin(double)
7
8declare double @tan(double)
9
10declare double @sqrt(double)
11declare double @exp2(double)
12
13define double @T() {
14; CHECK-LABEL: @T(
15; CHECK-NOT: call
16; CHECK: ret
17  %A = call double @cos(double 0.000000e+00)
18  %B = call double @sin(double 0.000000e+00)
19  %a = fadd double %A, %B
20  %C = call double @tan(double 0.000000e+00)
21  %b = fadd double %a, %C
22  %D = call double @sqrt(double 4.000000e+00)
23  %c = fadd double %b, %D
24
25  ; PR9315
26  %E = call double @exp2(double 4.0)
27  %d = fadd double %c, %E
28  ret double %d
29}
30
31define i1 @test_sse_cvt() nounwind readnone {
32; CHECK-LABEL: @test_sse_cvt(
33; CHECK-NOT: call
34; CHECK: ret i1 true
35entry:
36  %i0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
37  %i1 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
38  %i2 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
39  %i3 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
40  %i4 = call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> <double 1.75, double undef>) nounwind
41  %i5 = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> <double 1.75, double undef>) nounwind
42  %i6 = call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> <double 1.75, double undef>) nounwind
43  %i7 = call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> <double 1.75, double undef>) nounwind
44  %sum11 = add i32 %i0, %i1
45  %sum12 = add i32 %i4, %i5
46  %sum1 = add i32 %sum11, %sum12
47  %sum21 = add i64 %i2, %i3
48  %sum22 = add i64 %i6, %i7
49  %sum2 = add i64 %sum21, %sum22
50  %sum1.sext = sext i32 %sum1 to i64
51  %b = icmp eq i64 %sum1.sext, %sum2
52  ret i1 %b
53}
54
55declare i32 @llvm.x86.sse.cvtss2si(<4 x float>) nounwind readnone
56declare i32 @llvm.x86.sse.cvttss2si(<4 x float>) nounwind readnone
57declare i64 @llvm.x86.sse.cvtss2si64(<4 x float>) nounwind readnone
58declare i64 @llvm.x86.sse.cvttss2si64(<4 x float>) nounwind readnone
59declare i32 @llvm.x86.sse2.cvtsd2si(<2 x double>) nounwind readnone
60declare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) nounwind readnone
61declare i64 @llvm.x86.sse2.cvtsd2si64(<2 x double>) nounwind readnone
62declare i64 @llvm.x86.sse2.cvttsd2si64(<2 x double>) nounwind readnone
63
64define double @test_intrinsic_pow() nounwind uwtable ssp {
65entry:
66; CHECK-LABEL: @test_intrinsic_pow(
67; CHECK-NOT: call
68  %0 = call double @llvm.pow.f64(double 1.500000e+00, double 3.000000e+00)
69  ret double %0
70}
71declare double @llvm.pow.f64(double, double) nounwind readonly
72
73; Shouldn't fold because of -fno-builtin
74define double @sin_() nounwind uwtable ssp {
75; FNOBUILTIN-LABEL: @sin_(
76; FNOBUILTIN: %1 = call double @sin(double 3.000000e+00)
77  %1 = call double @sin(double 3.000000e+00)
78  ret double %1
79}
80
81; Shouldn't fold because of -fno-builtin
82define double @sqrt_() nounwind uwtable ssp {
83; FNOBUILTIN-LABEL: @sqrt_(
84; FNOBUILTIN: %1 = call double @sqrt(double 3.000000e+00)
85  %1 = call double @sqrt(double 3.000000e+00)
86  ret double %1
87}
88
89; Shouldn't fold because of -fno-builtin
90define float @sqrtf_() nounwind uwtable ssp {
91; FNOBUILTIN-LABEL: @sqrtf_(
92; FNOBUILTIN: %1 = call float @sqrtf(float 3.000000e+00)
93  %1 = call float @sqrtf(float 3.000000e+00)
94  ret float %1
95}
96declare float @sqrtf(float)
97
98; Shouldn't fold because of -fno-builtin
99define float @sinf_() nounwind uwtable ssp {
100; FNOBUILTIN-LABEL: @sinf_(
101; FNOBUILTIN: %1 = call float @sinf(float 3.000000e+00)
102  %1 = call float @sinf(float 3.000000e+00)
103  ret float %1
104}
105declare float @sinf(float)
106
107; Shouldn't fold because of -fno-builtin
108define double @tan_() nounwind uwtable ssp {
109; FNOBUILTIN-LABEL: @tan_(
110; FNOBUILTIN: %1 = call double @tan(double 3.000000e+00)
111  %1 = call double @tan(double 3.000000e+00)
112  ret double %1
113}
114
115; Shouldn't fold because of -fno-builtin
116define double @tanh_() nounwind uwtable ssp {
117; FNOBUILTIN-LABEL: @tanh_(
118; FNOBUILTIN: %1 = call double @tanh(double 3.000000e+00)
119  %1 = call double @tanh(double 3.000000e+00)
120  ret double %1
121}
122declare double @tanh(double)
123
124; Shouldn't fold because of -fno-builtin
125define double @pow_() nounwind uwtable ssp {
126; FNOBUILTIN-LABEL: @pow_(
127; FNOBUILTIN: %1 = call double @pow(double 3.000000e+00, double 3.000000e+00)
128  %1 = call double @pow(double 3.000000e+00, double 3.000000e+00)
129  ret double %1
130}
131declare double @pow(double, double)
132
133; Shouldn't fold because of -fno-builtin
134define double @fmod_() nounwind uwtable ssp {
135; FNOBUILTIN-LABEL: @fmod_(
136; FNOBUILTIN: %1 = call double @fmod(double 3.000000e+00, double 3.000000e+00)
137  %1 = call double @fmod(double 3.000000e+00, double 3.000000e+00)
138  ret double %1
139}
140declare double @fmod(double, double)
141
142; Shouldn't fold because of -fno-builtin
143define double @atan2_() nounwind uwtable ssp {
144; FNOBUILTIN-LABEL: @atan2_(
145; FNOBUILTIN: %1 = call double @atan2(double 3.000000e+00, double 3.000000e+00)
146  %1 = call double @atan2(double 3.000000e+00, double 3.000000e+00)
147  ret double %1
148}
149declare double @atan2(double, double)
150