Issue |
127196
|
Summary |
[libclc] CLC (ab)uses ASM labels to emit llvm intrinsics instead of using Clang Builtins
|
Labels |
clang
|
Assignees |
|
Reporter |
Maetveis
|
LibCLC uses the [Asm labels][1] feature to directly call LLVM intrinsic functions from OpenCL code.
For an example overloads of `__clc_round`
https://github.com/llvm/llvm-project/blob/1b6340d9c3b75c29dec5218dbab2bb8194edfc1e/libclc/generic/lib/math/round.cl#L3-L6
https://github.com/llvm/llvm-project/blob/1b6340d9c3b75c29dec5218dbab2bb8194edfc1e/libclc/clc/include/clc/math/unary_intrin.inc#L29
would look roughly like the following after preprocessing:
```opencl
__attribute__((overloadable)) half8 __clc_round(half8 d) __asm("llvm.round.v8f16");
```
For many (all?) intrinsics that are called like this Clang has builtins that lower to the same llvm intrinsics. For the above example `__builtin_round` or `__builtin_elementwise_round` could be used instead.
This might be problem because Clang will emit different IR when it knows it's calling an intrinsic and not a real function. Such unusual IR would then might need to be worked around in the LLVM backends of targets.
As an example for the SPIR-V target function calls receive the `spir_func` calling convention by default, while intrinsic calls will not. [Demonstration on Compiler Explorer][2]
[1]: https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels.html#Assembler-names-for-functions
[2]: https://godbolt.org/z/1hr9oKxPG
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs