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: unassignedb...@nondot.org Reporter: dbau...@gmail.com CC: llvm-bugs@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.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs