<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 - Unnecessary use of SIMD"
   href="https://bugs.llvm.org/show_bug.cgi?id=44781">44781</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unnecessary use of SIMD
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>kobalicek.petr@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang tries sometimes so hard to use SIMD that it generates worse code than
actually not using it. A very simple example below:

struct Box {
    int x0, y0, x1, y1;
};

bool check(const Box& box) noexcept {
  return ((box.x0 | box.y0 | box.x1 | box.y1) & 0xFFu) == 0;
}

Clang 8+ compiles this code to:

check(Box const&):
        vmovdqu xmm0, xmmword ptr [rdi]
        vpshufd xmm1, xmm0, 78          # xmm1 = xmm0[2,3,0,1]
        vpor    xmm0, xmm0, xmm1
        vpshufd xmm1, xmm0, 229         # xmm1 = xmm0[1,1,2,3]
        vpor    xmm0, xmm0, xmm1
        vpextrb eax, xmm0, 0
        test    al, al
        sete    al
        ret

Whereas GCC (and Clang 7 and lesser) is just really fine with a scalar code:

check(Box const&):
        mov     eax, DWORD PTR [rdi]
        or      eax, DWORD PTR [rdi+4]
        or      eax, DWORD PTR [rdi+8]
        or      eax, DWORD PTR [rdi+12]
        test    al, al
        sete    al
        ret

The resulting SIMD code Clang produces is just worse (and bigger) than the
scalar one, and I think it would also be slower as it contains shuffles and
extract.</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>