Take the following simple source:
int X[4] = {1};
int *foo() { return &X[1]; }
----
With -static -O2, we get:
_foo:
        lis r3,ha16(_X+4)
        la r3,lo16(_X+4)(r3)
        blr
---
Which is the most optimial.
With -O2 -mdynamic-no-pic, we get:
_foo:
        lis r3,ha16(_X)
        la r3,lo16(_X)(r3)
        addi r3,r3,4
        blr
Which is not optimial at all.
The PIC version is just as bad:
_foo:
        mflr r0
        bcl 20,31,"L00000000001$pb"
"L00000000001$pb":
        stw r31,-4(r1)
        mflr r31
        mtlr r0
        addis r3,r31,ha16(_X-"L00000000001$pb")
        lwz r31,-4(r1)
        la r3,lo16(_X-"L00000000001$pb")(r3)
        addi r3,r3,4
        blr

-----

All of the ha16 and lo16 should be including +4 in them instead of explicatly
adding 4 to the register.

This testcase comes from Chris Lattner.


-- 
           Summary: CONST (PLUS a + 4) is not done for -fPIC or -mdynamic-
                    no-pic
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org
GCC target triplet: powerpc-darwin


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

Reply via email to