This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/54829] bad optimization: sub followed by cmp w/ zero (x86 & ARM)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54829

Daniel Santos <daniel.santos at pobox dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|bad optimization: sub       |bad optimization: sub
                   |followed by cmp w/ zero     |followed by cmp w/ zero
                   |(ARM)                       |(x86 & ARM)

--- Comment #3 from Daniel Santos <daniel.santos at pobox dot com> 2012-10-06 15:55:47 UTC ---
Sure it can:

extern print_gt(void);
extern print_lt(void);
extern print_eq(void);

void cmp_and_branch(long a, long b)
{
    if (a > b) {
        print_gt();
    } else if (a < b) {
        print_lt();
    } else {
        print_eq();
    }
}

Here's x86_64:

cmp_and_branch:
.LFB0:
    .cfi_startproc
    cmpq    %rsi, %rdi
    jg  .L5
    jl  .L6
    jmp print_eq
    .p2align 4,,10
    .p2align 3
.L6:
    jmp print_lt
    .p2align 4,,10
    .p2align 3
.L5:
    jmp print_gt
    .cfi_endproc

And here's i386:

cmp_and_branch:
.LFB0:
    .cfi_startproc
    movl    8(%esp), %eax
    cmpl    %eax, 4(%esp)
    jg  .L5
    jl  .L6
    jmp print_eq
    .p2align 2,,3
.L6:
    jmp print_lt
    .p2align 2,,3
.L5:
    jmp print_gt
    .cfi_endproc


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]