<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/127196>127196</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libclc] CLC (ab)uses ASM labels to emit llvm intrinsics instead of using Clang Builtins
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Maetveis
      </td>
    </tr>
</table>

<pre>
    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
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VU2v6jYQ_TVmMyJKHALJggUXSvVUrvr0bvW2yB-TxL2OjWwHLv31lZ1cHn3qpptKiCixPT4zc84Z5r3qDOKWVC-kOizYGHrrtq8MwxWVX3Ar79uT4vvTHkaPHkKPQKqXnR9AM47ak-pAqpeCVAdokYXRIQQLUjkUQd9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