This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/60554] New: redundant instruction is generated for setting the flags on x86
- From: "l_belev at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 17 Mar 2014 16:27:05 +0000
- Subject: [Bug rtl-optimization/60554] New: redundant instruction is generated for setting the flags on x86
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60554
Bug ID: 60554
Summary: redundant instruction is generated for setting the
flags on x86
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: l_belev at yahoo dot com
consider this simple function:
int is_float_negative(int x) { return (int)(x ^ 0x80000000) > 0; }
for x86, with options "-O3 -march=core2", GCC 4.8.2 generates the following
code:
....
_is_float_negative:
movl 4(%esp), %eax
addl $-2147483648, %eax
testl %eax, %eax
setg %al
movzbl %al, %eax
ret
....
apparently (x^0x80000000) is replaced with (x+0x80000000), that's ok.
the problem is the testl instruction - why the compiler decided to emit it?
the addl instruction itself sets the needed flags (Z and N) just right.