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

    <tr>
        <th>Summary</th>
        <td>
            [FMV] incorrect codegen when there is no TU-local caller
        </td>
    </tr>

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

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

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

<pre>
    https://clang.godbolt.org/z/heoTnxqz5

Compare:
```
__attribute__((target_version("dotprod+lse")))
int foo(void) { return 1; }

__attribute__((target_version("default")))
int foo(void) { return 0; }

#ifdef HAS_CALLER
int caller(void) { return foo(); }
#endif
```

```
--rtlib=compiler-rt -O2 -DHAS_CALLER=1
```
vs
```
--rtlib=compiler-rt -O2
```

While GCC's version has self-consistent and correct behavior, IMO it would be better to always emit the weak ifunc+resolver along with the definition of the `default` version so you can forward-declare the not-attributed version of the function and call these from any other TU.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVN2uozYQfhpzMyICAwEuuMhPaSvtaqX2bHsZGTyAt44ntYek2aev4GTPbquo6kpWIj7x_YyHGRWCGR1iI4q9KI6Rmnki33zyhJaGEHWk783EfAki2wnZCtn2VrlxM5LuyPKG_Chk-1nIdkJ6cX_9-bkQyVEku9ffA50vyuNCfkW3yeOsj6eTYvammxlPJyErIStWfkQ-XdEHQ27FpCa-eNJC7m1AIaWQ9eOsKsYxDERCVlcyWsgaRLkHjzx7B6nI9iDK47ep_q8tDmq2_J2GyRNDITMzaBzgp92vp8Pu3bsffvmq1Ctr0T8Xe3VZjP8hKjN02gxP7_QpGMeerelEduzpfDEWfewZ4g8S4uM3mbJj-pR-Dd-n-h_Bfp-MRfjxcBCyDPC4b5hUgIB2iHtywQRGx6Cchp68x56hw0ldDXkhD_Dz-w9gGG40Ww0dQofM6IEJlL2pewA8GwaeEG6o_gAzzK4Xcu8xkL2iB2XJjXAzPK0vaRyMM7ykoGFFxDb50vpt8hYxENxphl4tXfE35XWssbfK40pyxPHbV6XfWA_JJcNqsRalrF3QgDB4OoNydyCe0MPLx02km0zXWa0ibNIyKcsiz8sqmpqir1Ls0kHWXVpLpbdlUWa13HZJnndZnUemkYnME5nKdJvmWbXBtFJbratadcWQVlrkCZ6VsRtrr-dlciMTwoxNleZ1HlnVoQ3rIpByHXKR7XrSOKJbRqA4Rr5ZmHE3j0HkiTWBw1ctNmzXPdK-_00URzDuS_MeInCb0C11ewQTwBG8fIwt9co-RiCavf3XshkNT3O36eksZLtYPf7ii6dP2LOQ7VpDELJdy_g7AAD__32Detc">