https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70734

            Bug ID: 70734
           Summary: __builtin_add_overflow emits poor code on x86-64
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arigo at tunes dot org
  Target Milestone: ---

Tested on gcc_5_branch:

    extern void abort(void);
    void f(int a, int b, int *r)
    {
        if (__builtin_add_overflow(a, b, r))
            abort();
    }

Results in this x86-64 assembler (xgcc -O2 -S):

    xorl    %eax, %eax
    addl    %edi, %esi
    seto    %al
    movl    %esi, (%rdx)
    testl   %eax, %eax
    jne .L8

I would expect code with a direct "jo" instead of "seto/test/jne".  I guess it
is a known issue related to the difficulties of returning the condition code
from an asm() statement.  Still, I would have expected this builtin to work
around that issue.

Reply via email to