Compile the following code with options -Os -mthumb -march=armv5te int mul12(int x) { return x*12; }
Gcc generates: lsl r3, r0, #1 add r0, r3, r0 lsl r0, r0, #2 @ sp needed for prologue bx lr This code sequence may be good for speed. But when we optimize for size, we can get shorter code sequence: mov r3, 12 mul r0, r3, r0 bx lr These code is generated by the expand pass. We may consider to generate different instructions when optimize for size. This kind of multiplication is usually found in computing the address of an array element. -- Summary: not optimal result for multiplication with constant when -Os is specified Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: carrot at google dot com GCC build triplet: i686-linux GCC host triplet: i686-linux GCC target triplet: arm-eabi http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41653