Digital Signal Processing Reference
In-Depth Information
a
b
for
(i = 0; i
<
M;
i ++)
{
for
(i = 0; i
<
M;
i ++)
{
for
(j = 0; j
M;
j ++)
{
for
(j = 0; j
M;
j ++)
{
<
<
a[i ][ j] = 5
∗
j;
∗
(a+M
∗
i+j ) = 5
∗
j;
}
}
}
}
Fig. 10
a
b
ivar pa = a;
for
(i = 0; i
<
M;
for
(i = 0; i
<
M;
i ++)
{
i ++)
{
pa = a+M
∗
i;
ivar1 j=ivarpa ;
ivar2 j=0;
for
(j = 0; j
<
M;
for
(j = 0; j
<
M;
j ++)
{
j ++)
{
∗
(pa+j) = 5
∗
j;
∗
( ivar1 j) = ivar2 j;
ivar1 j++;
ivar2 j+=5;
ivar pa += M;
}
}
}
(
b
) After induction variable creation
3.3.5
Loop Invariant Code Motion
and, hence, reduces the number of instructions executed per loop iteration. An
only dependent on the outer loop iterator
i
, but is constant for any value of the inner
loop iterator
j
. “Hoisting” this constant subexpression out of the
j
-loop results in the
constant expression, it is also amendable to further optimization.
Strength Reduction
with a cheaper addition, and
Induction Variable Creation
can eliminate the use of
the loop iterator
j
in favor of an induction variable incremented in each iteration that
offered by many DSPs.
Before any loop-invariant computation can be moved out of a loop the compiler
needs to verify this property. This is easy for genuine constants. For general
expression it must be shown that all reaching definitions of the arguments of an
expression are outside the loop. After that a new block of code containing the
hoisted, loop-invariant computation is inserted as a
pre-header
to the loop.