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

    <tr>
        <th>Summary</th>
        <td>
            ARM backend aggressively pessimizes code with broadcasted constants
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    I'm having a lot of trouble with the arm (32 and 64 bit) backends de-optimizing code related to broadcasted constants. There are several issues:

- LLVM attempts to observe constants through memory, and propagate them.
- LLVM moves broadcasts into loops.
- LLVM spills broadcasts by redoing the broadcast, rather than spilling and reloading a vector.

Here's an example that demonstrates several issues: https://godbolt.org/z/chjx4d4vh

If the compiler would compile the code as written, there would be no register spills, because the constants would occupy half as many registers. I included a commented call to `make_opaque` that is one attempted workaround, to trick the compiler into not thinking these are constants (at the expense of a function call...), and it does work to do that, but the compiler still moves the broadcasts (`dup` instructions) out of the loop and spills some of the registers.

I run into this issue very frequently. Any suggested workarounds, e.g. some annotation to force the compiler to keep a broadcast outside of the loop, or other possible, fixes would be very welcome. As it stands, I find `vmla_lane_X` intrinsics to be almost useless because of this issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVEGP4jgT_TXhUuooGJqGQw79fSO0Lc1cVqvV3kaVuEg8OK6MqwLN_PqVHWia3b0AIfar9169KhRxXSCqi-f_Fc9fFjhpz7G20mP0pIuG7aV-K8zLAD2eXOgAwbMCH0AjT40nODvtQXsCjAMUZrsygMHCZg2N08LsoMH2SMEKWHriUd3gfiWgli1BJI9KFpShiYy2RUmPLQdRDCol_NFTTNgEQieK6MGJTCTF6rWovhTV9fMJvn798xugKg2jSgLkRiie6A4G2keeuh4GGjheCvP_zHSMPGKHSknFUD7gDXwiuVMTcEEZPPMojwdldN4_nGwuEMlykprc-XiTykbUniJoj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