[llvm-bugs] [Bug 27571] New: Codegen for checked addition is particularly poor

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 28 23:34:34 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27571

            Bug ID: 27571
           Summary: Codegen for checked addition is particularly poor
           Product: libraries
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: ARM
          Assignee: unassignedbugs at nondot.org
          Reporter: dbau.pp at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160429/287617fd/attachment.html>


More information about the llvm-bugs mailing list