<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67703>67703</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang][GPU] Clang emits unsupported intrinsic calls for math functions on NVPTX and AMDGPU
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jhuber6
</td>
</tr>
</table>
<pre>
The Clang frontend will eagerly replace definitions like `sin` with the LLVM intrinsic version. This is enabled by various default configurations on the GPU target, e.g. `-fno-math-errno`. This is problematic because it prevent us from linking in implementations of math functions, such as from the work-in-progress `libc` math library for GPUs. These intrinsics are the not handled by the backend. See https://godbolt.org/z/3za6f1edY for an example of this behavior. Passing `-fmath-errno` causes it to emit regular `sin` calls.
This is currently not an issue with the CUDA / OpenMP / HIP toolchains because they eagerly replace calls to `sin` with calls to `__nv_sin` which are not recognized as library calls.
The typical solution for unsupported intrinsic calls for LLVM is to simply lower the intrinsic call to its associated library call in the backend. This is problematic for the GPU because we prefer to do static LTO linking, meaning that we will link in definitions before the backend has run. Because of this, it's likely that a static library will not extract the symbol and it will be unresolved.
One solution is to prevent this lowering in all cases for the GPU. Many implementations once linked will likely resolve to builtin implementations anyway. Another solution is to have a lowering pass that's run before LTO linking that resolves unknown library calls to regular calls so we can get back the original version before the backend is run.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVUFv2zgT_TX0ZRBBliM5PviQNnC_D2i2BjYpdk_FiBpJbOihQVJ21V-_GMraOG2AvSQGRc6bee_NDIZgOibaqvKDKh8WOMTe-e33fqjJV4vaNeP2qSf4aJE7aL3jSNzA2VgLhB15O4Kno0VN0FBr2ETjOIA1LwSqyoNhVeVwNrGH2BN8_vz1EQxHbzgYDSfywTjO4Kk3AUwAYqwtNVCPcEJv3BAkLA42gnbcmm7wOCE4TgE_7Z8hou8oquIjUNZlAnvTsrs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