<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Missed vectorization for std::reverse"
   href="https://bugs.llvm.org/show_bug.cgi?id=43664">43664</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed vectorization for std::reverse
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <algorithm>
#include <vector>
#include <cstdint>

void reverse_epi8(std::vector<int32_t>&v) {
    std::reverse(v.begin(),v.begin()+32);
}

void reverse_epi32(std::vector<int32_t>& v) {
    std::reverse(v.begin(),v.begin()+32);
}

Clang does not vectorize std::reverse with -O3 -march=haswell -std=c++11. 
reverse_epi8(std::vector<int, std::allocator<int> >&):     #
@reverse_epi8(std::vector<int, std::allocator<int> >&)
        mov     rax, qword ptr [rdi]
        lea     rcx, [rax + 124]
        add     rax, 4
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
        mov     edx, dword ptr [rax - 4]
        mov     esi, dword ptr [rcx]
        mov     dword ptr [rax - 4], esi
        mov     dword ptr [rcx], edx
        add     rcx, -4
        cmp     rax, rcx
        lea     rax, [rax + 4]
        jb      .LBB0_1
        ret

GCC 8+ vectorizes it.

reverse_epi8(std::vector<int, std::allocator<int> >&):
        mov     rax, QWORD PTR [rdi]
        vmovdqa ymm0, YMMWORD PTR .LC0[rip]
        vmovdqu ymm1, YMMWORD PTR [rax]
        vpermd  ymm2, ymm0, YMMWORD PTR [rax+96]
        vpermd  ymm1, ymm0, ymm1
        vmovdqu YMMWORD PTR [rax], ymm2
        vpermd  ymm2, ymm0, YMMWORD PTR [rax+64]
        vmovdqu YMMWORD PTR [rax+96], ymm1
        vmovdqu ymm1, YMMWORD PTR [rax+32]
        vmovdqu YMMWORD PTR [rax+32], ymm2
        vpermd  ymm0, ymm0, ymm1
        vmovdqu YMMWORD PTR [rax+64], ymm0
        vzeroupper
        ret


<a href="https://godbolt.org/z/gJkt3c">https://godbolt.org/z/gJkt3c</a>


Another issue, with std::reverse(v.begin(), v.begin()+2), there is really bad
codegen:
<a href="https://godbolt.org/z/D-k-SA">https://godbolt.org/z/D-k-SA</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>