<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 --- - llvm.bitreverse.i8 on x86 lowers to questionable assembly"
   href="https://llvm.org/bugs/show_bug.cgi?id=31810">31810</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm.bitreverse.i8 on x86 lowers to questionable assembly
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>On x86 the 32 and 64 bit versions of bitreverse look very good, but the
generated code for the 8-bit version looks worse than the naive implementation:

<a href="https://godbolt.org/g/kAlOC7">https://godbolt.org/g/kAlOC7</a>

@bitrev_8_naive(unsigned char)
        mov     eax, 2149582850
        imul    rax, rdi
        movabs  rcx, 36578664720
        and     rcx, rax
        movabs  rax, 4311810305
        imul    rax, rcx
        shr     rax, 32
        ret

vs llvm.bitreverse.i8:

@bitrev_8(unsigned char)
        rol     dil, 4
        mov     eax, edi
        and     al, 51
        shl     al, 2
        and     dil, -52
        shr     dil, 2
        or      dil, al
        mov     eax, edi
        and     al, 85
        add     al, al
        and     dil, -86
        shr     dil
        or      dil, al
        mov     eax, edi
        ret</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>