-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Emit fpbuiltin version of function only for function with FP arguments. #17253
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
Conversation
floating point type arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
[=](id<1> wiID) { | ||
// NFPA: call spir_func float @fdiv(ptr noundef byval({{.*}}) align 1 {{.*}}, ptr noundef byval({{.*}}) align 1 {{.*}}) | ||
// NFPA-FAST: call reassoc nnan ninf nsz arcp afn spir_func nofpclass(nan inf) float @fdiv(ptr noundef byval({{.*}}) align 1 {{.*}}, ptr noundef byval({{.*}}) align 1 {{.*}}) | ||
a[0] = fdiv(HalfValue1, HalfValue2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, if it is a real-world example, do e have fdiv builtin in SYCL/OpenCL/C++?. What about a[0] = Value1 / Value2;
, can the issue be observed in this case and does your patch fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MrSidims Thanks for the review. Fixed it.
clang/lib/CodeGen/CGCall.cpp
Outdated
// as fpbuiltins. | ||
if (!getLangOpts().OffloadFP32PrecSqrt || | ||
!getLangOpts().OffloadFP32PrecDiv) { | ||
for (auto Arg : IRCallArgs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (if applicable): to avoid some static analyzers complains about 'auto causes copy'.
for (auto Arg : IRCallArgs) { | |
for (auto &Arg : IRCallArgs) { |
|
||
#include "sycl.hpp" | ||
|
||
namespace sycl { | ||
class half {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's important, that we properly define sycl::half class aka add to it half storage. So /
operator mustn't be extern - instead it should have a definition. Otherwise the code here doesn't test the issue - I'm pretty sure, that _ZdvN4sycl4halfES0_
would never become llvm.fpbuiltin intrinsic anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a minimalist class half
.
clang/lib/CodeGen/CGCall.cpp
Outdated
if (hasFPAccuracyFuncMap || hasFPAccuracyVal || isFp32SqrtFunction) { | ||
bool ArgsTypeIsFloat = true; | ||
// In sycl mode, functions' arguments of type half are expanded | ||
// to pointer types. Exclude these functions from bein emitted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// to pointer types. Exclude these functions from bein emitted | |
// to pointer types. Exclude these functions from being emitted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am okay with the changes.
@intel/llvm-gatekeepers Can this be merged in please? |
@sarnex Thanks. |
sure |
When the arguments of a function are of half types, such as
sqrt(half_type v)
they are expanded to:load ptr addrspace(4), ptr addrspace(4) %a.addr.ascast, align 8, !tbaa !5
This will generate a crash in the BE due to type mismatch. The expected type of the function is
float
.This patch fixes the issue by restricting the emission of
fpbuiltin
only to functions that take floating point values arguments.