[llvm-bugs] [Bug 46432] New: Failure to optimize double overflow comparison to __builtin_add_overflow

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 24 03:17:49 PDT 2020


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

            Bug ID: 46432
           Summary: Failure to optimize double overflow comparison to
                    __builtin_add_overflow
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: gabravier at gmail.com
                CC: llvm-bugs at lists.llvm.org

unsigned foo(unsigned a, unsigned b)
{
    unsigned sum = a + b;
    if (sum < a)
        abort();
    if (sum < b)
        abort();
    return sum;
}

This can be optimized to remove one of the two checks, or to this :

unsigned foo(unsigned a, unsigned b)
{
    unsigned sum;
    if (__builtin_add_overflow(a, b, &sum))
        abort();
    else
        return sum;
}

This transformation is done by GCC, but not by LLVM.

-- 
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/20200624/2c402140/attachment-0001.html>


More information about the llvm-bugs mailing list