This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation
- From: "astrange at ithinksw dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Jul 2007 18:47:23 -0000
- Subject: [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
> /usr/local/gcc43/bin/g++ -v
Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: ../gcc/configure --prefix=/usr/local/gcc43 --disable-multilib
--with-arch=pentium-m --with-tune=nocona --enable-target-optspace
--disable-bootstrap --with-gmp=/sw --with-system-zlib
--enable-languages=c,c++,objc,obj-c++
Thread model: posix
gcc version 4.3.0 20070702 (experimental)
> /usr/local/gcc43/bin/gcc -Os -fno-pic -fomit-frame-pointer -S sub.c
"i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];" generates:
movl $7, %ecx
subl %eax, %ecx
sall %cl, %edx
It would be better if it generated:
negl %eax
addl $7, %eax
sall %al, %edx
which would leave a register free (which helps if this function is inlined);
this is safe since eax isn't used again later.
You can do this by transforming 'y = constant - x' into 'y = -x + constant'.
It looks like gcc actually does the reverse; if I change the source to match
the best output, it generates the same thing.
--
Summary: Missed optimization of 'y = constant - x' operation
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: astrange at ithinksw dot com
GCC build triplet: i386-apple-darwin8.10.1
GCC host triplet: i386-apple-darwin8.10.1
GCC target triplet: i386-apple-darwin8.10.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593