This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/30354] New: -Os doesn't optimize a/CONST even if it saves size.
- From: "vda dot linux at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Jan 2007 22:09:43 -0000
- Subject: [Bug rtl-optimization/30354] New: -Os doesn't optimize a/CONST even if it saves size.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
gcc -O2 usually optimizes a/CONST. In many cases code is not only significantly
faster, but also smaller:
unsigned f(unsigned a) { return a/10; }
gcc 4.1.1 -O2:
movl $-858993459, %eax
mull 4(%esp)
shrl $3, %edx
movl %edx, %eax
ret
gcc 4.1.1 -Os:
movl 4(%esp), %eax
movl $10, %edx
movl %edx, %ecx
xorl %edx, %edx
divl %ecx
ret
Unfortunately, gcc -S never uses this optimization.
Note that with code proposed in bug 28417 a/CONST can be optimized even further
(we can use smaller mul constant and avoid shrl) when we know from VRP that
value of a is always small enough.
--
Summary: -Os doesn't optimize a/CONST even if it saves size.
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: vda dot linux at googlemail dot com
GCC build triplet: i386-pc-linux-gnu
GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30354