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

    <tr>
        <th>Summary</th>
        <td>
            Missed autovectorization opportunity
        </td>
    </tr>

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

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

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

<pre>
    Got a report of a simple loop that should autovectorize but does not do so on aarch64 (but does on x86 / AVX512). Repro:

```
#include <stdint.h>
#include <stdlib.h>

void noAutovec(uint32_t* __restrict ip, float* __restrict src, float* __restrict dst, size_t n) {
   //  If you encourage the compile with the `#pragma` this does autovectorize.
   // #pragma clang loop vectorize(enable)
    for (size_t i=0; i<n; ++i) {
 uint32_t idx = ip[i];
      dst[i] = src[idx];
    }
}
```

This vectorizes on x86 (`clang -march=haswell -mavx512f -O3`) but does not on aarch64 in my experiments (`clang -target aarch64-redhat-linux-gnu -march=armv9-a+sve2+fp16`).

Using `#pragma clang loop vectorize(enable)` makes vectorization work on aarch64. So this hints at the cost-model rejecting things (I assume vectorization should be beneficial when SVE is available).

(this mirror meta T222824954 )
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVE2P4zYM_TXKhUjgSP7SwYd4s1PsYVGgu130NpBt2mZXlgxJzmTm1xeKM5lk0aKAYAsiRfI9PlF5T4NBrFhWs-y4UUsYrau-qvCG9aax3Wv1mw2gwOFsXQDbgwJP06wRtLUzhFEF8KNddAdqCfaEbbCO3hCaJUBn0YOxcQPegjWglGvHPAXGy5uDNXAuc2D8CQ4__sr2nHG5gz9wdpaJA0suK0-uKzkwLsi0eukQmPjkQ0cm7EYmPv-bTVNzsyWHk6UOjD2slTJeLmSC4M-B8QM8Pzv0wVEbgGbGP0GvrfrV4l37X6bOh2jy9IbPAQzjElhRs-QAEMFFfPClh1e7AJrWLk4NCGFEaO00k0Z4oTBeDiJOLmanhkmxPIEwkl-5euB49xD7dgNarcyw9ufmy3iJRjUaGZfrNeiti3241ktMHBMm6rj5ZOKG8Zrxmu5wvLMF1J2BiWPkKauJZUcmrkABLjyspxefyFhWU3d-cGPFMbZk_d43Nzl8j2hvhd_po2R5smLbTlFHTBxH5V9Q63hwOmd73sP2d3GhTz4q8E57ZGB6BTzP6GhCE_xj6KDcgOHde-uwG1XYajLLeTuY5SO3ctNJbhXjtT8hZ7zu532-5t6tSP70ZIaHbv5_b_IEJvUTPxhQgayBF-t-3oHYwTe7ymKkiECFq5J82E62Qw0O_8Y2xPxhJDNcQH4B5f0y4S-xr--3QWjQYE8tKQ0vIxr49uMzkAd1UqSvBV6hMV5e0k_knHUwYVDwnXNe8lRm8X3LTVeJTgqpNljtizSTuSzKdDNWmZKiKPpCNTIRok_LskepJM_lXia83W-o4gnPkpRLLkTO011eFIXKu6LM2jTtUbI0wUmR3ml9mnbWDRvyfsFqL4pSphutGtT-faa5Knptm2XwLE00-eA_7gUKGquv5D0-DrCVGTvHsbcYCq-bxelqDGH2cShdntxAYVyaXWsnxp9iyOtvOzsbyWf86VKXZ_zpWtqp4v8EAAD__5rguRM">