http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46092

           Summary: Improve constant handling of thumb2 instructions
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: car...@google.com
                CC: car...@google.com
              Host: i686-linux
            Target: arm-eabi
             Build: i686-linux


Compile the following code with options -march=armv7-a -mthumb -Os

unsigned long tv(unsigned long x)
{
  if (x >= 65521)
    x = x - 65521;
  return x;
}

gcc generates:

tv:
        movw    r3, #65520
        cmp     r0, r3
        ittt    hi
        subhi   r0, r0, #65024   // A
        subhi   r0, r0, #496     // B
        subhi   r0, r0, #1       // C
        bx      lr

Notice that (x = x - 65521) is translated into 3 instructions. Actually 65521
can be loaded into register with one instruction. So the shorter result is:

tv:
        movw    r3, #65520
        cmp     r0, r3
        ittt    hi
        movwhi   r1, #65521
        subhi   r0, r1
        bx      lr

This should be improved by function arm_gen_constant. The function is already
commented with
/* ??? This needs more work for thumb2.  */

Reply via email to