1 // RUN: %clang_cc1 -Wno-implicit-function-declaration -fmath-errno -emit-llvm -o - %s -triple i386-unknown-unknown | FileCheck -check-prefix CHECK-YES %s
2 // RUN: %clang_cc1 -Wno-implicit-function-declaration -emit-llvm -o - %s -triple i386-unknown-unknown | FileCheck -check-prefix CHECK-NO %s
3 // RUN: %clang_cc1 -Wno-implicit-function-declaration -funsafe-math-optimizations -emit-llvm -o - %s -triple i386-unknown-unknown | FileCheck -check-prefix CHECK-FAST %s
5 // CHECK-YES-LABEL: define{{.*}} void @test_sqrt
6 // CHECK-NO-LABEL: define{{.*}} void @test_sqrt
7 // CHECK-FAST-LABEL: define{{.*}} void @test_sqrt
8 void test_sqrt(float a0
, double a1
, long double a2
) {
9 // CHECK-YES: call float @sqrtf
10 // CHECK-NO: call float @llvm.sqrt.f32(float
11 // CHECK-FAST: call reassoc nsz arcp afn float @llvm.sqrt.f32(float
14 // CHECK-YES: call double @sqrt
15 // CHECK-NO: call double @llvm.sqrt.f64(double
16 // CHECK-FAST: call reassoc nsz arcp afn double @llvm.sqrt.f64(double
19 // CHECK-YES: call x86_fp80 @sqrtl
20 // CHECK-NO: call x86_fp80 @llvm.sqrt.f80(x86_fp80
21 // CHECK-FAST: call reassoc nsz arcp afn x86_fp80 @llvm.sqrt.f80(x86_fp80
22 long double l2
= sqrtl(a2
);
25 // CHECK-YES: declare float @sqrtf(float noundef)
26 // CHECK-YES: declare double @sqrt(double noundef)
27 // CHECK-YES: declare x86_fp80 @sqrtl(x86_fp80 noundef)
28 // CHECK-NO: declare float @llvm.sqrt.f32(float)
29 // CHECK-NO: declare double @llvm.sqrt.f64(double)
30 // CHECK-NO: declare x86_fp80 @llvm.sqrt.f80(x86_fp80)
31 // CHECK-FAST: declare float @llvm.sqrt.f32(float)
32 // CHECK-FAST: declare double @llvm.sqrt.f64(double)
33 // CHECK-FAST: declare x86_fp80 @llvm.sqrt.f80(x86_fp80)
35 // CHECK-YES-LABEL: define{{.*}} void @test_pow
36 // CHECK-NO-LABEL: define{{.*}} void @test_pow
37 void test_pow(float a0
, double a1
, long double a2
) {
38 // CHECK-YES: call float @powf
39 // CHECK-NO: call float @llvm.pow.f32
40 float l0
= powf(a0
, a0
);
42 // CHECK-YES: call double @pow
43 // CHECK-NO: call double @llvm.pow.f64
44 double l1
= pow(a1
, a1
);
46 // CHECK-YES: call x86_fp80 @powl
47 // CHECK-NO: call x86_fp80 @llvm.pow.f80
48 long double l2
= powl(a2
, a2
);
51 // CHECK-YES: declare float @powf(float noundef, float noundef)
52 // CHECK-YES: declare double @pow(double noundef, double noundef)
53 // CHECK-YES: declare x86_fp80 @powl(x86_fp80 noundef, x86_fp80 noundef)
54 // CHECK-NO: declare float @llvm.pow.f32(float, float) [[NUW_RNI:#[0-9]+]]
55 // CHECK-NO: declare double @llvm.pow.f64(double, double) [[NUW_RNI]]
56 // CHECK-NO: declare x86_fp80 @llvm.pow.f80(x86_fp80, x86_fp80) [[NUW_RNI]]
58 // CHECK-YES-LABEL: define{{.*}} void @test_fma
59 // CHECK-NO-LABEL: define{{.*}} void @test_fma
60 void test_fma(float a0
, double a1
, long double a2
) {
61 // CHECK-YES: call float @fmaf
62 // CHECK-NO: call float @llvm.fma.f32
63 float l0
= fmaf(a0
, a0
, a0
);
65 // CHECK-YES: call double @fma
66 // CHECK-NO: call double @llvm.fma.f64
67 double l1
= fma(a1
, a1
, a1
);
69 // CHECK-YES: call x86_fp80 @fmal
70 // CHECK-NO: call x86_fp80 @llvm.fma.f80
71 long double l2
= fmal(a2
, a2
, a2
);
74 // CHECK-YES: declare float @fmaf(float noundef, float noundef, float noundef)
75 // CHECK-YES: declare double @fma(double noundef, double noundef, double noundef)
76 // CHECK-YES: declare x86_fp80 @fmal(x86_fp80 noundef, x86_fp80 noundef, x86_fp80 noundef)
77 // CHECK-NO: declare float @llvm.fma.f32(float, float, float) [[NUW_RN2:#[0-9]+]]
78 // CHECK-NO: declare double @llvm.fma.f64(double, double, double) [[NUW_RN2]]
79 // CHECK-NO: declare x86_fp80 @llvm.fma.f80(x86_fp80, x86_fp80, x86_fp80) [[NUW_RN2]]
81 // Just checking to make sure these library functions are marked readnone
82 void test_builtins(double d
, float f
, long double ld
) {
83 // CHECK-NO: @test_builtins
84 // CHECK-YES: @test_builtins
85 double atan_
= atan(d
);
86 long double atanl_
= atanl(ld
);
87 float atanf_
= atanf(f
);
88 // CHECK-NO: declare double @llvm.atan.f64(double) [[NUW_RNI:#[0-9]+]]
89 // CHECK-NO: declare x86_fp80 @llvm.atan.f80(x86_fp80) [[NUW_RNI]]
90 // CHECK-NO: declare float @llvm.atan.f32(float) [[NUW_RNI]]
91 // CHECK-YES: declare double @atan(double noundef) [[NUW:#[0-9]+]]
92 // CHECK-YES: declare x86_fp80 @atanl(x86_fp80 noundef) [[NUW]]
93 // CHECK-YES: declare float @atanf(float noundef) [[NUW]]
95 double atan2_
= atan2(d
, 2);
96 long double atan2l_
= atan2l(ld
, ld
);
97 float atan2f_
= atan2f(f
, f
);
98 // CHECK-NO: declare double @llvm.atan2.f64(double, double) [[NUW_RNI]]
99 // CHECK-NO: declare x86_fp80 @llvm.atan2.f80(x86_fp80, x86_fp80) [[NUW_RNI]]
100 // CHECK-NO: declare float @llvm.atan2.f32(float, float) [[NUW_RNI]]
101 // CHECK-YES: declare double @atan2(double noundef, double noundef) [[NUW]]
102 // CHECK-YES: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) [[NUW]]
103 // CHECK-YES: declare float @atan2f(float noundef, float noundef) [[NUW]]
105 double exp_
= exp(d
);
106 long double expl_
= expl(ld
);
107 float expf_
= expf(f
);
108 // CHECK-NO: declare double @llvm.exp.f64(double) [[NUW_RNI]]
109 // CHECK-NO: declare x86_fp80 @llvm.exp.f80(x86_fp80) [[NUW_RNI]]
110 // CHECK-NO: declare float @llvm.exp.f32(float) [[NUW_RNI]]
111 // CHECK-YES: declare double @exp(double noundef) [[NUW]]
112 // CHECK-YES: declare x86_fp80 @expl(x86_fp80 noundef) [[NUW]]
113 // CHECK-YES: declare float @expf(float noundef) [[NUW]]
115 double log_
= log(d
);
116 long double logl_
= logl(ld
);
117 float logf_
= logf(f
);
118 // CHECK-NO: declare double @llvm.log.f64(double) [[NUW_RNI]]
119 // CHECK-NO: declare x86_fp80 @llvm.log.f80(x86_fp80) [[NUW_RNI]]
120 // CHECK-NO: declare float @llvm.log.f32(float) [[NUW_RNI]]
121 // CHECK-YES: declare double @log(double noundef) [[NUW]]
122 // CHECK-YES: declare x86_fp80 @logl(x86_fp80 noundef) [[NUW]]
123 // CHECK-YES: declare float @logf(float noundef) [[NUW]]
126 // CHECK-YES: attributes [[NUW]] = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+x87" }
127 // CHECK-NO-DAG: attributes [[NUW_RNI]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }