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

    <tr>
        <th>Summary</th>
        <td>
            Static array indices in function parameter declarations cause poor SIMD code-generation
        </td>
    </tr>

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

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

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

<pre>
    Static array indices in function parameter declarations poorly interfere with lowering of SIMD load-and-splat instructions, causing Clang/LLVM to generate separate full-vector load + vector-to-vector broadcast instructions. Here's the simplest example ([repro in Compiler Explorer](https://gcc.godbolt.org/z/75sfdsGzz)):

```c
#include <stddef.h>

#include <wasm_simd128.h>

struct minmax_params {
  float min[2];
  float max[2];
};

v128_t f(const struct minmax_params params[1])
{
    // Generates v128.load64_splat as expected
    return wasm_v128_load64_splat(&params->min);
}

v128_t g(const struct minmax_params params[static 1])
{
    // Generates two instructions: v128.load + i8x16.shuffle
    return wasm_v128_load64_splat(&params->min);
}
```

The example above is for WebAssembly SIMD, but this issue is not specific to this backend and can be reproduced at least on ARM as well.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVE1v2zAM_TX2hYhhy4mTHHxo048NaC_bsB0DWaITbbJlSHKT9tePkps1bXfYhgG2JZkUyUfysTHysf7suVcCuLX8EVQvlUBHK7RjL7wyPQzc8g49WpAoNB3CXweDMVaHGyRp0SIclN-DNge0qt-BaeHzx_sr-sHljPdy5gbNPak7b8do2CVsA4KPLqhvNO93Cbu5u_t6D97ADnskTwgOg3_atKPWswcU3thoFBJ2CdN55s1J0lgSCe5ee8rgA0WYsKUDvyebqhs0kg4eediRqVWyuLQ4WBOgb0w3KE2Ar4-DNhZtsrgilb33g0vKCwqTnp0Q2c7IxmifGRtif6J3uXCtdLdPtF-Hh7TzqyQ_fat8esTzmZWqF3qUFEK5cV5KbLN9Ul6_uvRK6cBdtyUAsmCrd6oTYuhU3_HjNhbOQbK8nKQALSUuigktC6DKtyJ-fCtKlmf7-H0g11sPLaVEUHI9_NbttJC1ImZvfbL2yyPAlEi4fa61g2A5C8Wt5tupX7ijIg1UW5Qv9yz60fYQUxGDOb8SasmqyfuM8hPQhkKcwXmPZfeHWNxElr-A5A_mddOXFy8wYw-r1bGoMrcf21bj_wZ5arhzzF-IAqfO5415QFAOWiLPN2wunMOuIV4H8gaCNqMnzpCCcm6Mmr2hLFFJVEuZIKpGacPFD-wlENOJ0z00CJFOchRIfz1oDKSkcXLx6T5U9YBaZynWRVWt8-ViztaprEu5Ltc89cpr_OfBFEYKxvE0TSBhJM6e5wkppKPV9Rsq0-Qam0yYjg5aP5yWGQH4Tr1Hx4ieJtbNYl2wPN3XTdU2zQor3q5yWTaFqLBcsGKVl8uWL3JMNW9Qu5qaJmGsx8OUQNpT76SqZjljRcFYnuflfJ6xdl6i4HnJl7lcF4tknmPHlc5CHGG-pLaOITXjzpFQK-fdi5A7p3Y9YnRH9vno98bW9yEpj-5JPPE0uq9j-D8BXl7oNg">