Re: Loop Unroll

Christian Bau <christian.bau@isltd.insignia.com>
22 May 2001 13:33:05 -0400

          From comp.compilers

Related articles
Loop Unroll lxh@arch.cs.pku.edu.cn (Alkaid) (2001-05-18)
Re: Loop Unroll mike@dimmick.demon.co.uk (Mike Dimmick) (2001-05-21)
Re: Loop Unroll gvmt@bgl.vsnl.net.in (Venkatesha Murthy G.) (2001-05-21)
Re: Loop Unroll samiam@cisco.com (Scott Moore) (2001-05-21)
Re: Loop Unroll rkrayhawk@aol.com (2001-05-21)
Re: Loop Unroll christian.bau@isltd.insignia.com (Christian Bau) (2001-05-22)
| List of all articles for this month |
From: Christian Bau <christian.bau@isltd.insignia.com>
Newsgroups: comp.compilers
Date: 22 May 2001 13:33:05 -0400
Organization: Insignia Solutions plc
References: 01-05-046
Keywords: optimize
Posted-Date: 22 May 2001 13:33:05 EDT

Alkaid wrote:
> When we do ILP optimization, loop unrolling is a kind of method.
> But there is a question: if loop time is a big prime number, how to
> unroll the loop? e.g. when loop time is 100, I can unroll the loop
> 4 times to get a new one which has 25 iterations. What shall I do if
> the loop time is 101?


The simple answer: 25 iterations four times unrolled, and one iteration
not unrolled.


The more complicated answer: Usually you don't want to do only loop
unrolling, but you want to mix the operations from all (lets say four)
iterations to get better scheduling. For example,


for (i = 0; i < n; ++i) a [i] = b [i] + 1.0;


you want to change the instruction order from


load, add, store,
load, add, store,
load, add, store,
load, add, store


to something like


load, load, load, add
load, add
add, store
add, store, store, store


which will give you much better scheduling on some processors. This is
not always legal, depending on how the arrays a and b overlap. So what
you do is this:


if (n > 0) {
int single_iterations = unrolling_illegal () ? n : n % 4;
for (i = 0; i < single_iterations; ++i) {
single iteration;
}
for (; i < n; i += 4) {
four iterations;
}
}


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.