[llvm-bugs] [Bug 40125] New: Poor code generated for __builtin_sub_overflow with constant RHS

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 20 15:24:19 PST 2018


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

            Bug ID: 40125
           Summary: Poor code generated for __builtin_sub_overflow with
                    constant RHS
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: craig.topper at gmail.com
                CC: llvm-bugs at lists.llvm.org

This generates some impressively bad code considering its equivalent to
checking if x is 0.

void bar();

void foo(unsigned x) {
  unsigned y;
  if (__builtin_sub_overflow(x, 1, &y))
    bar();
}

X86 assembly 

        mov     eax, edi
        add     rax, -1
        movabs  rcx, 8589934591
        and     rcx, rax
        add     edi, -1
        cmp     rcx, rdi
        jne     .LBB0_2
        ret
.LBB0_2:
        jmp     bar()                 # TAILCALL


https://godbolt.org/z/0K1SuH

-- 
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/20181220/2ab921f6/attachment.html>


More information about the llvm-bugs mailing list