GCC fails to generate efficient code for basic pointer operations.

Please have a look at this example:
***
test.c:
register int * src asm("r15");

int test( ){
  src[1]=src[0];
  src++;
}

main(){
}

***

compile the above with gcc -S -O3 test.c

shows us the following ASM output:

test:
        mr 9,15
        addi 15,15,4
        lwz 0,0(9)
        stw 0,4(9)
        blr

compile with gcc -S -Os test.c
Gives this output
test:
        mr 9,15
        addi 15,15,4
        lwz 0,0(9)
        stw 0,4(9)
        blr


As you can see both -O3 and -Os produce the same output.
The generated output is far from optimal.

GCC generates for the simple pointer operation this code:
        mr 9,15
        addi 15,15,4
        lwz 0,0(9)
        stw 0,4(9)

But GCC should rather generate this:
        lwz 0,0(15)
        stwu 0,4(15)


Two of the four instructions are unneeded.
We've here code with literally thousands of unneeded instructions generated
like this.


I very much hope that this information is helpful to you and that you can fix
this.

Many thanks in advance

Gunnar von Boehn


-- 
           Summary: PowerPC generated PTR code ineffiency
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gunnar at greyhound-data dot com
 GCC build triplet: powerpc64-unknown-linux-gnu
  GCC host triplet: powerpc64-unknown-linux-gnu
GCC target triplet: powerpc64-unknown-linux-gnu


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

Reply via email to