<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 - Missed opportunity to use cmp with exx instead od rxx (code size optimization)"
   href="https://bugs.llvm.org/show_bug.cgi?id=43823">43823</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed opportunity to use cmp with exx instead od rxx (code size optimization)
          </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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>bool test1(U64 val)
{
    return ((U32)(val & 0x120)) == 0x20;
}

define dso_local zeroext i1 @test1(i64 %0) local_unnamed_addr #0 {
  %2 = and i64 %0, 288
  %3 = icmp eq i64 %2, 32
  ret i1 %3
}

test1:  
        and     edi, 288
        cmp     rdi, 32
        sete    al
        ret

(-O0's trunc LLVM IR instruction is eliminated)

but codegen could use "cmp edi" instead of "cmp rdi":

test1:
        and     edi, 288
        cmp     edi, 32
        sete    al
        ret

GCC does this code size optimization (eliminate REX prefix), Clang does not.

Another opportunity for "cmp edi":
bool test2(U64 val)
{
    return (val & 0x120) == 0x20;
}

test2:                     
        and     edi, 288
        cmp     rdi, 32
        sete    al
        ret

Both GCC and Clang fails to use rdi for "test2" case.

<a href="https://godbolt.org/z/A0hjTg">https://godbolt.org/z/A0hjTg</a>


Another case:

bool test3(U64 val)
{
    return ((short)(val & 0x120)) == 0x20;
}

Clang
test3:                                  # @test3
        and     edi, 288
        cmp     rdi, 32
        sete    al
        ret

GCC
test3:
        and     di, 288
        cmp     di, 32
        sete    al
        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>