Comment 1 for bug 663939

Revision history for this message
Yao Qi (yao-codesourcery) wrote :

This bug is reported in upstreams GCC, and the problem exists in Linaro GCC 4.5 also.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46092

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. */