This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Visual Studio .NET vs GCC
- From: <tm_gccmail at mail dot kloo dot net>
- To: gcc-bugs at gcc dot gnu dot org
- Cc: joern dot rennecke at superh dot com, aoliva at redhat dot com
- Date: Wed, 26 Feb 2003 19:41:15 -0800 (PST)
- Subject: Visual Studio .NET vs GCC
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