Skip to content

Commit fc205f3

Browse files
frasercrmckKornevNikita
authored andcommitted
[SYCL] Stop emission of modf intrinsic for NVPTX/AMDGCN (#17958)
A recent change in #126750 changed the lowering of the modf builtin(s) to lower to the llvm.modf intrinsic. Certain SYCL targets such as NVPTX and AMDGCN cannot currently handle this intrinsic in the backend because they don't have the necessary target library info. Even if they did, the SYCL device libraries are linked in earlier at the IR level so we'd be left with an unresolved symbol. We have been working around this at clang codegen time by avoiding the emission of intrinsics altogether by (ab)using a guard on math intrinsics. The problem with us hooking into GenerateIntrinsics like this is that SYCL is wanting to use it as a guarantee that (a certain subset of) intrinsics won't be emitted if GenerateIntrinsics is false, whereas upstream does not make this guarantee: it's an opt-in toggle for a more optimal lowering strategy. Thus we're always going to be liable to this sort of upstream change. This doesn't feel like the right mechanism for SYCL to handle these builtins (or intrinsics) long term, but this fix restores the previous behaviour without making things much worse. Fixes the AMDGCN/NVPTX aspects of #17813
1 parent f078780 commit fc205f3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,9 +3025,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
30253025
GenerateIntrinsics =
30263026
ConstWithoutErrnoOrExceptions && ErrnoOverridenToFalseWithOpt;
30273027
}
3028-
if (GenerateIntrinsics &&
3029-
!(getLangOpts().SYCLIsDevice && (getTarget().getTriple().isNVPTX() ||
3030-
getTarget().getTriple().isAMDGCN()))) {
3028+
bool IsSYCLDeviceWithoutIntrinsics =
3029+
getLangOpts().SYCLIsDevice &&
3030+
(getTarget().getTriple().isNVPTX() || getTarget().getTriple().isAMDGCN());
3031+
if (GenerateIntrinsics && !IsSYCLDeviceWithoutIntrinsics) {
30313032
switch (BuiltinIDIfNoAsmLabel) {
30323033
case Builtin::BIacos:
30333034
case Builtin::BIacosf:
@@ -4102,7 +4103,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41024103
case Builtin::BI__builtin_modf:
41034104
case Builtin::BI__builtin_modff:
41044105
case Builtin::BI__builtin_modfl:
4105-
if (Builder.getIsFPConstrained())
4106+
if (Builder.getIsFPConstrained() || IsSYCLDeviceWithoutIntrinsics)
41064107
break; // TODO: Emit constrained modf intrinsic once one exists.
41074108
return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
41084109
case Builtin::BI__builtin_isgreater:

0 commit comments

Comments
 (0)