In the following code we produce an extra la.

int curr_state_graph_pass_num = 0;
void
pass_states (void)
{
  curr_state_graph_pass_num++;
}

We currently produce at -O2 -mdynamic-no-pic:
_pass_states:
        lis r9,ha16(_curr_state_graph_pass_num)
        la r9,lo16(_curr_state_graph_pass_num)(r9)
        lwz r2,0(r9)
        addi r2,r2,1
        stw r2,0(r9)
        blr

We should be able to produce the following instead:
_pass_states:
        lis r9,ha16(_curr_state_graph_pass_num)
        lwz r2,lo16(_curr_state_graph_pass_num)(r9)
        addi r2,r2,1
        stw r2,lo16(_curr_state_graph_pass_num)(r9)
        blr

-- 
           Summary: missed optimization with globals
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: minor
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: powerpc-darwin


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

Reply via email to