This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/42502] Bad register allocation in a very simple code



------- Comment #2 from sliao at google dot com  2010-01-07 13:28 -------
Using flags, -march=armv5te -mthumb -Os, GCC 4.5.0 (trunk) generates the
following code:

00000000 <test>:
   0:    b570          push    {r4, r5, r6, lr}
   2:    b084          sub    sp, #16
   4:    1c05          adds    r5, r0, #0
   6:    4668          mov    r0, sp
   8:    1c0e          adds    r6, r1, #0
   a:    466c          mov    r4, sp
   c:    f7ff fffe     bl    0 <func>
  10:    2d01          cmp    r5, #1
  12:    d102          bne.n    1a <func+0x1a>
  14:    9b00          ldr    r3, [sp, #0]
  16:    9c01          ldr    r4, [sp, #4]
  18:    e00c          b.n    34 <func+0x34>
  1a:    68a2          ldr    r2, [r4, #8]
  1c:    68e3          ldr    r3, [r4, #12]
  1e:    2e02          cmp    r6, #2
  20:    d102          bne.n    28 <func+0x28>
  22:    1c1c          adds    r4, r3, #0
  24:    1c13          adds    r3, r2, #0
  26:    e005          b.n    34 <func+0x34>
  28:    6820          ldr    r0, [r4, #0]
  2a:    6861          ldr    r1, [r4, #4]
  2c:    1c1c          adds    r4, r3, #0
  2e:    1c13          adds    r3, r2, #0
  30:    1a1b          subs    r3, r3, r0
  32:    418c          sbcs    r4, r1
  34:    b004          add    sp, #16
  36:    1c18          adds    r0, r3, #0
  38:    1c21          adds    r1, r4, #0
  3a:    bd70          pop    {r4, r5, r6, pc}
----------------------------------------------------

GCC 4.2.1 generates the following code:

00000000 <test>:
   0:    b530          push    {r4, r5, lr}
   2:    b085          sub    sp, #20
   4:    1c04          adds    r4, r0, #0
   6:    4668          mov    r0, sp
   8:    1c0d          adds    r5, r1, #0
   a:    f7ff fffe     bl    0 <func>
   e:    2c01          cmp    r4, #1
  10:    d102          bne.n    18 <func+0x18>
  12:    9800          ldr    r0, [sp, #0]
  14:    9901          ldr    r1, [sp, #4]
  16:    e007          b.n    28 <func+0x28>
  18:    9802          ldr    r0, [sp, #8]
  1a:    9903          ldr    r1, [sp, #12]
  1c:    2d02          cmp    r5, #2
  1e:    d003          beq.n    28 <func+0x28>
  20:    9b00          ldr    r3, [sp, #0]
  22:    9c01          ldr    r4, [sp, #4]
  24:    1ac0          subs    r0, r0, r3
  26:    41a1          sbcs    r1, r4
  28:    b005          add    sp, #20
  2a:    bd30          pop    {r4, r5, pc}
------------------------------------------------------

GCC 4.2.1's code size is still smaller than GCC 4.5.0, and GCC 4.5.0's
generated code is similar to GCC 4.4.

I think it's still an issue in the trunk now.

For completeness sake, the source code is:
struct node
{
 long long a;
 long long b;
};

void func (struct node *n);

long long test (int from, int to)
{
 struct node n;
 func(&n);
 if (from == 1)
   return n.a;
 else
   {
     if (to == 2)
       return n.b;
     else
       return n.b - n.a;
   }
}


-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]