stores inside loops

Paul Koning pkoning@xedia.com
Thu Nov 6 14:54:00 GMT 1997


I'm seeing a lack of optimization that surprises me...

Given the following:

extern int a[100], b[100];
extern int s;

void foo(void)
{
	int i;
	s = 0;
	for (i=0;i<100;i++)
		s += a[i] * b[i];
}

I did gcc -O3 -S for {arm, sparc, mips64, x86} and on all of these
ended up with code that does the load and store of "s" INSIDE the
loop.

Given that s is not declared volatile I had expected that the
optimizer would move the load and store outside the loop.  Was that an
unreasonable expectation?

	paul



More information about the Gcc mailing list