[Bug rtl-optimization/19702] New: suboptimal multiple branch comparison code produced
yuri at tsoft dot com
gcc-bugzilla@gcc.gnu.org
Sun Jan 30 01:53:00 GMT 2005
When two comparisons immediately follow each other that compare same numbers but
branch twice based on 3 possible comparison outcomes actual comparison is
performed twice in asm code. One comparision suffices.
Also if second branches are strongly disadvantaged even pre-jxx mov for each
branch should be moved outside of the main body of the function.
Yuri (yuri at ONLYtsoftLOWER CASEcomMATTERS)
-- begin code --
int f(int k) {
if (k < 300)
return (10);
if (k > 300)
return (-10);
return (0);
}
int main() { f(299); }
-- end code --
obtained assembly log:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 55 08 mov 0x8(%ebp),%edx
6: 81 fa 2b 01 00 00 cmp $0x12b,%edx
c: b8 0a 00 00 00 mov $0xa,%eax
11: 7e 0f jle 22 <_Z1fi+0x22>
13: 81 fa 2c 01 00 00 cmp $0x12c,%edx
19: b8 f6 ff ff ff mov $0xfffffff6,%eax
1e: 7f 02 jg 22 <_Z1fi+0x22>
20: 31 c0 xor %eax,%eax
22: c9 leave
23: c3 ret
expected assembly log:
: 55 push %ebp
: 89 e5 mov %esp,%ebp
: 8b 55 08 mov 0x8(%ebp),%edx
: 81 fa 2b 01 00 00 cmp $0x12b,%edx
: b8 0a 00 00 00 mov $0xa,%eax
: 7e 0f jle 22 <_Z1fi+ret>
: b8 f6 ff ff ff mov $0xfffffff6,%eax
: 7f 02 je 22 <_Z1fi+ret>
: 31 c0 xor %eax,%eax
ret: c9 leave
: c3 ret
--
Summary: suboptimal multiple branch comparison code produced
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yuri at tsoft dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19702
More information about the Gcc-bugs
mailing list