------- Comment #17 from rguenther at suse dot de 2006-04-10 08:10 ------- Subject: Re: loop header should also be pulled out of the inner loop too
On Mon, 9 Apr 2006, rakdver at gcc dot gnu dot org wrote: > (In reply to comment #14) > > (In reply to comment #11) > > > I updated the patch for current mainline, but it still has issues for some > > > common uses of loops: > > > > > > void foo(int *ie, int *je, double *x) > > > { > > > int i, j; > > > for (j=0; j<*je; ++j) > > > for (i=0; i<*ie; ++i) > > > x[i+j] = 0.0; > > > } > > > > > > After loop header copying we have > > > > > > if (*je > 0) > > > for (j=0; j<*je; ++j) > > > if (*ie > 0) > > > for (i=0; i<*ie; ++i) > > > x[i+j ] = 0.0; > > > > > > note how in this form we see the condition *ie > 0 not invariant wrt the > > > outer loop (because it does a memory load), but if we would run load-PRE > > > between loop header copying and guard hoisting we would get > > > > actually, thinking about it again, it should suffice to teach > > invariant_without_guard_p about invariant memory loads, and this should just > > work. > > It basically does, the only other problem is that we are not able to determine > that the outer loop is not infinite. It that because we don't recognize the condition of the loop header? Otherwise we know that *je > 0 and the loop runs from 0 to *je (in fact, I have loop determine the number of iterations of the loop to be *je). Of course this is with load-PRE moving the load before the loop-header and thus SCEV being presented with D.xxx = *je; if (D.xxx > 0) for (j=0; j<D.xxx; ++j) ... which it just handles fine. It looks like a chicken-and-egg problem ;) Richard. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23855