Skip to content

[SYCL]Support LLVM FP intrinsic in llvm-spirv and enable the corresponding … #2880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,38 +165,14 @@ static bool IsSyclMathFunc(unsigned BuiltinID) {
case Builtin::BI__builtin_truncl:
case Builtin::BIlroundl:
case Builtin::BI__builtin_lroundl:
case Builtin::BIcopysign:
case Builtin::BI__builtin_copysign:
case Builtin::BIfloor:
case Builtin::BI__builtin_floor:
case Builtin::BIfmax:
case Builtin::BI__builtin_fmax:
case Builtin::BIfmin:
case Builtin::BI__builtin_fmin:
case Builtin::BInearbyint:
case Builtin::BI__builtin_nearbyint:
case Builtin::BIrint:
case Builtin::BI__builtin_rint:
case Builtin::BIround:
case Builtin::BI__builtin_round:
case Builtin::BItrunc:
case Builtin::BI__builtin_trunc:
case Builtin::BIcopysignf:
case Builtin::BI__builtin_copysignf:
case Builtin::BIfloorf:
case Builtin::BI__builtin_floorf:
case Builtin::BIfmaxf:
case Builtin::BI__builtin_fmaxf:
case Builtin::BIfminf:
case Builtin::BI__builtin_fminf:
case Builtin::BInearbyintf:
case Builtin::BI__builtin_nearbyintf:
case Builtin::BIrintf:
case Builtin::BI__builtin_rintf:
case Builtin::BIroundf:
case Builtin::BI__builtin_roundf:
case Builtin::BItruncf:
case Builtin::BI__builtin_truncf:
case Builtin::BIlroundf:
case Builtin::BI__builtin_lroundf:
case Builtin::BI__builtin_fpclassify:
Expand Down
64 changes: 64 additions & 0 deletions clang/test/SemaSYCL/supported_math.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-strict -verify %s
extern "C" float sinf(float);
extern "C" float cosf(float);
extern "C" float floorf(float);
extern "C" float logf(float);
extern "C" float nearbyintf(float);
extern "C" float rintf(float);
extern "C" float roundf(float);
extern "C" float truncf(float);
extern "C" float copysignf(float, float);
extern "C" double sin(double);
extern "C" double cos(double);
extern "C" double floor(double);
extern "C" double log(double);
extern "C" double nearbyint(double);
extern "C" double rint(double);
extern "C" double round(double);
extern "C" double trunc(double);
extern "C" double copysign(double, double);
template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
kernelFunc();
}

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
});
return 0;
}
24 changes: 3 additions & 21 deletions clang/test/SemaSYCL/unsupported_math.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify %s
extern "C" float sinf(float);
extern "C" float cosf(float);
extern "C" float logf(float);
extern "C" double sin(double);
extern "C" double cos(double);
extern "C" double log(double);
template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
kernelFunc();
Expand All @@ -14,21 +8,9 @@ int main() {
kernel<class kernel_function>([=]() {
int acc[1] = {5};
acc[0] *= 2;
acc[0] += (int)sinf(1.0f); // expected-no-error
acc[0] += (int)sin(1.0); // expected-no-error
acc[0] += (int)__builtin_sinf(1.0f); // expected-no-error
acc[0] += (int)__builtin_sin(1.0); // expected-no-error
acc[0] += (int)cosf(1.0f); // expected-no-error
acc[0] += (int)cos(1.0); // expected-no-error
acc[0] += (int)__builtin_cosf(1.0f); // expected-no-error
acc[0] += (int)__builtin_cos(1.0); // expected-no-error
acc[0] += (int)logf(1.0f); // expected-no-error
acc[0] += (int)log(1.0); // expected-no-error
acc[0] += (int)__builtin_logf(1.0f); // expected-no-error
acc[0] += (int)__builtin_log(1.0); // expected-no-error
acc[0] += (int)__builtin_fabsl(-1.0); // expected-error{{builtin is not supported on this target}}
acc[0] += (int)__builtin_cosl(-1.0); // expected-error{{builtin is not supported on this target}}
acc[0] += (int)__builtin_powl(-1.0, 10.0); // expected-error{{builtin is not supported on this target}}
acc[0] += (int)__builtin_fabsl(-1.0); // expected-error{{builtin is not supported on this target}}
acc[0] += (int)__builtin_cosl(-1.0); // expected-error{{builtin is not supported on this target}}
acc[0] += (int)__builtin_powl(-1.0, 10.0); // expected-error{{builtin is not supported on this target}}
});
return 0;
}