[PATCH] for optimization/10080: Loop unroller nearly useless

Richard Henderson rth@redhat.com
Wed Mar 19 05:19:00 GMT 2003


On Wed, Mar 19, 2003 at 01:58:51AM +0100, Zdenek Dvorak wrote:
> > Many, but *definitely* not all.  Firstly, constant iteration
> > is much more common.
> 
> Sure about this statement? I don't think so, but I haven't seen any
> statistics.

Fairly sure.

> I agree. In fact I am almost sure nothing wrong can happen in this
> case anyway -- the counts here are always taken mod small power of 2,
> so subregs should not matter.

Err, so are you or are you not handling loops like

	unsigned int i;
	for (i = 0; i != 1; i += 5)
	  ...

which iterates UINT_MAX*4+1 times?  Please tell me you are...

> > This is a very bad attitude to have wrt optimization.
> > Repeat after me: "We shall always produce correct code!"
> 
> this is why I would do it only when specifially asked to by special
> flag.

No.

> IMHO this is much better than either ignoring the border cases
> silently (as it is done on many places in gcc) or always decreasing
> effectivity of optimizations due to cases that really do not exist in
> practice.

No.  For these cases we should generate two sets of code.  One
that is optimized for a specific set of assumptions, and another
that isn't.  E.g.

	unsigned int i, b, e, c;
	for (i = b; i < e; i += c)
	  ...

    =>

	if (b < e && n <= UINT_MAX-c+1)
	  // unroll as desired, known that overflow is impossible.
	else
	  // generate straight copy, known that overflow *will* happen.



r~



More information about the Gcc-patches mailing list