<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 - SLP vectorizer produces lower performance code"
   href="https://bugs.llvm.org/show_bug.cgi?id=48662">48662</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SLP vectorizer produces lower performance code
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>chfast@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The code just checks if array uint64_t[4] has all zeros.

using u64 = unsigned long;

struct u256
{
    u64 w[4];
};


bool iszero(const u256& u)
{
    return (u.w[0] == 0) & (u.w[1] == 0) & (u.w[2] == 0) & (u.w[3] == 0);
}


Without SLP vectorization (-fno-slp-vectorize) the compiler produces nice OR
folding:

iszero(u256 const&):                       # @iszero(u256 const&)
        mov     rax, qword ptr [rdi + 8]
        or      rax, qword ptr [rdi]
        or      rax, qword ptr [rdi + 16]
        or      rax, qword ptr [rdi + 24]
        sete    al
        ret

With SLP vectorization (default):

iszero(u256 const&):                       # @iszero(u256 const&)
        movdqu  xmm0, xmmword ptr [rdi]
        movdqu  xmm1, xmmword ptr [rdi + 16]
        por     xmm1, xmm0
        pxor    xmm0, xmm0
        pcmpeqb xmm0, xmm1
        pmovmskb        eax, xmm0
        cmp     eax, 65535
        sete    al
        ret


>From llvm-mca the vectorized code may have higher throughput but higher
latency. In my real life usage of similar code I can definitely notice the
performance degradation.

<a href="https://godbolt.org/z/z19EPc">https://godbolt.org/z/z19EPc</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>