Strength Reduction (SR) [2] replaces expensive
operations by equivalent cheaper ones from the target machine
language. Some machine instructions are considerably cheaper than
others and can often be used as special cases of more expensive
operators. For instance, is invariably cheaper to implement as
than as a call to an exponentiation routine. Moreover, an
additive operator is generally cheaper than a multiplicative operator.
Some loops have a variable that is incremented or decremented, and
a variable that is set in the loop to where and
are loop-invariant. Then we can calculate 's value without
reference to ; whenever is incremented by we can increment
by

Figure 5.3:
Before and After Strength Reduction

s = 0 s = 0
i = 0 k = a
L1: if i < n goto L2 b = n * 4
j = i * 4 c = a + b
k = j + d L1: if k < c goto L2
x = M[k] x = M[k]
s = s + x s = s + x
i = i + 1 k = k + 4
goto L1 goto L1
L2 L2
(a) Before (b) After

The program (a) from Figure 5.3 is a program to sum the
elements of an array. Using induction variable analysis to find
that and are related induction variables,
strength reduction to replace a multiplication by 4 with an
addition, then induction variable elimination to replace
by
, we get the program (b).
We have reviewed the key features of SR and its
algorithm briefly. SR is a very powerful algorithm to
transform computations involving multiplications and additions
together into computations only using additions. Thus, it could be a
very competitive candidate to optimize the current HPJava compiler
because of the complexity of the associated terms in the subscript
expression of a multiarray element access.

Figure 5.4:
Translation of overall construct, applying Strength Reduction.

SOURCE:

TRANSLATION:

where:

Before applying PRE and SR to some scientific
algorithms, we can apply this SR technique on the
basic translation of overall construct in the subsection
4.5.5. The naive translation generates a local subscript,
sub, and a global subscript, glb for the index i. We
call these two variables, control subscripts for the index
i. The computations for the control subscripts are obviously
amenable to SR. Thus, Figure 5.4
shows the translation scheme for overall after applying Strength
Reduction.
Next:Dead Code Elimination Up:Optimization Strategies for HPJava Previous:Partial Redundancy EliminationContents
Bryan Carpenter
2004-06-09