Skip to content

Commit

Permalink
[SYCL] Enable more clang builtins for SYCL device compiler (#3060)
Browse files Browse the repository at this point in the history
This patch enables math builtins supported by LLVM-SPIRV-Translator:
fmax/f (depends on llvm.maxnum)
fmin/f (depends on llvm.minnum)
isinf (depends on llvm.fabs)
isfinite (depends on llvm.fabs)
isnormal (depends on llvm.fabs)
fpclassify (depends on llvm.fabs)

Signed-off-by: gejin <ge.jin@intel.com>
  • Loading branch information
jinge90 authored Jan 22, 2021
1 parent 83c897e commit 1040b94
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
12 changes: 0 additions & 12 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,8 @@ static bool IsSyclMathFunc(unsigned BuiltinID) {
case Builtin::BI__builtin_truncl:
case Builtin::BIlroundl:
case Builtin::BI__builtin_lroundl:
case Builtin::BIfmax:
case Builtin::BI__builtin_fmax:
case Builtin::BIfmin:
case Builtin::BI__builtin_fmin:
case Builtin::BIfmaxf:
case Builtin::BI__builtin_fmaxf:
case Builtin::BIfminf:
case Builtin::BI__builtin_fminf:
case Builtin::BIlroundf:
case Builtin::BI__builtin_lroundf:
case Builtin::BI__builtin_fpclassify:
case Builtin::BI__builtin_isfinite:
case Builtin::BI__builtin_isinf:
case Builtin::BI__builtin_isnormal:
return false;
default:
break;
Expand Down
83 changes: 50 additions & 33 deletions clang/test/SemaSYCL/supported_math.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-strict -verify %s
// expected-no-diagnostics
extern "C" float sinf(float);
extern "C" float cosf(float);
extern "C" float floorf(float);
Expand All @@ -8,6 +9,8 @@ extern "C" float rintf(float);
extern "C" float roundf(float);
extern "C" float truncf(float);
extern "C" float copysignf(float, float);
extern "C" float fminf(float, float);
extern "C" float fmaxf(float, float);
extern "C" double sin(double);
extern "C" double cos(double);
extern "C" double floor(double);
Expand All @@ -17,6 +20,8 @@ extern "C" double rint(double);
extern "C" double round(double);
extern "C" double trunc(double);
extern "C" double copysign(double, double);
extern "C" double fmin(double, double);
extern "C" double fmax(double, double);
template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
kernelFunc();
Expand All @@ -26,39 +31,51 @@ int main() {
kernel<class kernel_function>([=]() {
int acc[1] = {5};
acc[0] *= 2;
acc[0] += (int)truncf(1.0f); // expected-no-diagnostics
acc[0] += (int)trunc(1.0); // expected-no-diagnostics
acc[0] += (int)roundf(1.0f); // expected-no-diagnostics
acc[0] += (int)round(1.0); // expected-no-diagnostics
acc[0] += (int)rintf(1.0f); // expected-no-diagnostics
acc[0] += (int)rint(1.0); // expected-no-diagnostics
acc[0] += (int)nearbyintf(0.5f); // expected-no-diagnostics
acc[0] += (int)nearbyint(0.5); // expected-no-diagnostics
acc[0] += (int)floorf(0.5f); // expected-no-diagnostics
acc[0] += (int)floor(0.5); // expected-no-diagnostics
acc[0] += (int)copysignf(1.0f, -0.5f); // expected-no-diagnostics
acc[0] += (int)copysign(1.0, -0.5); // expected-no-diagnostics
acc[0] += (int)sinf(1.0f); // expected-no-diagnostics
acc[0] += (int)sin(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_sinf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_sin(1.0); // expected-no-diagnostics
acc[0] += (int)cosf(1.0f); // expected-no-diagnostics
acc[0] += (int)cos(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_cosf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_cos(1.0); // expected-no-diagnostics
acc[0] += (int)logf(1.0f); // expected-no-diagnostics
acc[0] += (int)log(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_truncf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_trunc(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_rintf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_rint(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_nearbyintf(0.5f); // expected-no-diagnostics
acc[0] += (int)__builtin_nearbyint(0.5); // expected-no-diagnostics
acc[0] += (int)__builtin_floorf(0.5f); // expected-no-diagnostics
acc[0] += (int)__builtin_floor(0.5); // expected-no-diagnostics
acc[0] += (int)__builtin_copysignf(1.0f, -0.5f); // expected-no-diagnostics
acc[0] += (int)__builtin_logf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_log(1.0); // expected-no-diagnostics
acc[0] += (int)truncf(1.0f);
acc[0] += (int)trunc(1.0);
acc[0] += (int)roundf(1.0f);
acc[0] += (int)round(1.0);
acc[0] += (int)rintf(1.0f);
acc[0] += (int)rint(1.0);
acc[0] += (int)nearbyintf(0.5f);
acc[0] += (int)nearbyint(0.5);
acc[0] += (int)floorf(0.5f);
acc[0] += (int)floor(0.5);
acc[0] += (int)copysignf(1.0f, -0.5f);
acc[0] += (int)copysign(1.0, -0.5);
acc[0] += (int)fminf(1.5f, 0.5f);
acc[0] += (int)fmin(1.5, 0.5);
acc[0] += (int)fmaxf(1.5f, 0.5f);
acc[0] += (int)fmax(1.5, 0.5);
acc[0] += (int)sinf(1.0f);
acc[0] += (int)sin(1.0);
acc[0] += (int)__builtin_sinf(1.0f);
acc[0] += (int)__builtin_sin(1.0);
acc[0] += (int)cosf(1.0f);
acc[0] += (int)cos(1.0);
acc[0] += (int)__builtin_cosf(1.0f);
acc[0] += (int)__builtin_cos(1.0);
acc[0] += (int)logf(1.0f);
acc[0] += (int)log(1.0);
acc[0] += (int)__builtin_truncf(1.0f);
acc[0] += (int)__builtin_trunc(1.0);
acc[0] += (int)__builtin_rintf(1.0f);
acc[0] += (int)__builtin_rint(1.0);
acc[0] += (int)__builtin_nearbyintf(0.5f);
acc[0] += (int)__builtin_nearbyint(0.5);
acc[0] += (int)__builtin_floorf(0.5f);
acc[0] += (int)__builtin_floor(0.5);
acc[0] += (int)__builtin_copysignf(1.0f, -0.5f);
acc[0] += (int)__builtin_fminf(1.5f, 0.5f);
acc[0] += (int)__builtin_fmin(1.5, 0.5);
acc[0] += (int)__builtin_fmaxf(1.5f, 0.5f);
acc[0] += (int)__builtin_fmax(1.5, 0.5);
acc[0] += (int)__builtin_logf(1.0f);
acc[0] += (int)__builtin_log(1.0);
acc[0] += __builtin_isinf(1.0);
acc[0] += __builtin_isfinite(1.0);
acc[0] += __builtin_isnormal(1.0);
acc[0] += __builtin_fpclassify(0, 1, 4, 3, 2, 1.0);
});
return 0;
}

0 comments on commit 1040b94

Please sign in to comment.