<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 - Single bit extract and add/sub could generate better code via carry bit"
   href="https://bugs.llvm.org/show_bug.cgi?id=35908">35908</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Single bit extract and add/sub could generate better code via carry bit
          </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>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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>dave@znu.io
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following code, which is a reduction derived from a client of
llvm::TrailingObjects.

void dummy(int arg);
void test_add(int x, int y, int z) { dummy(bool(z & (1 << 30)) + x + y); }
void test_sub(int x, int y, int z) { dummy(bool(z & (1 << 30)) - x - y); }

On pre-BEXTR CPUs, the following code is emitted:

"test_add"
        shrl    $30, %edx
        andl    $1, %edx
        addl    %esi, %edi
        addl    %edx, %edi

"test_sub"
        shrl    $30, %edx
        andl    $1, %edx
        addl    %esi, %edi
        subl    %edi, %edx
        movl    %edx, %edi

And on BEXTR capable CPUs:

"test_add"
        movl    $286, %eax              # imm = 0x11E
        bextrl  %eax, %edx, %eax
        addl    %esi, %edi
        addl    %eax, %edi

"test_sub"
        movl    $286, %eax              # imm = 0x11E
        bextrl  %eax, %edx, %eax
        addl    %esi, %edi
        subl    %edi, %eax
        movl    %eax, %edi

But in practice, pre-BEXTR CPUs can generate the best code

"test_add"
        btl     $30, %edx
        adcl    %esi, %edx

"test_sub"
        btl     $30, %edx
        sbbl    %esi, %edx</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>