not hoisting loads/stores

Dan Nicolaescu dann@godzilla.ICS.UCI.EDU
Sat Dec 4 13:31:00 GMT 1999


Hi!

Here is a simple example where gcc does not hoist loads/stores out of
a loop. 

I don't see any reason why it shouldn't do it... 

gcc -v 

Reading specs from /home/dann/local/packages/gcc-2211/lib/gcc-lib/sparc-sun-solaris2.7/2.96/specs
gcc version 2.96 19991122 (experimental)


--test.c--
typedef struct  {
  int     n_m;
  float* x_m;
} test_struct;

void
f (test_struct s)
{
  int i;
  for (i=0; i < s.n_m; ++i)
    s.x_m[i] = s.n_m;
}
--end test.c--

compiled with gcc -O2 -fstrict-aliasing -S

Here is the generated sparc assembly:

	.file	"test.c"
gcc2_compiled.:
.section	".text"
	.align 4
	.global f
	.type	 f,#function
	.proc	020
f:
	!#PROLOGUE# 0
	add	%sp, -120, %sp
	!#PROLOGUE# 1
	ld	[%o0], %o2
	mov	0, %o1
	cmp	%o1, %o2
	bge	.LL4
	nop
	ld	[%o0+4], %o3
.LL6:
	st	%o2, [%sp+100]
	ld	[%sp+100], %f3
	^^^^^^^^^^^
	those could be hoisted outside the loop

	sll	%o1, 2, %o0
	fitos	%f3, %f2
	^^^^^^
	this one too

	add	%o1, 1, %o1
	cmp	%o1, %o2
	bl	.LL6
	st	%f2, [%o3+%o0]
.LL4:
	retl
	sub	%sp, -120, %sp
.LLfe1:
	.size	 f,.LLfe1-f
	.ident	"GCC: (GNU) 2.96 19991122 (experimental)"



If I change the type of x_m to be long* everything is fine. 

Any ideas? 

Thanks.
	--dan


More information about the Gcc mailing list