Toward Efficient Flow-Sensitive Induction Variable Analysis and Dependence Testing for Loop...
-
Upload
anne-adams -
Category
Documents
-
view
218 -
download
0
Transcript of Toward Efficient Flow-Sensitive Induction Variable Analysis and Dependence Testing for Loop...
Toward Efficient Flow-SensitiveInduction Variable Analysis and Dependence Testing for Loop Optimization
Yixin Shou, Robert A. van Engelen, Johnnie Birch, Kyle A. Gallivan
Restructuring Compilers Research Lab
Florida State University
Outline
Motivation The CR# Algebra
Flow-Sensitive Induction Variable Analysis Algorithms with CRs on SSA forms
Application: Data Dependence Testing
Conclusions
Motivation Induction Variable Recognition: a Classic Compiler
Problem Most Loop Optimizations Rely on Accurate IV
Recognition Loop strength reduction IV elimination IV substitution Array recovery Array data dependence testing
Problem nonlinear IV conditionally updated IV Pointer arithmetic in loops
Motivating Examples (cont.)
Conditional updated IV and partial wrap around variables in loops
do l = 1, latt(1)
if (...) then
nred = nred+1
lisred(nred) = ...
else
...
endif
...
end do
k = 0
do j = 1, n
a[k] = ...
if (...) then
k = k+1
else
k = j
endif
...
end do
k = 0
do j = 1, n
a[j-1] = ...
...
end do
(a) Loop from QCD Benchmark
(b) Original Loop (c) Optimized Loop
Motivating Examplesk = 1
Do j = 1, n
a[k]= ...
if (...) then
k = k+2
else if (...) then
k = j
else
...
endif
enddo
Example Loop Bounding Functions
IVs which do not have closed forms
0
5
10
15
20
25
30
35
0 1 2 3 4 5Index iV
alu
e S
eq
ue
nc
e o
f F
un
cti
on
g(i)f(i)
More Powerful IV Recognition Methods IV recognition can quickly gets more complicated
with deps and flow Induction variable recognition with chains of recur
rences by van Engelen Linear, nonlinear and conditional IV Further improve other compiler optimizations
Extend IV analysis algorithm based on CR# algebra on SSA form
Outline
Motivation The CR# Algebra
Flow-Sensitive Induction Variable Analysis Algorithms on SSA forms
Application: Data Dependence Testing Conclusions
Preliminaries
Basic form:
Фi = {ϕ0, ⊙1, f1}i, where ⊙1 = + or *
A value sequence with initial value ϕ0 updated by adding or multiplying the current value by step function f1
When f1 is another CR form, this produces a chain of recurrences
Фi = {ϕ0, ⊙1, {ϕ1, ⊙2, {ϕ2,..., ⊙k, {ϕk}i}i}i}i
which is usually written in flattened form
Фi = {ϕ0, ⊙1, ϕ1, ⊙2, ϕ2,..., ⊙ k, ϕ k}i Multi-variate CR forms
CR coefficients are nested CR forms of a different grid variable
A chain of recurrences (CR) represents a polynomial or exponential function or mix evaluated over a unit-distance grid
Chains of Recurrences: Algebra
CR simplification rules produces an equivalent CR expression that can be evaluated more efficiently.
CR Inverse rules (CR-1) derive a closed form functions corresponding to CR expressions.
Some selected rules
{x, +, y} + c {x+c, +, y}
c{x, +, y} {c·x, +, c·y}
{x, +, y} + {u, +, v} {x+u, +, y+v}
{x, +, y} * {u, +, v} {x·u, +, y{u, +, v}+v{x, +, y}+y·v}
{0, +, f1}i i * f1
How to Obtain CR Forms using CR Algebra
Algorithm to compute the CR form of a symbolic function f(i):
1. Replace index i with its CR form {0,+,1} in the symbolic form of f
2. Compute CR form using the CR algebra rewrite rules
Example:
f(i) = c·(i+a) = c·({0, +, 1}+a) = c{a, +, 1} = {c·a, +, c}
CR# Alignment and Bounds CR# Algebra: a new extension of CR algebra The Delay Operator #
Define recurrences with out of sequence values CR form with Delayed operator can be used to define any sequence of v
alues followed by a polynomial, geometric CR form, or another delayed form.
wrap-around variables can be accurately represented using delayed forms
Aligned CR forms Same index variable Same length Operators pairwise match
CR Alignment Rules Lemma 1, 2, 3
Compute bounds for two CR form after CR alignment
Example Close form function of CRs
f(i) = {1, #, 1, +, 2}i = 1 if i = 0
2*i -1 if i > 0 g(i) = {1, *, 2}i = 2i for i = 0…n
After CR alignment f(i) = {1, #, 1, +, 2}i = {1, #, 1, +, 2, *, 1}i
g(i) = {1, *, 2}i = {1, #, 2, *, 2}i = {1, #, 2, +, 2, *, 2}i
After CR Bounding Min({1, #, 1, +, 2, *, 1}i , {1, #, 2, +, 2, *, 2}i) = {1, #, 1, +, 2, *, 1}I
Max({1, #, 1, +, 2, *, 1}i , {1, #, 2, +, 2, *, 2}i) = {1, #, 2, +, 2, *, 2}I
0
5
10
15
20
25
30
35
0 1 2 3 4 5Index iV
alu
e S
equ
ence
of
Fu
nct
ion
f(i) g(i)
Outline
Motivation The CR# Algebra
Flow-Sensitive Induction Variable Analysis Algorithms on SSA forms
Application: Data Dependence Testing Conclusions
SSA Form
Static Single Assignment (SSA) Form: a internal compiler representation each use refers to a single definition each definition has a unique name by attaching indices to variables The compiler inserts special join functions (called -functions) at points where
different control flow paths meet.
Advantage of SSA explicit def-use pairs to help compiler data flow optimizations no anti and output data dependences Compiler dataflow optimizations algorithms are strongly enhanced by using SSA
forms.
Integrate CR Approach on SSA Form
Static Single Assignment (SSA) form is used in many modern compilers to facilitate a wide range of powerful compiler dataflow optimizations.
CR representation is a very effective form for induction expression in loops and facilitate the loop analysis, optimization and dependence testing.
Integrate the CR approach in SSA forms improve many data flow analysis and dependence testing. Make our unified CR framework adapt to a much wider range of
compilers
Flow-Sensitive Induction Variable Analysis Algorithms on SSA forms
The algorithm for IV recognition with CRs is based on A major observation from Gerlek, Stolz, and Wolfe
A strongly connected region (SCR) of SSA chain graph represent a induction variable in the loop. SCR: a set of node in the graph where there exist a path for any t
wo nodes in the set. Collect initial value and induction sequence information in the SCR cycl
e. Determine recurrence relations and then CR form of the induction vari
able
Example 1: Linear recurrences pattern
1
a1
a0
+a2
1
x0
+
2
Original loop nest:
a := 1
while (a<10) {
x := a + 2
a := a+1
}
SSA form:
a0 := 1if (a0>=10) goto L2L1:
a1 := (a0, a2)
x0 :=a1 + 2
a2 := a1+1 if (a2<10) goto L1
L2:
Recurrence Relations Set:
<a1, (1, a1+1)>
CR form for variable a1
{1, +, 1}
Example 2: Non-linear recurrences patternx := 0
i := 1
while (i<10) {
x := x+i
i := i+1
}
x0 := 0i0 := 1if (i0>=10) goto L2L1:
x1:= (x0, x2) i1 := (i0, i2) x2 := x1+i1 i2 := i1+1 if (i2<10) goto L1 L2:
Recurrence Relations Set:
<i1, (1, i1+1)>
<x1, (0, x1+i1)>
CR form:i1: {1,+, 1}
x1: {0, +, 1, +, 1}
1
i1
i0
+i2
1x1
x0
0
+x2
Example 3: Conditional recurrences pattern
0
j1
j0
+
j4
2
j2
j3
+
3
j := 0 i := 1 while (i<10) { if (p) then j := j+2 else
j := j+3 i = i + 1 }
j0 := 0 i0 := 1if (i0>=10) goto L2
L1: i1 := (i0, i2)
j1:= (j0, j4)
if (p)
j2 := j1+2 goto L3
j3 := j1+3
L3: j4:= (j2, j3)
i2 := i1+1 if (i2<10) goto L1
L2:
Recurrence Relations Set:
<i1, (1, i1+1)>
<j1, (0, j1+2)>, <j1, (0, j1+3)>
Example 4: Conditional and Wrap Around Recurrences
Outline
Motivation The CR# Algebra
Flow-Sensitive Induction Variable Analysis Algorithms on SSA forms
Application: Data Dependence Testing Conclusions
Data Dependence testing Based on CR# algebra
Accurate data dependence testing is crucial for parallelizing compilers
Benefits of Array & Pointer Dependence Testing with CRs Directly build the dependence equation based on CR forms
Eliminates IV substitution phase Eliminates the need for pointer-to-array conversion for dependence testing
on pointer-based C code Able to solve dependence with linear, nonlinear, conditional upd
ated variables and pointers arithmetic.
CR Dependence Equations Compute dependence equations in CR form for
pointer and array accesses in loop nests directly without IV substitution or pointer-to-array conversion
Solve the equations by computing value ranges of the CR forms to determine solution intervals
If the solution space is empty, there is no dependence
Determining the Value Range of a CR Form on a Domain
If a function is monotonic on its domain, then it is trivial to find its exact value range
The monotonic properties of a CR form are determined by the stepping functions
Suppose x(i) = {x0, +, s(i-1)} for i = 0, …, n If s(i-1) > 0 then x(i) is monotonically increasing If s(i-1) < 0 then x(i) is monotonically decreasing
Example:
Loop Nest CR Solution
Lower Bound of Dependence Equation
p = A
q = A+n
for (i=0 to n-1)
*p++ = *q++
if … then q = q+1
endif
endfor
P1:
{A, +, 1}
q1:
Min CR:
{A+n, +, 1}
Max CR:
{A+n, +, 2}
Low({A+n, +, 1} –
{A, +, 1})
= n > n -1 >= 0
Conclusions The CR-based compiler analysis framework supports:
IV recognition Array dependence testing with affine, nonlinear, and symbolic dependen
ce equations Dependence testing on pointer arithmetic Induction variable substitution
Flow-sensitive generalized induction variables (GIVs) analysis algorithm based on CR# algebra are able to analyze nonlinear index expression Non-closed index expression Enhance the monotonic analysis, data dependence testing and other co
mpiler optimizations
Thanks