Andrew Haley <[EMAIL PROTECTED]> writes:

> It appears that memory references to arrays aren't being hoisted out
> of loops: in this test case, gcc 3.4 doesn't touch memory at all in
> the loop, but 4.3pre (and 4.2, etc) does.
> 
> Here's the test case:
> 
> void foo(int *a)
> {       int i;
>         for (i = 0; i < 1000000; i++)
>    a[0] += a[1];
> }

At the tree level, the problem is that the assignment to a[0] is seen
as aliasing a[1].  This causes the use of a[1] to look like a USE of
an SMT, and the assignment to a[0] to look like a DEF of the same
SMT.  So in tree-ssa-loop-im.c the statements look like they are not
loop invariant.

I don't know we can do better with our current aliasing
representation.  Unless we decide to do some sort of array SRA.

Or perhaps we could make the loop invariant motion pass more
complicated: when it sees a use or assignment of a memory tag, it
could explicitly check all the other uses/assignments in the loop and
see if they conflict.  I don't really know how often this would pay
off, though.

At the RTL level we no longer try to hoist MEM references out of
loops.  We now assume that is handled at the tree level.

Ian

Reply via email to