This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/54829] bad optimization: sub followed by cmp w/ zero (x86 & ARM)
- From: "daniel.santos at pobox dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 06 Oct 2012 15:55:47 +0000
- Subject: [Bug target/54829] bad optimization: sub followed by cmp w/ zero (x86 & ARM)
- Auto-submitted: auto-generated
- References: <bug-54829-4@http.gcc.gnu.org/bugzilla/>
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