Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenOpenCL / fpmath.cl
blobf3649d52e0091154a9ce786e7daf8f1ab98a8154
1 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s
2 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s
3 // RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.2 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-FLT %s
4 // RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -triple spir-unknown-unknown -pedantic | FileCheck --check-prefix=CHECK-DBL %s
6 typedef __attribute__(( ext_vector_type(4) )) float float4;
8 float spscalardiv(float a, float b) {
9 // CHECK: @spscalardiv
10 // CHECK: fdiv{{.*}},
11 // NODIVOPT: !fpmath ![[MD_FDIV:[0-9]+]]
12 // DIVOPT-NOT: !fpmath !{{[0-9]+}}
13 return a / b;
16 float4 spvectordiv(float4 a, float4 b) {
17 // CHECK: @spvectordiv
18 // CHECK: fdiv{{.*}},
19 // NODIVOPT: !fpmath ![[MD_FDIV]]
20 // DIVOPT-NOT: !fpmath !{{[0-9]+}}
21 return a / b;
24 float spscalarsqrt(float a) {
25 // CHECK-LABEL: @spscalarsqrt
26 // NODIVOPT: call float @llvm.sqrt.f32(float %{{.+}}), !fpmath ![[MD_SQRT:[0-9]+]]
27 // DIVOPT: call float @llvm.sqrt.f32(float %{{.+}}){{$}}
28 return __builtin_sqrtf(a);
31 float elementwise_sqrt_f32(float a) {
32 // CHECK-LABEL: @elementwise_sqrt_f32
33 // NODIVOPT: call float @llvm.sqrt.f32(float %{{.+}}), !fpmath ![[MD_SQRT:[0-9]+]]
34 // DIVOPT: call float @llvm.sqrt.f32(float %{{.+}}){{$}}
35 return __builtin_elementwise_sqrt(a);
38 float4 elementwise_sqrt_v4f32(float4 a) {
39 // CHECK-LABEL: @elementwise_sqrt_v4f32
40 // NODIVOPT: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %{{.+}}), !fpmath ![[MD_SQRT:[0-9]+]]
41 // DIVOPT: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %{{.+}}){{$}}
42 return __builtin_elementwise_sqrt(a);
46 #if __OPENCL_C_VERSION__ >=120
47 void printf(constant char* fmt, ...);
49 void testdbllit(long *val) {
50 // CHECK-FLT: float noundef 2.000000e+01
51 // CHECK-DBL: double noundef 2.000000e+01
52 printf("%f", 20.0);
55 #endif
57 #ifndef NOFP64
58 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
59 typedef __attribute__(( ext_vector_type(4) )) double double4;
61 double dpscalardiv(double a, double b) {
62 // CHECK: @dpscalardiv
63 // CHECK-NOT: !fpmath
64 return a / b;
67 double4 dpvectordiv(double4 a, double4 b) {
68 // CHECK: @dpvectordiv
69 // CHECK-NOT: !fpmath
70 return a / b;
73 double dpscalarsqrt(double a) {
74 // CHECK-LABEL: @dpscalarsqrt
75 // CHECK: call double @llvm.sqrt.f64(double %{{.+}}){{$}}
76 return __builtin_sqrt(a);
79 double elementwise_sqrt_f64(double a) {
80 // CHECK-LABEL: @elementwise_sqrt_f64
81 // CHECK: call double @llvm.sqrt.f64(double %{{.+}}){{$}}
82 return __builtin_elementwise_sqrt(a);
85 double4 elementwise_sqrt_v4f64(double4 a) {
86 // CHECK-LABEL: @elementwise_sqrt_v4f64
87 // CHECK: call <4 x double> @llvm.sqrt.v4f64(<4 x double> %{{.+}}){{$}}
88 return __builtin_elementwise_sqrt(a);
91 #endif
93 // NODIVOPT: ![[MD_FDIV]] = !{float 2.500000e+00}
94 // NODIVOPT: ![[MD_SQRT]] = !{float 3.000000e+00}