[Bug rtl-optimization/80491] New: Compiler regression for long-add case.

khim at google dot com gcc-bugzilla@gcc.gnu.org
Sat Apr 22 19:52:00 GMT 2017


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

            Bug ID: 80491
           Summary: Compiler regression for long-add case.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: khim at google dot com
  Target Milestone: ---

Simple long addition program.

struct pair {
  uint64_t low;
  uint64_t hi;
};

pair add(pair& a, pair& b) {
 pair s;
 s.low = a.low + b.low;
 s.hi = a.hi + b.hi + (s.low < a.low); //carry
 return s;
}

Old versions of GCC produced adequate code:

$ gcc -S -O3 test.cc -o-
        .file   "test.cc"
        .text
        .p2align 4,,15
        .globl  _Z3addR4pairS0_
        .type   _Z3addR4pairS0_, @function
_Z3addR4pairS0_:
.LFB4:
        .cfi_startproc
        movq    (%rdi), %rax
        movq    8(%rsi), %rdx
        xorl    %ecx, %ecx
        addq    8(%rdi), %rdx
        addq    (%rsi), %rax
        setc    %cl
        addq    %rcx, %rdx
        ret
        .cfi_endproc
.LFE4:
        .size   _Z3addR4pairS0_, .-_Z3addR4pairS0_
        .ident  "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
        .section        .note.GNU-stack,"",@progbits

New version of gcc produces comparison and jump:
$ gcc -S -O3 test.cc -o-
        .file "test.cc"
        .text
        .p2align 4,,15
        .globl _Z3addR4pairS0_
        .type _Z3addR4pairS0_, @function
        _Z3addR4pairS0_:
        .LFB4:
        .cfi_startproc
        xorl %ecx, %ecx
        movq (%rsi), %rax
        addq (%rdi), %rax
        jc .L5
.L2:
        movq 8(%rsi), %rdx
        addq 8(%rdi), %rdx
        addq %rcx, %rdx
        ret
.L5:
        movl $1, %ecx
        jmp .L2
.cfi_endproc
.LFE4:
.size _Z3addR4pairS0_, .-_Z3addR4pairS0_
.ident "GCC: (GNU) 7.0.1 20170307 (experimental)"
.section .note.GNU-stack,"",@progbits


For comparison - clang produces perfect code here:
$ clang++ -S -O3 test1.cc -o- 
        .text
        .file   "test1.cc"
        .globl  _Z3addR4pairS0_
        .p2align        4, 0x90
        .type   _Z3addR4pairS0_,@function
_Z3addR4pairS0_:                        # @_Z3addR4pairS0_
        .cfi_startproc
# BB#0:
        movq    (%rsi), %rax
        movq    8(%rsi), %rdx
        addq    8(%rdi), %rdx
        addq    (%rdi), %rax
        adcq    $0, %rdx
        retq
.Lfunc_end0:
        .size   _Z3addR4pairS0_, .Lfunc_end0-_Z3addR4pairS0_
        .cfi_endproc

        .ident  "Android clang version 4.0.285906  (based on LLVM 4.0.285906)"
        .section        ".note.GNU-stack","",@progbits


More information about the Gcc-bugs mailing list