Skip to content

[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

Merged
merged 7 commits into from
Mar 6, 2025
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
17 changes: 16 additions & 1 deletion clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5905,7 +5905,22 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
bool isFp32SqrtFunction =
(FuncName == "sqrt" && !getLangOpts().OffloadFP32PrecSqrt &&
IsFloat32Type);
if (hasFPAccuracyFuncMap || hasFPAccuracyVal || isFp32SqrtFunction) {
bool ArgsTypeIsFloat = true;
// In sycl mode, functions' arguments of type half are expanded
// to pointer types. Exclude these functions from being emitted
// as fpbuiltins.
if (!getLangOpts().OffloadFP32PrecSqrt ||
!getLangOpts().OffloadFP32PrecDiv) {
for (auto &Arg : IRCallArgs) {
if (!Arg->getType()->isFPOrFPVectorTy() &&
!Arg->getType()->isIntOrIntVectorTy()) {
ArgsTypeIsFloat = false;
break;
}
}
}
if (ArgsTypeIsFloat &&
(hasFPAccuracyFuncMap || hasFPAccuracyVal || isFp32SqrtFunction)) {
CI = MaybeEmitFPBuiltinofFD(IRFuncTy, IRCallArgs, CalleePtr,
FD->getName(), FD->getBuiltinID());
if (CI)
Expand Down
136 changes: 136 additions & 0 deletions clang/test/CodeGenSYCL/Inputs/half_type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#define __SYCL_CONSTEXPR_HALF constexpr
using StorageT = _Float16;

class half {
public:
half() = default;
constexpr half(const half &) = default;
constexpr half(half &&) = default;

__SYCL_CONSTEXPR_HALF half(const float &rhs) : Data(rhs) {}

constexpr half &operator=(const half &rhs) = default;

__SYCL_CONSTEXPR_HALF half &operator/=(const half &rhs) {
Data /= rhs.Data;
return *this;
}

#define OP(op, op_eq) \
__SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \
const half rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend double operator op(const half lhs, \
const double rhs) { \
double rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend double operator op(const double lhs, \
const half rhs) { \
double rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend float operator op(const half lhs, \
const float rhs) { \
float rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend float operator op(const float lhs, \
const half rhs) { \
float rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \
const int rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const int lhs, \
const half rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \
const long rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const long lhs, \
const half rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const half lhs, \
const long long rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const long long lhs, \
const half rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const half &lhs, \
const unsigned int &rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const unsigned int &lhs, \
const half &rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const half &lhs, \
const unsigned long &rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const unsigned long &lhs, \
const half &rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op( \
const half &lhs, const unsigned long long &rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
} \
__SYCL_CONSTEXPR_HALF friend half operator op(const unsigned long long &lhs, \
const half &rhs) { \
half rtn = lhs; \
rtn op_eq rhs; \
return rtn; \
}
OP(/, /=)

#undef OP

// Operator float
__SYCL_CONSTEXPR_HALF operator float() const {
return static_cast<float>(Data);
}

private:
__SYCL_CONSTEXPR_HALF StorageT getFPRep() const { return Data; }

StorageT Data;
};

Loading
Loading