Add support for constant folding the pow intrinsic.
[oota-llvm.git] / test / Transforms / ConstProp / calls.ll
1 ; RUN: opt < %s -constprop -S | FileCheck %s
2 ; RUN: opt < %s -constprop -disable-simplify-libcalls -S | FileCheck %s --check-prefix=FNOBUILTIN
3
4 declare double @cos(double)
5
6 declare double @sin(double)
7
8 declare double @tan(double)
9
10 declare double @sqrt(double)
11 declare double @exp2(double)
12
13 define double @T() {
14 ; CHECK: @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
31 define i1 @test_sse_cvt() nounwind readnone {
32 ; CHECK: @test_sse_cvt
33 ; CHECK-NOT: call
34 ; CHECK: ret i1 true
35 entry:
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
55 declare i32 @llvm.x86.sse.cvtss2si(<4 x float>) nounwind readnone
56 declare i32 @llvm.x86.sse.cvttss2si(<4 x float>) nounwind readnone
57 declare i64 @llvm.x86.sse.cvtss2si64(<4 x float>) nounwind readnone
58 declare i64 @llvm.x86.sse.cvttss2si64(<4 x float>) nounwind readnone
59 declare i32 @llvm.x86.sse2.cvtsd2si(<2 x double>) nounwind readnone
60 declare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) nounwind readnone
61 declare i64 @llvm.x86.sse2.cvtsd2si64(<2 x double>) nounwind readnone
62 declare i64 @llvm.x86.sse2.cvttsd2si64(<2 x double>) nounwind readnone
63
64 define double @test_intrinsic_pow() nounwind uwtable ssp {
65 entry:
66 ; CHECK: @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 }
71 declare double @llvm.pow.f64(double, double) nounwind readonly
72
73 ; Shouldn't fold because of -fno-builtin
74 define double @sin_() nounwind uwtable ssp {
75 ; FNOBUILTIN: @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
82 define double @sqrt_() nounwind uwtable ssp {
83 ; FNOBUILTIN: @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
90 define float @sqrtf_() nounwind uwtable ssp {
91 ; FNOBUILTIN: @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 }
96 declare float @sqrtf(float)
97
98 ; Shouldn't fold because of -fno-builtin
99 define float @sinf_() nounwind uwtable ssp {
100 ; FNOBUILTIN: @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 }
105 declare float @sinf(float)
106
107 ; Shouldn't fold because of -fno-builtin
108 define double @tan_() nounwind uwtable ssp {
109 ; FNOBUILTIN: @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
116 define double @tanh_() nounwind uwtable ssp {
117 ; FNOBUILTIN: @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 }
122 declare double @tanh(double)
123
124 ; Shouldn't fold because of -fno-builtin
125 define double @pow_() nounwind uwtable ssp {
126 ; FNOBUILTIN: @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 }
131 declare double @pow(double, double)
132
133 ; Shouldn't fold because of -fno-builtin
134 define double @fmod_() nounwind uwtable ssp {
135 ; FNOBUILTIN: @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 }
140 declare double @fmod(double, double)
141
142 ; Shouldn't fold because of -fno-builtin
143 define double @atan2_() nounwind uwtable ssp {
144 ; FNOBUILTIN: @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 }
149 declare double @atan2(double, double)