<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 --- - [aarch64] optimize obscured vector integer comparisons against zero"
   href="https://llvm.org/bugs/show_bug.cgi?id=26819">26819</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[aarch64] optimize obscured vector integer comparisons against 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>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: AArch64
          </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>I think the AArch64 backend is missing a couple of folds related to vector
integer comparisons ( related x86 bug: <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [x86, SSE] missing optimizations for pos/neg integer vector comparisons"
   href="show_bug.cgi?id=26701">bug 26701</a> ). 

I'm not sure why anyone would write NEON code like this, but it could happen?

// Are elements of 'a' > -1? Ie, is 'a' positive?
int32x2_t test_vcgt_s32(int32x2_t a) {
  return vcgt_s32(a, vceq_s32(a, a));
}

$ ./clang -O1 ...
test_vcge_s32:
    sshr    v0.2s, v0.2s, #31
    mvn     v0.8b, v0.8b
    ret

The IR is optimized from a compare+sext to a shift+not in InstCombine.

But this can be optimized to: is 'a' >= 0?
So is this the optimal codegen?
    cmge    v0.2s, v0.2s, #0
    ret

Similarly, for:

// Are elements of 'a' <= -1? Ie, is 'a' negative?
int32x2_t test_vcle_s32(int32x2_t a) {
  return vcle_s32(a, vceq_s32(a, a) );
}

$ ./clang -O1 ...
test_vcle_s32:
    movi    d1, #0xffffffffffffffff
    cmge    v0.2s, v1.2s, v0.2s
    ret

Should this be:
    cmlt    v0.2s, v0.2s, #0
    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>