<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] Failure to canonicalize compare results in reloading of constants"
   href="https://llvm.org/bugs/show_bug.cgi?id=23084">23084</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AArch64] Failure to canonicalize compare results in reloading of constants
          </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>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>james.greenhalgh@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>james.molloy@arm.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14123" name="attach_14123" title="Testcase">attachment 14123</a> <a href="attachment.cgi?id=14123&action=edit" title="Testcase">[details]</a></span>
Testcase

In the attached testcase, after tail-call inlining, two comparisons of x
against 20,000 are generated. The compiler does not pick a canonical way to do
this comparison, and ends up checking (x > 20000) for the first comparison and
(x < 20001) for the second. This results in a useless load of the constant
20001.

clang --target aarch64 canonicalize-compare.c -O2 -S

foo:
    movz    w8, #0x4e20        /* !!!!  */
    cmp     w0, w8
    b.gt    .LBB0_3
    movz    w8, #0x4e21        /* !!!!  */
.LBB0_2:
    add    w9, w0, w0, lsl #6
    neg     w0, w9
    cmp     w0, w8
    b.lt    .LBB0_2      /* Could be B.LE and reuse the first constant  */
.LBB0_3:
    ret

GCC generates:

foo:
    mov    w1, 20000
    cmp    w0, w1
    bgt    .L2
.L3:
    add    w0, w0, w0, lsl 6
    neg    w0, w0
    cmp    w0, w1
    ble    .L3
.L2:
    ret

Which looks neater.</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>