<html>
    <head>
      <base href="https://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 --- - [x86, SSE] missing optimizations for pos/neg integer vector comparisons"
   href="https://llvm.org/bugs/show_bug.cgi?id=26701">26701</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86, SSE] missing optimizations for pos/neg integer vector comparisons
          </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>All
          </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>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Checking if integer vector elements are positive or negative would seem to be a
common operation, but we don't handle this very well. We need to do extra work
because SSE/AVX only provide 2 integer comparison instructions (eq/gt):

define <4 x i32> @is_positive_using_signshift(<4 x i32> %x) {
  %sign = ashr <4 x i32> %x, <i32 31, i32 31, i32 31, i32 31>
  %not = xor <4 x i32> %sign, <i32 -1, i32 -1, i32 -1, i32 -1>
  ret <4 x i32> %not
}

define <4 x i32> @is_positive_using_sge(<4 x i32> %x) {
  %cmp = icmp sge <4 x i32> %x, zeroinitializer
  %sext = sext <4 x i1> %cmp to <4 x i32>
  ret <4 x i32> %sext
}

define <4 x i32> @is_positive_using_sgt(<4 x i32> %x) {
  %cmp = icmp sgt <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
  %sext = sext <4 x i1> %cmp to <4 x i32>
  ret <4 x i32> %sext
}

define <4 x i32> @is_negative_using_signshift(<4 x i32> %x) {
  %sign = ashr <4 x i32> %x, <i32 31, i32 31, i32 31, i32 31>
  ret <4 x i32> %sign
}

define <4 x i32> @is_negative_using_slt(<4 x i32> %x) {
  %cmp = icmp slt <4 x i32> %x, zeroinitializer
  %sext = sext <4 x i1> %cmp to <4 x i32>
  ret <4 x i32> %sext
}

define <4 x i32> @is_negative_using_sle(<4 x i32> %x) {
  %cmp = icmp sle <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
  %sext = sext <4 x i1> %cmp to <4 x i32>
  ret <4 x i32> %sext
}

$ ./llc -o - pcmp.ll -mattr=avx
_is_positive_using_signshift: 
    vpsrad    $31, %xmm0, %xmm0
    vpcmpeqd    %xmm1, %xmm1, %xmm1
    vpxor    %xmm1, %xmm0, %xmm0
    retq

_is_positive_using_sge:   
    vpxor    %xmm1, %xmm1, %xmm1
    vpcmpgtd    %xmm0, %xmm1, %xmm0
    vpcmpeqd    %xmm1, %xmm1, %xmm1
    vpxor    %xmm1, %xmm0, %xmm0
    retq

_is_positive_using_sgt:  
    vpcmpeqd    %xmm1, %xmm1, %xmm1
    vpcmpgtd    %xmm1, %xmm0, %xmm0
    retq

_is_negative_using_signshift: 
    vpsrad    $31, %xmm0, %xmm0
    retq

_is_negative_using_slt:         
    vpxor    %xmm1, %xmm1, %xmm1
    vpcmpgtd    %xmm0, %xmm1, %xmm0
    retq

_is_negative_using_sle:           
    vpcmpeqd    %xmm1, %xmm1, %xmm1
    vpcmpgtd    %xmm1, %xmm0, %xmm0
    vpxor    %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>