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