<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 - Fold AND+CMP to CMP"
   href="https://bugs.llvm.org/show_bug.cgi?id=38003">38003</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Fold AND+CMP to CMP
          </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>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,

bool sw1(int x) {
    switch(x) {
        case 2:
        case 5:
        case 6:
        case 31:
            return true;

        default:
            return false;
    }
}

Clang -03
sw1(int): 
  add edi, -2                 // why?
  cmp edi, 29                 // fold add + cmp to cmp edi, 31
  ja .LBB0_2
  mov eax, 536870937
  mov ecx, edi
  shr eax, cl
  and eax, 1
  ret
.LBB0_2:
  xor eax, eax
  ret


GCC 8.1 emits:
sw1(int):
  xor eax, eax
  cmp edi, 31
  ja .L1
  mov eax, 1
  mov ecx, edi
  sal rax, cl
  test eax, 2147483752
  setne al
.L1:
  ret

ICC 18  (more jumps, worse code?):
sw1(int):
  cmp edi, 64
  jae ..B1.4 
  mov rax, 0x080000068 
  bt rax, rdi 
  jnc ..B1.4 
  mov eax, 1
  ret 
..B1.4: 
  xor eax, eax
  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>