<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 - [AArch64] compare and branch with long immediate optimisation"
   href="https://bugs.llvm.org/show_bug.cgi?id=52140">52140</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AArch64] compare and branch with long immediate optimisation
          </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>Keywords</th>
          <td>beginner
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>pavel.iliin@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Сomparison with complex immediates followed by branch/cset can be improved.
Currently clang optimise  
int feqi (int a)
{
  return a == 0x111111;
}

long long feql (long long a)
{
  return a == 0x222222;
}

int fnei (int a)
{
  return a != 0x333333;
}

long long fnel (long long a)
{
  return a != 0x444444;
}
into 
feqi(int):                               // @feqi(int)
        mov     w8, #4369
        movk    w8, #17, lsl #16
        cmp     w0, w8
        cset    w0, eq
        ret
feql(long long):                               // @feql(long long)
        mov     w8, #8738
        movk    w8, #34, lsl #16
        cmp     x0, x8
        cset    w0, eq
        ret
fnei(int):                               // @fnei(int)
        mov     w8, #13107
        movk    w8, #51, lsl #16
        cmp     w0, w8
        cset    w0, ne
        ret
fnel(long long):                               // @fnel(long long)
        mov     w8, #17476
        movk    w8, #68, lsl #16
        cmp     x0, x8
        cset    w0, ne
        ret
However gcc performs better emitting sub+subs instead of mov+movk+cmp:
feqi(int):
        sub     w0, w0, #1118208
        subs    w0, w0, #273
        cset    w0, eq
        ret
feql(long long):
        sub     x0, x0, #2236416
        subs    x0, x0, #546
        cset    x0, eq
        ret
fnei(int):
        sub     w0, w0, #3354624
        subs    w0, w0, #819
        cset    w0, ne
        ret
fnel(long long):
        sub     x0, x0, #4472832
        subs    x0, x0, #1092
        cset    x0, ne
        ret

Details of GCC implementation:
<a href="https://gcc.gnu.org/legacy-ml/gcc-patches/2015-10/msg00800.html">https://gcc.gnu.org/legacy-ml/gcc-patches/2015-10/msg00800.html</a></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>