<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Failure to beneficially vectorize 'copyable' elements in integer binary ops"
   href="https://llvm.org/bugs/show_bug.cgi?id=30787">30787</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Failure to beneficially vectorize 'copyable' elements in integer binary ops
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>a.bataev@hotmail.com, andrew.v.tischenko@gmail.com, llvm-bugs@lists.llvm.org, mkuper@google.com, spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We successfully vectorize:

// clang -O3 -march=btver2

void add0(int * __restrict dst, const int * __restrict src) {
  *dst++ = *src++ + 1;
  *dst++ = *src++ + 1;
  *dst++ = *src++ + 2;
  *dst++ = *src++ + 3;
}

add0(int*, int const*):
        vmovdqu xmm0, xmmword ptr [rsi]
        vpaddd  xmm0, xmm0, xmmword ptr [rip + .LCPI0_0]
        vmovdqu xmmword ptr [rdi], xmm0
        ret

But fail to do so if one or more elements simplify to a simple copy. If the
cost model says it would still be beneficial we should vectorize such cases:

void add1(int * __restrict dst, const int * __restrict src) {
  *dst++ = *src++ + 0;
  *dst++ = *src++ + 1;
  *dst++ = *src++ + 2;
  *dst++ = *src++ + 3;
}

add1(int*, int const*):
        mov     ecx, dword ptr [rsi + 4]
        mov     eax, dword ptr [rsi]
        mov     edx, dword ptr [rsi + 8]
        inc     ecx
        mov     dword ptr [rdi], eax
        add     edx, 2
        mov     dword ptr [rdi + 4], ecx
        mov     ecx, dword ptr [rsi + 12]
        mov     dword ptr [rdi + 8], edx
        add     ecx, 3
        mov     dword ptr [rdi + 12], ecx
        ret

Similarly for SUB/MUL/SHL/LSHR/ASHR (DIV/REM?). Possibly for -ffast-math float
FADD/FSUB/FMUL/FDIV operations as well.

Further examples can be found here: <a href="https://godbolt.org/g/ueIYiF">https://godbolt.org/g/ueIYiF</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>