[comp.lang.c] What is loop unfolding

bright@Data-IO.COM (Walter Bright) (09/09/88)

In article <403@marob.MASA.COM> samperi@marob.masa.com (Dominick Samperi) writes:
>Sorry for jumping into this discussion rather late, but could someone
>please give a brief definition of "loop unrolling."

It is the conversion of loops like:
	for (i = 0; i < 2; i++)
	    foo(i);
into:
	i = 0; foo(i);
	i = 1; foo(i);
	i = 2;
Constant propagation and dead assignment elimination is then done in an
attempt to reduce the above to:
	foo(0);
	foo(1);

Note: my optimizer does not do loop unrolling. Loop unrolling is, however,
common among Fortran optimizers.