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

    <tr>
        <th>Summary</th>
        <td>
            C++ Range view filters prevent vectorization.
        </td>
    </tr>

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

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

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

<pre>
    As of now, C++ range adapters pipelines that invoke std::ranges::views::filter prevent vectorization, where the equivalent imperative algorithm vectorizes normally. This is true with both the libstdc++ and the libc++. Note that the same thing happens for GCC.
The only discussion I've found about the problem was by Bryce Adelstein Lelbach in [episode 124 of ADSP.](https://youtu.be/m-I5OMGNm5U)

Here is a [Godbolt](https://flux.godbolt.org/z/T8hPW1GKq) link showcasing the issue.
I've added a version using Tristan Brindle's Flux library, which does vectorize properly due to its iteration logic.

What I'm yet unclear about, is whether this is just an implementation detail that might get ironed out eventually, or if there is something in the standard specification of the C++ ranges that prevents this kind of optimization. Bryce Adelstein Lelbach asserts that this is due to the non-shape preserving nature of the filter adaptor, but couldn't a standard library implementation do the same kind of consumer analysis that Flux does, or would that go against some aspect of the standard?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VF-T2jYQ_zTiZec8RuAADzzA3XDNtE0zzXXyLFuLvTlZcrQrCPn0Hdmm10zTF7AtafXb3581zNR6xL2qjqp6WpgkXYj7Tzd3Mf4YQ2OiXdTB3vYHhnAGH65KP8Kj0keljxCNbxGMNYNgZBhoQEceGaQzAuQv4RWBxarVQa0O426eni-E1_nxTE4wwhDxgl7ggo2ESN-NUPD5smuHEUE6BPya6GJc3kX9gNEIXRCMa0Mk6fp_jiKDD7E3zt0KeOmIgRgkJoQrSQd1kG6s56hmsc3cjPH2_nX-VMCHIDg1k1fY9PmNfAudGQb0DOcQ4fnxsVDlkyoPLx1C8O4Glrh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