<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 - Missed optimization in 16-bit __builtin_add_overflow on aarch64"
   href="https://bugs.llvm.org/show_bug.cgi?id=38751">38751</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimization in 16-bit __builtin_add_overflow on aarch64
          </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>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>tblodt@icloud.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following C function generates this code on aarch64 with -O3:

void g(int a, int b, int *c, int *o, int *v) {
    *o = __builtin_add_overflow((int16_t) a, (int16_t) b, (int16_t *) c);
}

  sxth w8, w0
  add w8, w8, w1, sxth
  sxth w9, w8
  cmp w9, w8
  cset w9, ne
  strh w8, [x2]
  str w9, [x3]
  ret

The sequence
  sxth w9, w8
  cmp w9, w8
can be rewritten as
  cmp w8, w8, sxth
which is one instruction shorter and uses one less register. So the following
code should be generated instead:

  sxth w8, w0
  add w8, w8, w1, sxth
  cmp w8, w8, sxth
  str w8, [x2]
  cset w8, ne
  str w8, [x3]
  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>