| 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 |
| 5 |
|
| 6 |
typedef __attribute__(( ext_vector_type(4) )) float float4; |
| 7 |
|
| 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; |
| 14 |
} |
| 15 |
|
| 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; |
| 22 |
} |
| 23 |
|
| 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); |
| 29 |
} |
| 30 |
|
| 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); |
| 36 |
} |
| 37 |
|
| 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); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
#if __OPENCL_C_VERSION__ >=120 |
| 47 |
void printf(constant char* fmt, ...); |
| 48 |
|
| 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); |
| 53 |
} |
| 54 |
|
| 55 |
#endif |
| 56 |
|
| 57 |
#ifndef NOFP64 |
| 58 |
#pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 59 |
typedef __attribute__(( ext_vector_type(4) )) double double4; |
| 60 |
|
| 61 |
double dpscalardiv(double a, double b) { |
| 62 |
// CHECK: @dpscalardiv |
| 63 |
// CHECK-NOT: !fpmath |
| 64 |
return a / b; |
| 65 |
} |
| 66 |
|
| 67 |
double4 dpvectordiv(double4 a, double4 b) { |
| 68 |
// CHECK: @dpvectordiv |
| 69 |
// CHECK-NOT: !fpmath |
| 70 |
return a / b; |
| 71 |
} |
| 72 |
|
| 73 |
double dpscalarsqrt(double a) { |
| 74 |
// CHECK-LABEL: @dpscalarsqrt |
| 75 |
// CHECK: call double @llvm.sqrt.f64(double %{{.+}}){{$}} |
| 76 |
return __builtin_sqrt(a); |
| 77 |
} |
| 78 |
|
| 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); |
| 83 |
} |
| 84 |
|
| 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); |
| 89 |
} |
| 90 |
|
| 91 |
#endif |
| 92 |
|
| 93 |
// NODIVOPT: ![[MD_FDIV]] = !{float 2.500000e+00} |
| 94 |
// NODIVOPT: ![[MD_SQRT]] = !{float 3.000000e+00} |