• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 @acos(double)
5declare double @asin(double)
6declare double @atan(double)
7declare double @atan2(double, double)
8declare double @ceil(double)
9declare double @cos(double)
10declare double @cosh(double)
11declare double @exp(double)
12declare double @exp2(double)
13declare double @fabs(double)
14declare double @floor(double)
15declare double @fmod(double, double)
16declare double @log(double)
17declare double @log10(double)
18declare double @pow(double, double)
19declare double @sin(double)
20declare double @sinh(double)
21declare double @sqrt(double)
22declare double @tan(double)
23declare double @tanh(double)
24
25declare float @acosf(float)
26declare float @asinf(float)
27declare float @atanf(float)
28declare float @atan2f(float, float)
29declare float @ceilf(float)
30declare float @cosf(float)
31declare float @coshf(float)
32declare float @expf(float)
33declare float @exp2f(float)
34declare float @fabsf(float)
35declare float @floorf(float)
36declare float @fmodf(float, float)
37declare float @logf(float)
38declare float @log10f(float)
39declare float @powf(float, float)
40declare float @sinf(float)
41declare float @sinhf(float)
42declare float @sqrtf(float)
43declare float @tanf(float)
44declare float @tanhf(float)
45
46define double @T() {
47; CHECK-LABEL: @T(
48; FNOBUILTIN-LABEL: @T(
49
50; CHECK-NOT: call
51; CHECK: ret
52  %A = call double @cos(double 0.000000e+00)
53  %B = call double @sin(double 0.000000e+00)
54  %a = fadd double %A, %B
55  %C = call double @tan(double 0.000000e+00)
56  %b = fadd double %a, %C
57  %D = call double @sqrt(double 4.000000e+00)
58  %c = fadd double %b, %D
59
60  %slot = alloca double
61  %slotf = alloca float
62; FNOBUILTIN: call
63  %1 = call double @acos(double 1.000000e+00)
64  store double %1, double* %slot
65; FNOBUILTIN: call
66  %2 = call double @asin(double 1.000000e+00)
67  store double %2, double* %slot
68; FNOBUILTIN: call
69  %3 = call double @atan(double 3.000000e+00)
70  store double %3, double* %slot
71; FNOBUILTIN: call
72  %4 = call double @atan2(double 3.000000e+00, double 4.000000e+00)
73  store double %4, double* %slot
74; FNOBUILTIN: call
75  %5 = call double @ceil(double 3.000000e+00)
76  store double %5, double* %slot
77; FNOBUILTIN: call
78  %6 = call double @cosh(double 3.000000e+00)
79  store double %6, double* %slot
80; FNOBUILTIN: call
81  %7 = call double @exp(double 3.000000e+00)
82  store double %7, double* %slot
83; FNOBUILTIN: call
84  %8 = call double @exp2(double 3.000000e+00)
85  store double %8, double* %slot
86; FNOBUILTIN: call
87  %9 = call double @fabs(double 3.000000e+00)
88  store double %9, double* %slot
89; FNOBUILTIN: call
90  %10 = call double @floor(double 3.000000e+00)
91  store double %10, double* %slot
92; FNOBUILTIN: call
93  %11 = call double @fmod(double 3.000000e+00, double 4.000000e+00)
94  store double %11, double* %slot
95; FNOBUILTIN: call
96  %12 = call double @log(double 3.000000e+00)
97  store double %12, double* %slot
98; FNOBUILTIN: call
99  %13 = call double @log10(double 3.000000e+00)
100  store double %13, double* %slot
101; FNOBUILTIN: call
102  %14 = call double @pow(double 3.000000e+00, double 4.000000e+00)
103  store double %14, double* %slot
104; FNOBUILTIN: call
105  %15 = call double @sinh(double 3.000000e+00)
106  store double %15, double* %slot
107; FNOBUILTIN: call
108  %16 = call double @tanh(double 3.000000e+00)
109  store double %16, double* %slot
110; FNOBUILTIN: call
111  %17 = call float @acosf(float 1.000000e+00)
112  store float %17, float* %slotf
113; FNOBUILTIN: call
114  %18 = call float @asinf(float 1.000000e+00)
115  store float %18, float* %slotf
116; FNOBUILTIN: call
117  %19 = call float @atanf(float 3.000000e+00)
118  store float %19, float* %slotf
119; FNOBUILTIN: call
120  %20 = call float @atan2f(float 3.000000e+00, float 4.000000e+00)
121  store float %20, float* %slotf
122; FNOBUILTIN: call
123  %21 = call float @ceilf(float 3.000000e+00)
124  store float %21, float* %slotf
125; FNOBUILTIN: call
126  %22 = call float @cosf(float 3.000000e+00)
127  store float %22, float* %slotf
128; FNOBUILTIN: call
129  %23 = call float @coshf(float 3.000000e+00)
130  store float %23, float* %slotf
131; FNOBUILTIN: call
132  %24 = call float @expf(float 3.000000e+00)
133  store float %24, float* %slotf
134; FNOBUILTIN: call
135  %25 = call float @exp2f(float 3.000000e+00)
136  store float %25, float* %slotf
137; FNOBUILTIN: call
138  %26 = call float @fabsf(float 3.000000e+00)
139  store float %26, float* %slotf
140; FNOBUILTIN: call
141  %27 = call float @floorf(float 3.000000e+00)
142  store float %27, float* %slotf
143; FNOBUILTIN: call
144  %28 = call float @fmodf(float 3.000000e+00, float 4.000000e+00)
145  store float %28, float* %slotf
146; FNOBUILTIN: call
147  %29 = call float @logf(float 3.000000e+00)
148  store float %29, float* %slotf
149; FNOBUILTIN: call
150  %30 = call float @log10f(float 3.000000e+00)
151  store float %30, float* %slotf
152; FNOBUILTIN: call
153  %31 = call float @powf(float 3.000000e+00, float 4.000000e+00)
154  store float %31, float* %slotf
155; FNOBUILTIN: call
156  %32 = call float @sinf(float 3.000000e+00)
157  store float %32, float* %slotf
158; FNOBUILTIN: call
159  %33 = call float @sinhf(float 3.000000e+00)
160  store float %33, float* %slotf
161; FNOBUILTIN: call
162  %34 = call float @sqrtf(float 3.000000e+00)
163  store float %34, float* %slotf
164; FNOBUILTIN: call
165  %35 = call float @tanf(float 3.000000e+00)
166  store float %35, float* %slotf
167; FNOBUILTIN: call
168  %36 = call float @tanhf(float 3.000000e+00)
169  store float %36, float* %slotf
170
171; FNOBUILTIN: ret
172
173  ; PR9315
174  %E = call double @exp2(double 4.0)
175  %d = fadd double %c, %E
176  ret double %d
177}
178
179define i1 @test_sse_cvts_exact() nounwind readnone {
180; CHECK-LABEL: @test_sse_cvts_exact(
181; CHECK-NOT: call
182; CHECK: ret i1 true
183entry:
184  %i0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> <float 3.0, float undef, float undef, float undef>) nounwind
185  %i1 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> <float 3.0, float undef, float undef, float undef>) nounwind
186  %i2 = call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> <double 7.0, double undef>) nounwind
187  %i3 = call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> <double 7.0, double undef>) nounwind
188  %sum02 = add i32 %i0, %i2
189  %sum13 = add i64 %i1, %i3
190  %cmp02 = icmp eq i32 %sum02, 10
191  %cmp13 = icmp eq i64 %sum13, 10
192  %b = and i1 %cmp02, %cmp13
193  ret i1 %b
194}
195
196; TODO: Inexact values should not fold as they are dependent on rounding mode
197define i1 @test_sse_cvts_inexact() nounwind readnone {
198; CHECK-LABEL: @test_sse_cvts_inexact(
199; CHECK-NOT: call
200; CHECK: ret i1 true
201entry:
202  %i0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
203  %i1 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
204  %i2 = call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> <double 1.75, double undef>) nounwind
205  %i3 = call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> <double 1.75, double undef>) nounwind
206  %sum02 = add i32 %i0, %i2
207  %sum13 = add i64 %i1, %i3
208  %cmp02 = icmp eq i32 %sum02, 4
209  %cmp13 = icmp eq i64 %sum13, 4
210  %b = and i1 %cmp02, %cmp13
211  ret i1 %b
212}
213
214; FLT_MAX/DBL_MAX should not fold
215define i1 @test_sse_cvts_max() nounwind readnone {
216; CHECK-LABEL: @test_sse_cvts_max(
217; CHECK: call
218; CHECK: call
219; CHECK: call
220; CHECK: call
221entry:
222  %fm = bitcast <4 x i32> <i32 2139095039, i32 undef, i32 undef, i32 undef> to <4 x float>
223  %dm = bitcast <2 x i64> <i64 9218868437227405311, i64 undef> to <2 x double>
224  %i0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> %fm) nounwind
225  %i1 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> %fm) nounwind
226  %i2 = call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> %dm) nounwind
227  %i3 = call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> %dm) nounwind
228  %sum02 = add i32 %i0, %i2
229  %sum13 = add i64 %i1, %i3
230  %sum02.sext = sext i32 %sum02 to i64
231  %b = icmp eq i64 %sum02.sext, %sum13
232  ret i1 %b
233}
234
235; INF should not fold
236define i1 @test_sse_cvts_inf() nounwind readnone {
237; CHECK-LABEL: @test_sse_cvts_inf(
238; CHECK: call
239; CHECK: call
240; CHECK: call
241; CHECK: call
242entry:
243  %fm = bitcast <4 x i32> <i32 2139095040, i32 undef, i32 undef, i32 undef> to <4 x float>
244  %dm = bitcast <2 x i64> <i64 9218868437227405312, i64 undef> to <2 x double>
245  %i0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> %fm) nounwind
246  %i1 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> %fm) nounwind
247  %i2 = call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> %dm) nounwind
248  %i3 = call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> %dm) nounwind
249  %sum02 = add i32 %i0, %i2
250  %sum13 = add i64 %i1, %i3
251  %sum02.sext = sext i32 %sum02 to i64
252  %b = icmp eq i64 %sum02.sext, %sum13
253  ret i1 %b
254}
255
256; NAN should not fold
257define i1 @test_sse_cvts_nan() nounwind readnone {
258; CHECK-LABEL: @test_sse_cvts_nan(
259; CHECK: call
260; CHECK: call
261; CHECK: call
262; CHECK: call
263entry:
264  %fm = bitcast <4 x i32> <i32 2143289344, i32 undef, i32 undef, i32 undef> to <4 x float>
265  %dm = bitcast <2 x i64> <i64 9221120237041090560, i64 undef> to <2 x double>
266  %i0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> %fm) nounwind
267  %i1 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> %fm) nounwind
268  %i2 = call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> %dm) nounwind
269  %i3 = call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> %dm) nounwind
270  %sum02 = add i32 %i0, %i2
271  %sum13 = add i64 %i1, %i3
272  %sum02.sext = sext i32 %sum02 to i64
273  %b = icmp eq i64 %sum02.sext, %sum13
274  ret i1 %b
275}
276
277define i1 @test_sse_cvtts_exact() nounwind readnone {
278; CHECK-LABEL: @test_sse_cvtts_exact(
279; CHECK-NOT: call
280; CHECK: ret i1 true
281entry:
282  %i0 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> <float 3.0, float undef, float undef, float undef>) nounwind
283  %i1 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> <float 3.0, float undef, float undef, float undef>) nounwind
284  %i2 = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> <double 7.0, double undef>) nounwind
285  %i3 = call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> <double 7.0, double undef>) nounwind
286  %sum02 = add i32 %i0, %i2
287  %sum13 = add i64 %i1, %i3
288  %cmp02 = icmp eq i32 %sum02, 10
289  %cmp13 = icmp eq i64 %sum13, 10
290  %b = and i1 %cmp02, %cmp13
291  ret i1 %b
292}
293
294define i1 @test_sse_cvtts_inexact() nounwind readnone {
295; CHECK-LABEL: @test_sse_cvtts_inexact(
296; CHECK-NOT: call
297; CHECK: ret i1 true
298entry:
299  %i0 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
300  %i1 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
301  %i2 = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> <double 1.75, double undef>) nounwind
302  %i3 = call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> <double 1.75, double undef>) nounwind
303  %sum02 = add i32 %i0, %i2
304  %sum13 = add i64 %i1, %i3
305  %cmp02 = icmp eq i32 %sum02, 2
306  %cmp13 = icmp eq i64 %sum13, 2
307  %b = and i1 %cmp02, %cmp13
308  ret i1 %b
309}
310
311; FLT_MAX/DBL_MAX should not fold
312define i1 @test_sse_cvtts_max() nounwind readnone {
313; CHECK-LABEL: @test_sse_cvtts_max(
314; CHECK: call
315; CHECK: call
316; CHECK: call
317; CHECK: call
318entry:
319  %fm = bitcast <4 x i32> <i32 2139095039, i32 undef, i32 undef, i32 undef> to <4 x float>
320  %dm = bitcast <2 x i64> <i64 9218868437227405311, i64 undef> to <2 x double>
321  %i0 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> %fm) nounwind
322  %i1 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> %fm) nounwind
323  %i2 = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> %dm) nounwind
324  %i3 = call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> %dm) nounwind
325  %sum02 = add i32 %i0, %i2
326  %sum13 = add i64 %i1, %i3
327  %sum02.sext = sext i32 %sum02 to i64
328  %b = icmp eq i64 %sum02.sext, %sum13
329  ret i1 %b
330}
331
332; INF should not fold
333define i1 @test_sse_cvtts_inf() nounwind readnone {
334; CHECK-LABEL: @test_sse_cvtts_inf(
335; CHECK: call
336; CHECK: call
337; CHECK: call
338; CHECK: call
339entry:
340  %fm = bitcast <4 x i32> <i32 2139095040, i32 undef, i32 undef, i32 undef> to <4 x float>
341  %dm = bitcast <2 x i64> <i64 9218868437227405312, i64 undef> to <2 x double>
342  %i0 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> %fm) nounwind
343  %i1 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> %fm) nounwind
344  %i2 = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> %dm) nounwind
345  %i3 = call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> %dm) nounwind
346  %sum02 = add i32 %i0, %i2
347  %sum13 = add i64 %i1, %i3
348  %sum02.sext = sext i32 %sum02 to i64
349  %b = icmp eq i64 %sum02.sext, %sum13
350  ret i1 %b
351}
352
353; NAN should not fold
354define i1 @test_sse_cvtts_nan() nounwind readnone {
355; CHECK-LABEL: @test_sse_cvtts_nan(
356; CHECK: call
357; CHECK: call
358; CHECK: call
359; CHECK: call
360entry:
361  %fm = bitcast <4 x i32> <i32 2143289344, i32 undef, i32 undef, i32 undef> to <4 x float>
362  %dm = bitcast <2 x i64> <i64 9221120237041090560, i64 undef> to <2 x double>
363  %i0 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> %fm) nounwind
364  %i1 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> %fm) nounwind
365  %i2 = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> %dm) nounwind
366  %i3 = call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> %dm) nounwind
367  %sum02 = add i32 %i0, %i2
368  %sum13 = add i64 %i1, %i3
369  %sum02.sext = sext i32 %sum02 to i64
370  %b = icmp eq i64 %sum02.sext, %sum13
371  ret i1 %b
372}
373
374declare i32 @llvm.x86.sse.cvtss2si(<4 x float>) nounwind readnone
375declare i32 @llvm.x86.sse.cvttss2si(<4 x float>) nounwind readnone
376declare i64 @llvm.x86.sse.cvtss2si64(<4 x float>) nounwind readnone
377declare i64 @llvm.x86.sse.cvttss2si64(<4 x float>) nounwind readnone
378declare i32 @llvm.x86.sse2.cvtsd2si(<2 x double>) nounwind readnone
379declare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) nounwind readnone
380declare i64 @llvm.x86.sse2.cvtsd2si64(<2 x double>) nounwind readnone
381declare i64 @llvm.x86.sse2.cvttsd2si64(<2 x double>) nounwind readnone
382
383define double @test_intrinsic_pow() nounwind uwtable ssp {
384entry:
385; CHECK-LABEL: @test_intrinsic_pow(
386; CHECK-NOT: call
387; CHECK: ret
388  %0 = call double @llvm.pow.f64(double 1.500000e+00, double 3.000000e+00)
389  ret double %0
390}
391
392declare double @llvm.pow.f64(double, double) nounwind readonly
393