Visual Studio .NET vs GCC

tm_gccmail@mail.kloo.net tm_gccmail@mail.kloo.net
Thu Feb 27 02:51:00 GMT 2003


I spent a few hours looking at Visual Studio .NET code generation vs.
GCC CVS on the SH4, and found some interesting details.

Here's the function I was analyzing:

int
integer_test(int i)
{
        int j;
        int a[256];

        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];
}

VS .NET manages to unroll the loop and put a[0] through a[7] in registers.
The loop winds up looking like this:

	add	r1,r15
	add	r11,r0
	add	r8,r0
	add	r9,r0
	add	r12,r0
	...
	add	r10,r0
	add	r13,r0
	...
	add	r3,r0

GCC using -funroll-loops is unable to keep the values in registers, and
generates stores (aliasing problems?):

        mov     r14,r1
        add     #8,r1
        mov.l   @r1+,r2
        add     r2,r0
        mov.l   r0,@(28,r14)
        mov.l   @r1+,r2
        add     r2,r0
        mov.l   r0,@(28,r14)
        mov.l   @r1+,r2
        add     r2,r0
        mov.l   r0,@(28,r14)
        mov.l   @r1+,r2
        add     r2,r0
        mov.l   r0,@(28,r14)
        add     r7,r14
        mov.l   @r1,r1
        add     r1,r0
        mov     r14,r15
        lds.l   @r15+,pr
        mov.l   @r15+,r14
        rts
        mov.l   @r15+,r8

What's interesting is:

1) VS.NET seems to have much better alias analysis capability than gcc

2) VS.NET can registerize parts of arrays

Toshi



More information about the Gcc-bugs mailing list