<html>
    <head>
      <base href="http://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 --- - optimization of (x>>8)==0 breaks other comparisons with x"
   href="http://llvm.org/bugs/show_bug.cgi?id=19964">19964</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>optimization of (x>>8)==0 breaks other comparisons with x
          </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>normal
          </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>nlewycky@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define zeroext i1 @between(i32 %bf.load, i32 %n) {
entry:
  %bf.lshr = lshr i32 %bf.load, 16
  %cmp2 = icmp eq i32 %bf.lshr, 0
  %cmp5 = icmp uge i32 %bf.lshr, %n
  %.cmp5 = or i1 %cmp2, %cmp5
  ret i1 %.cmp5
}

We codegen this wrong in x86 by lowering the "lshr" into an "andl" for the
comparison against zero, but also use that masked value to compare against %n.

nlewycky@ducttape:~$ llvm/Debug+Asserts/bin/llc x2.ll -o -
        .text
        .file   "x2.ll"
        .globl  between
        .align  16, 0x90
        .type   between,@function
between:                                # @between
        .cfi_startproc
# BB#0:                                 # %entry
        andl    $-65536, %edi           # imm = 0xFFFFFFFFFFFF0000
        sete    %cl
        cmpl    %esi, %edi  ;; nope! either %edi needs to be shifted right or
%esi needs to be shifted left
        setae   %al
        orb     %cl, %al
        retq
.Ltmp0:
        .size   between, .Ltmp0-between
        .cfi_endproc


        .section        ".note.GNU-stack","",@progbits

We produce correct code with llc -O0.</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>