1// Test that float variants of sqrt are emitted as available_externally inline 2// definitions that call the sqrt intrinsic with appropriate !fpmath metadata 3// depending on -cl-fp32-correctly-rounded-divide-sqrt 4 5// Test with -fdeclare-opencl-builtins 6// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -emit-llvm -o %t.ll %s 7// RUN: FileCheck -check-prefixes=CHECK,DEFAULT %s < %t.ll 8// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -cl-fp32-correctly-rounded-divide-sqrt -emit-llvm -o %t.ll %s 9// RUN: FileCheck -check-prefixes=CHECK,CORRECTLYROUNDED %s < %t.ll 10 11// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -cl-unsafe-math-optimizations -emit-llvm -o %t.ll %s 12// RUN: FileCheck -check-prefixes=CHECK,DEFAULT-UNSAFE %s < %t.ll 13// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -cl-fp32-correctly-rounded-divide-sqrt -cl-unsafe-math-optimizations -emit-llvm -o %t.ll %s 14// RUN: FileCheck -check-prefixes=CHECK,CORRECTLYROUNDED-UNSAFE %s < %t.ll 15 16// Test without -fdeclare-opencl-builtins 17// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -finclude-default-header -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,DEFAULT %s 18// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -finclude-default-header -cl-fp32-correctly-rounded-divide-sqrt -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,CORRECTLYROUNDED %s 19 20// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -finclude-default-header -cl-unsafe-math-optimizations -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,DEFAULT-UNSAFE %s 21// RUN: %clang_cc1 -disable-llvm-passes -triple amdgcn-unknown-unknown -finclude-default-header -cl-fp32-correctly-rounded-divide-sqrt -cl-unsafe-math-optimizations -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,CORRECTLYROUNDED-UNSAFE %s 22 23#pragma OPENCL EXTENSION cl_khr_fp16 : enable 24 25// CHECK-LABEL: define {{.*}} float @call_sqrt_f32( 26// DEFAULT: call float @_Z4sqrtf(float noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH:\![0-9]+]]{{$}} 27// CORRECTLYROUNDED: call float @_Z4sqrtf(float noundef %{{.+}}) #{{[0-9]+}}{{$}} 28 29// DEFAULT-UNSAFE: call reassoc nsz arcp contract afn float @_Z4sqrtf(float noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH:\![0-9]+]]{{$}} 30// CORRECTLYROUNDED-UNSAFE: call reassoc nsz arcp contract afn float @_Z4sqrtf(float noundef %{{.+}}) #{{[0-9]+}}{{$}} 31float call_sqrt_f32(float x) { 32 return sqrt(x); 33} 34 35// CHECK-LABEL: define {{.*}} <2 x float> @call_sqrt_v2f32( 36// DEFAULT: call <2 x float> @_Z4sqrtDv2_f(<2 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 37// CORRECTLYROUNDED: call <2 x float> @_Z4sqrtDv2_f(<2 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 38 39// DEFAULT-UNSAFE: call reassoc nsz arcp contract afn <2 x float> @_Z4sqrtDv2_f(<2 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 40// CORRECTLY-UNSAFE: call reassoc nsz arcp contract afn <2 x float> @_Z4sqrtDv2_f(<2 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 41float2 call_sqrt_v2f32(float2 x) { 42 return sqrt(x); 43} 44 45 46// CHECK-LABEL: define {{.*}} <3 x float> @call_sqrt_v3f32( 47// DEFAULT: call <3 x float> @_Z4sqrtDv3_f(<3 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 48// CORRECTLYROUNDED: call <3 x float> @_Z4sqrtDv3_f(<3 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 49 50// DEFAULT-UNSAFE: call reassoc nsz arcp contract afn <3 x float> @_Z4sqrtDv3_f(<3 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 51// CORRECTLY-UNSAFE: call reassoc nsz arcp contract afn <3 x float> @_Z4sqrtDv3_f(<3 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 52float3 call_sqrt_v3f32(float3 x) { 53 return sqrt(x); 54} 55 56 57 58// CHECK-LABEL: define {{.*}} <4 x float> @call_sqrt_v4f32( 59// DEFAULT: call <4 x float> @_Z4sqrtDv4_f(<4 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 60// CORRECTLYROUNDED: call <4 x float> @_Z4sqrtDv4_f(<4 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 61 62// DEFAULT-UNSAFE: call reassoc nsz arcp contract afn <4 x float> @_Z4sqrtDv4_f(<4 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 63// CORRECTLY-UNSAFE: call reassoc nsz arcp contract afn <4 x float> @_Z4sqrtDv4_f(<4 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 64float4 call_sqrt_v4f32(float4 x) { 65 return sqrt(x); 66} 67 68 69// CHECK-LABEL: define {{.*}} <8 x float> @call_sqrt_v8f32( 70// DEFAULT: call <8 x float> @_Z4sqrtDv8_f(<8 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 71// CORRECTLYROUNDED: call <8 x float> @_Z4sqrtDv8_f(<8 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 72 73// DEFAULT-UNSAFE: call reassoc nsz arcp contract afn <8 x float> @_Z4sqrtDv8_f(<8 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 74// CORRECTLYROUNDED-UNSAFE: call reassoc nsz arcp contract afn <8 x float> @_Z4sqrtDv8_f(<8 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 75float8 call_sqrt_v8f32(float8 x) { 76 return sqrt(x); 77} 78 79 80 81// CHECK-LABEL: define {{.*}} <16 x float> @call_sqrt_v16f32( 82// DEFAULT: call <16 x float> @_Z4sqrtDv16_f(<16 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 83// CORRECTLYROUNDED: call <16 x float> @_Z4sqrtDv16_f(<16 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 84 85// DEFAULT-UNSAFE: call reassoc nsz arcp contract afn <16 x float> @_Z4sqrtDv16_f(<16 x float> noundef %{{.+}}) #{{[0-9]+}}, !fpmath [[FPMATH]]{{$}} 86// CORRECTLY-UNSAFE: call reassoc nsz arcp contract afn <16 x float> @_Z4sqrtDv16_f(<16 x float> noundef %{{.+}}) #{{[0-9]+}}{{$}} 87float16 call_sqrt_v16f32(float16 x) { 88 return sqrt(x); 89} 90 91 92 93// Not for f64 94// CHECK-LABEL: define {{.*}} double @call_sqrt_f64( 95// CHECK: call {{.*}} double @_Z4sqrtd(double noundef %{{.+}}) #{{[0-9]+$}}{{$}} 96double call_sqrt_f64(double x) { 97 return sqrt(x); 98} 99 100 101// Not for f64 102// CHECK-LABEL: define {{.*}} <2 x double> @call_sqrt_v2f64( 103// CHECK: call {{.*}} <2 x double> @_Z4sqrtDv2_d(<2 x double> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 104double2 call_sqrt_v2f64(double2 x) { 105 return sqrt(x); 106} 107 108 109// CHECK-LABEL: define {{.*}} <3 x double> @call_sqrt_v3f64( 110// CHECK: call {{.*}} <3 x double> @_Z4sqrtDv3_d(<3 x double> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 111double3 call_sqrt_v3f64(double3 x) { 112 return sqrt(x); 113} 114 115 116// CHECK-LABEL: define {{.*}} <4 x double> @call_sqrt_v4f64( 117// CHECK: call {{.*}} <4 x double> @_Z4sqrtDv4_d(<4 x double> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 118double4 call_sqrt_v4f64(double4 x) { 119 return sqrt(x); 120} 121 122 123// CHECK-LABEL: define {{.*}} <8 x double> @call_sqrt_v8f64( 124// CHECK: call {{.*}} <8 x double> @_Z4sqrtDv8_d(<8 x double> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 125double8 call_sqrt_v8f64(double8 x) { 126 return sqrt(x); 127} 128 129 130// CHECK-LABEL: define {{.*}} <16 x double> @call_sqrt_v16f64( 131// CHECK: call {{.*}} <16 x double> @_Z4sqrtDv16_d(<16 x double> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 132double16 call_sqrt_v16f64(double16 x) { 133 return sqrt(x); 134} 135 136 137// Not for f16 138// CHECK-LABEL: define {{.*}} half @call_sqrt_f16( 139// CHECK: call {{.*}} half @_Z4sqrtDh(half noundef %{{.+}}) #{{[0-9]+$}}{{$}} 140half call_sqrt_f16(half x) { 141 return sqrt(x); 142} 143 144 145// CHECK-LABEL: define {{.*}} <2 x half> @call_sqrt_v2f16( 146// CHECK: call {{.*}} <2 x half> @_Z4sqrtDv2_Dh(<2 x half> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 147half2 call_sqrt_v2f16(half2 x) { 148 return sqrt(x); 149} 150 151 152// CHECK-LABEL: define {{.*}} <3 x half> @call_sqrt_v3f16( 153// CHECK: call {{.*}} <3 x half> @_Z4sqrtDv3_Dh(<3 x half> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 154half3 call_sqrt_v3f16(half3 x) { 155 return sqrt(x); 156} 157 158 159// CHECK-LABEL: define {{.*}} <4 x half> @call_sqrt_v4f16( 160// CHECK: call {{.*}} <4 x half> @_Z4sqrtDv4_Dh(<4 x half> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 161half4 call_sqrt_v4f16(half4 x) { 162 return sqrt(x); 163} 164 165 166// CHECK-LABEL: define {{.*}} <8 x half> @call_sqrt_v8f16( 167// CHECK: call {{.*}} <8 x half> @_Z4sqrtDv8_Dh(<8 x half> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 168half8 call_sqrt_v8f16(half8 x) { 169 return sqrt(x); 170} 171 172 173// CHECK-LABEL: define {{.*}} <16 x half> @call_sqrt_v16f16( 174// CHECK: call {{.*}} <16 x half> @_Z4sqrtDv16_Dh(<16 x half> noundef %{{.+}}) #{{[0-9]+$}}{{$}} 175half16 call_sqrt_v16f16(half16 x) { 176 return sqrt(x); 177} 178 179// DEFAULT: [[FPMATH]] = !{float 3.000000e+00} 180