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]

optimization/9895: GCC unable to retain array values in registers


>Number:         9895
>Category:       optimization
>Synopsis:       GCC unable to retain array values in registers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 01 02:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Toshi Morita
>Release:        unknown-1.0
>Organization:
>Environment:
host i386-linux, target sh-elf
>Description:
For this test case:

int
integer_calc_one(int i)
{
        int j;
        int a[8];

        a[0] = rand();
        a[1] = (i % 256) + 2;
        a[2] = a[0] + a[1];
        a[3] = a[2] / a[1];
        a[4] = a[3] - a[1];
        a[5] = a[4] * a[1];
        for (j = 0; j < 7; j ++)
                a[7] += a[j];

        return a[7];
}

The MS .net compiler is able to unroll the loop and retain
a[0]...a[7] in registers.

GCC is unable to retain the values in registers even when
-O2 -funroll-loops is specified:

        add     #4,r1
        add     #56,r2
        float   fpul,dr4
        fmov.s  fr5,@r1
        fmov.s  fr4,@-r1
        mov     r14,r1
        fadd    dr4,dr2
        add     #16,r1
        add     #4,r1
        fmov.s  fr3,@r1
        fmov.s  fr2,@-r1
        mov     r14,r1
        fdiv    dr4,dr2
        add     #24,r1
        add     #4,r1
        fmov.s  fr3,@r1
        fmov.s  fr2,@-r1
        mov     r14,r1
        fsub    dr4,dr2
        add     #32,r1
        add     #4,r1
        fmov.s  fr3,@r1
        fmov.s  fr2,@-r1
        mov     r14,r1
        fmul    dr4,dr2
        add     #40,r1
        add     #4,r1
        fmov.s  fr3,@r1
        fmov.s  fr2,@-r1
        mov     #7,r1
.L6:
        fmov.s  @r2+,fr0
        dt      r1
        fmov.s  @r3+,fr2
        fmov.s  @r2,fr1
        add     #-4,r2
        fmov.s  @r3+,fr3
        add     #4,r2
        fadd    dr2,dr0
        fmov.s  fr1,@r2
        bf/s    .L6
        fmov.s  fr0,@-r2
        add     #64,r14
        mov     r14,r15
        lds.l   @r15+,pr
        mov.l   @r15+,r14
        rts
        mov.l   @r15+,r8

The same problem seems to happen on x86 and other targets as well.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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