<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 optimization for ((X ashr C1) & C2) == 0"
   href="https://bugs.llvm.org/show_bug.cgi?id=48640">48640</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimization for ((X ashr C1) & C2) == 0
          </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>void foo();

void bad1(int e)
{
   if (((e >> 31) & 64) == 0) foo();
}

void bad2(int e)
{
   if (((e >> 31) & 64) != 0) foo();
}


void ok1(unsigned e)
{
   if (((e >> 31) & 64) == 0) foo();
}

void ok2(unsigned e)
{
   if (((e >> 31) & 64) != 0) foo();
}


LLVM:
bad1(int): # @bad1(int)
  shr edi, 25
  test dil, 64
  jne .LBB0_1
  jmp foo() # TAILCALL
.LBB0_1:
  ret
bad2(int): # @bad2(int)
  shr edi, 25
  test dil, 64
  jne .LBB1_2
  ret
.LBB1_2:
  jmp foo() # TAILCALL
ok1(unsigned int): # @ok1(unsigned int)
  jmp foo() # TAILCALL
ok2(unsigned int): # @ok2(unsigned int)
  ret


GCC:
bad1(int):
        test    edi, edi
        jns     .L4
        ret
.L4:
        jmp     foo()
bad2(int):
        test    edi, edi
        js      .L7
        ret
.L7:
        jmp     foo()
ok1(unsigned int):
        jmp     foo()
ok2(unsigned int):
        ret


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


So..
((X ashr C1) & C2) != 0 to X < 0

..and
((X ashr C1) & C2) == 0 to X >= 0?


define i1 @src(i32 %0) {
%1:
  %2 = ashr i32 %0, 31
  %3 = and i32 %2, 64
  %4 = icmp eq i32 %3, 0
  ret i1 %4
}
=>
define i1 @tgt(i32 %0) {
%1:
  %r = icmp sge i32 %0, 0
  ret i1 %r
}
Transformation seems to be correct!


define i1 @src(i32 %0) {
%1:
  %2 = ashr i32 %0, 31
  %3 = and i32 %2, 64
  %4 = icmp ne i32 %3, 0
  ret i1 %4
}
=>
define i1 @tgt(i32 %0) {
%1:
  %r = icmp slt i32 %0, 0
  ret i1 %r
}
Transformation seems to be correct!</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>