Loop oddity
law@redhat.com
law@redhat.com
Tue Jan 22 11:12:00 GMT 2002
In message <200201221708.g0MH8hj4015272@hiauly1.hia.nrc.ca>, "John David Anglin
" writes:
> Here is a loop oddity that I noticed. The loop
>
> for (i = 1000000; i; i--) {};
>
> yields the following assembly code when compiled at -O2 on the PA:
>
> ldil L'999424,%r19
> ldo 576(%r19),%r19
> ldo -625(%r19),%r19
> L$0109
> comib,<>,n 0,%r19,L$0109
> ldo -625(%r19),%r19
>
> You get similar results on other architectures. I was mystified by
> the transformation of the decrement from 1 to 625. Looking
> at the output of the loop pass, I see that it has unrolled the loop:
[ ... ]
The documentation needs to be updated.
The compiler will estimate the size of a rolled and unrolled loop -- if the
unrolled loop is likely to be as small or smaller than the rolled loop, then
it will proceed to unroll the loop.
jeff
More information about the Gcc
mailing list