gcc 3.4.6 on PPC why doing function inline with -O2?

ming lei lei_ming@hotmail.com
Fri Feb 23 02:06:00 GMT 2007


Here is the test.c file and two objdump output from compiled with -O1 and 
-O2 using gcc3.4.6 cross compiler(host is x86 linux and target is PPC440) 
respectively. It's obvious that the output from -O2 inlines Goo().

BTW, I compiled with -O2 using gcc 3.3.2 cross compiler on the same file 
which doesnt do inline for Goo().

=============test.c======================
static void Goo()
{
    char a[1024];
    a[0]=21;
}

void Foo(int cmd)
{
    char b[32];

    switch(cmd) {

    case 1:
        b[0] = 13;
        break;

    case 2:
        Goo();
        break;
    }
}
===================use -O2=========================
00000000 <Foo>:
   0:   2f 83 00 01     cmpwi   cr7,r3,1
   4:   94 21 fb d0     stwu    r1,-1072(r1)
   8:   2f 03 00 02     cmpwi   cr6,r3,2
   c:   41 9e 00 20     beq-    cr7,2c <Foo+0x2c>
  10:   41 9a 00 0c     beq-    cr6,1c <Foo+0x1c>
  14:   38 21 04 30     addi    r1,r1,1072
  18:   4e 80 00 20     blr
  1c:   38 00 00 15     li      r0,21
  20:   98 01 00 30     stb     r0,48(r1)
  24:   38 21 04 30     addi    r1,r1,1072
  28:   4e 80 00 20     blr
  2c:   38 00 00 0d     li      r0,13
  30:   98 01 00 10     stb     r0,16(r1)
  34:   38 21 04 30     addi    r1,r1,1072
  38:   4e 80 00 20     blr

===================use -O1=========================
00000000 <Goo>:
   0:   94 21 fb f0     stwu    r1,-1040(r1)
   4:   38 21 04 10     addi    r1,r1,1040
   8:   4e 80 00 20     blr

0000000c <Foo>:
   c:   94 21 ff d0     stwu    r1,-48(r1)
  10:   2f 83 00 01     cmpwi   cr7,r3,1
  14:   40 be 00 0c     bne+    cr7,20 <Foo+0x14>
  18:   38 00 00 0d     li      r0,13
  1c:   98 01 00 10     stb     r0,16(r1)
  20:   38 21 00 30     addi    r1,r1,48
  24:   4e 80 00 20     blr
===============================================




========================================================
Re: gcc 3.4.6 on PPC why doing function inline with -O2?
From: Andrew Haley <aph at redhat dot com>
To: "Ming Lei" <mlei at Brocade dot COM>
Cc: <gcc-help at gcc dot gnu dot org>
Date: Sat, 17 Feb 2007 10:36:05 +0000
Subject: Re: gcc 3.4.6 on PPC why doing function inline with -O2?
References: 
<A5443C1E48CD114B9B1A92EF04F6656601795EF3@hq-exch-1.corp.brocade.com>

--------------------------------------------------------------------------------

Ming Lei writes:

 > I came across a problem while using gcc3.4.6 on PPC440. It turns out
 > with -O2 flag the compiler does inline function expanding. I tested with
 > 3.2 version it doesn't do it in O2. The 3.4.6 manual says that only with
 > -O3 the compiler can do this inline function optimization. Even I used
 > -fno-inline-functions it doesn't work, but used -fno-inline does prevent
 > inline functions.
 >
 > Is it a bug in 3.4.6?

I don't think so.  Do you have a test case that shows this problem?

Andrew.

_________________________________________________________________
The average US Credit Score is 675. The cost to see yours: $0 by Experian. 
http://www.freecreditreport.com/pm/default.aspx?sc=660600&bcd=EMAILFOOTERAVERAGE



More information about the Gcc-help mailing list