<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 --- - Codegen for checked addition is particularly poor"
   href="https://llvm.org/bugs/show_bug.cgi?id=27571">27571</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Codegen for checked addition is particularly poor
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </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: ARM
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dbau.pp@gmail.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>The following C code results in code with a pile of seemingly unnecessary
instructions:

    int checked(int a, int b) {
        int res;
        if (__builtin_sadd_overflow(a, b, &res)) {
            __builtin_abort();
        }
        return res;
    }

With `clang-3.7 -O3 -target arm-unknown-linux-gnueabihf -S
-fomit-frame-pointer` (the last is to just remove irrelevant cruft, it doesn't
change the core codegen) this gives:

    checked:                                @ @checked
        .fnstart
    @ BB#0:
        mov    r2, r0
        add    r0, r2, r1
        mov    r1, #1
        cmp    r0, r2
        movwvc    r1, #0
        cmp    r1, #0
        bxeq    lr
        mov    lr, pc
        b    abort

The sequence `mov r1, #1` through `cmp r1 #0` seems particularly pointless: I
believe can be replaced by two instructions:

    cmp r0, r2
    bxvc lr

(I haven't found an arm variant with good codegen---v7 and v5 etc. are all
similar, and v6m is even worse!)

This seems to be particular to 32-bit ARM: x86 (64- and 32-bit) and AArch64
seem far better.</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>