Compiling this simple function in thumb mode:

int add_const(int x)
{
 return x+400;
}

I got:

       mov     r1, #200
       lsl     r3, r1, #1
       add     r0, r0, r3

A better code sequence should be:

    add r0, r0, 200
    add r0, r0, 200

In order to apply this optimization, the constant should be less than 2 times
of the largest immediate value in the target ISA. So this optimization should
also useful to other architecture with limited immediate operand range.

It can also be applied to sub instruction.


-- 
           Summary: Use less instructions to add some constants to register
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        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=40327

Reply via email to