1 // -O2
2 // RUN: %clang_cc1 -Wno-implicit-function-declaration \
3 // RUN: -triple x86_64-unknown-unknown -fmath-errno -ffp-contract=on \
4 // RUN: -fno-rounding-math -O2 -emit-llvm -o - %s \
5 // RUN: | FileCheck %s
6
7 // -ffast-math
8 // RUN: %clang_cc1 -Wno-implicit-function-declaration \
9 // RUN: -triple x86_64-unknown-unknown -menable-no-infs -menable-no-nans \
10 // RUN: -fapprox-func -funsafe-math-optimizations -fno-signed-zeros -mreassociate \
11 // RUN: -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math \
12 // RUN: -ffinite-math-only -ffast-math -emit-llvm -o - %s \
13 // RUN: | FileCheck %s -check-prefix=FAST
14
15 // -O0
16 // RUN: %clang_cc1 -Wno-implicit-function-declaration \
17 // RUN: -triple x86_64-unknown-unknown -fmath-errno -ffp-contract=on \
18 // RUN: -fno-rounding-math -O0 \
19 // RUN: -emit-llvm -o - %s | FileCheck %s -check-prefix=NOOPT
20
21 #pragma float_control(precise,on)
f1(float x)22 float f1(float x) {
23 return sqrtf(x);
24 }
25
26 // CHECK-LABEL: define {{.*}} float @f1
27 // CHECK: tail call float @sqrtf(float noundef {{.*}}) #[[ATTR4_O2:[0-9]+]]
28
29 // FAST-LABEL: define {{.*}} nofpclass(nan inf) float @f1
30 // FAST: call nofpclass(nan inf) float @sqrtf(float noundef nofpclass(nan inf) {{.*}}) #[[ATTR3_FAST:[0-9]+]]
31
32 // NOOPT-LABEL: define {{.*}} float @f1
33 // NOOPT: call float @sqrtf(float noundef {{.*}}) #[[ATTR4_NOOPT:[0-9]+]]
34
35 #pragma float_control(precise,off)
f2(float x)36 float f2(float x) {
37 return sqrtf(x);
38 }
39
40 // CHECK-LABEL: define {{.*}} float @f2
41 // CHECK: tail call fast float @llvm.sqrt.f32(float {{.*}})
42
43 // FAST-LABEL: define {{.*}} nofpclass(nan inf) float @f2
44 // FAST: call fast float @llvm.sqrt.f32(float {{.*}})
45
46 // NOOPT-LABEL: define {{.*}} float @f2
47 // NOOPT: call fast float @sqrtf(float {{.*}}) #[[ATTR4_NOOPT:[0-9]+]]
48
49 __attribute__((optnone))
f3(float x)50 float f3(float x) {
51 x = sqrtf(x);
52 return x;
53 }
54
55 // CHECK-LABEL: define {{.*}} float @f3
56 // CHECK: call float @sqrtf(float noundef {{.*}})
57
58 // FAST-LABEL: define {{.*}} nofpclass(nan inf) float @f3
59 // FAST: call nofpclass(nan inf) float @sqrtf(float noundef nofpclass(nan inf) {{.*}}) #[[ATTR4_FAST:[0-9]+]]
60
61 // NOOPT-LABEL: define {{.*}} float @f3
62 // NOOPT: call float @sqrtf(float noundef %0) #[[ATTR4_NOOPT:[0-9]+]]
63
64 // CHECK: [[ATTR4_O2]] = { nounwind }
65 // FAST: [[ATTR3_FAST]] = { nounwind willreturn memory(none) }
66 // NOOPT: [[ATTR4_NOOPT]] = { nounwind }
67