http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46309
Summary: optimization a==3||a==1
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
$g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/eid-letni/opt/gcc/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/eid-letni/opt/gcc
--enable-languages=c,c++
Thread model: posix
gcc version 4.6.0 20101105 (experimental) (GCC)
$uname -a
Linux eidletni 2.6.35-22-generic #35-Ubuntu SMP Sat Oct 16 20:36:48 UTC 2010
i686 GNU/Linux
$g++ -O3 -c main.ii
func good_comp have optimiz without jump:
bool good_comp(int a, int b)
{
return (a==3)||(a==1);
}
asm with no jumps:
00000020 <_Z9good_compii>:
20: 8b 54 24 04 mov 0x4(%esp),%edx
24: 83 fa 01 cmp $0x1,%edx
27: 0f 94 c0 sete %al
2a: 83 fa 03 cmp $0x3,%edx
2d: 0f 94 c2 sete %dl
30: 09 d0 or %edx,%eax
32: c3 ret
using "same" code with temps:
bool bad_comp(int a, int b)
{
bool tmp1 = (a==3);
bool tmp2 = (a==1);
return tmp1||tmp2;
}
asm(with jump):
00000000 <_Z8bad_compii>:
0: 8b 54 24 04 mov 0x4(%esp),%edx
4: b8 01 00 00 00 mov $0x1,%eax
9: 83 fa 03 cmp $0x3,%edx
c: 74 06 je 14 <_Z8bad_compii+0x14>
e: 83 fa 01 cmp $0x1,%edx
11: 0f 94 c0 sete %al
14: f3 c3 repz ret