<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 - [X86][SSE] Perform unsigned compare as signed when signbits are zero"
   href="https://bugs.llvm.org/show_bug.cgi?id=33276">33276</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[X86][SSE] Perform unsigned compare as signed when signbits are zero
          </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>Windows NT
          </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>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>SSE doesn't have an unsigned integer compare, so we have to flip the sign bits
and use the signed compare instructions. But if we know that the sign bits of
both values are zero then we should be able to avoid the flip:

llc -mtriple=x86_64-unknown -mcpu=btver2

define <4 x i32> @cmp_ugt_4i32(<4 x i32> %a0, <4 x i32> %a1) {
  %1 = lshr <4 x i32> %a0, <i32 1, i32 1, i32 1, i32 1>
  %2 = lshr <4 x i32> %a1, <i32 1, i32 1, i32 1, i32 1>
  %3 = icmp ugt <4 x i32> %1, %2
  %4 = sext <4 x i1> %3 to <4 x i32>
  ret <4 x i32> %4
}

cmp_ugt:
        vmovdqa .LCPI0_0(%rip), %xmm2   # xmm2 =
[2147483648,2147483648,2147483648,2147483648]
        vpsrld  $1, %xmm0, %xmm0
        vpsrld  $1, %xmm1, %xmm1
        vpxor   %xmm2, %xmm1, %xmm1
        vpxor   %xmm2, %xmm0, %xmm0
        vpcmpgtd        %xmm1, %xmm0, %xmm0
        retq

Ideally:

cmp_ugt:
        vpsrld  $1, %xmm0, %xmm0
        vpsrld  $1, %xmm1, %xmm1
        vpcmpgtd        %xmm1, %xmm0, %xmm0
        retq</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>