Download presentation
Presentation is loading. Please wait.
Published byAnne Adams Modified over 9 years ago
1
Toward Efficient Flow-Sensitive Induction 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
2
Outline Motivation The CR# Algebra Flow-Sensitive Induction Variable Analysis Algorithms with CRs on SSA forms Application: Data Dependence Testing Conclusions
3
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
4
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
5
Motivating Examples k = 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
6
More Powerful IV Recognition Methods IV recognition can quickly gets more complicated with deps and flow Induction variable recognition with chains of recurrences by van Engelen Linear, nonlinear and conditional IV Further improve other compiler optimizations Extend IV analysis algorithm based on CR# algebra on SSA form
7
Outline Motivation The CR# Algebra Flow-Sensitive Induction Variable Analysis Algorithms on SSA forms Application: Data Dependence Testing Conclusions
8
Preliminaries Basic form: Ф i = { ϕ 0, ⊙ 1, f 1 } i, where ⊙ 1 = + or * A value sequence with initial value ϕ 0 updated by adding or multiplying the current value by step function f 1 When f 1 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
9
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, +, f 1 } i i * f 1
10
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}
11
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 values 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
12
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 = 2 i 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
13
Outline Motivation The CR# Algebra Flow-Sensitive Induction Variable Analysis Algorithms on SSA forms Application: Data Dependence Testing Conclusions
14
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.
15
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
16
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 two nodes in the set. Collect initial value and induction sequence information in the SCR cycle. Determine recurrence relations and then CR form of the induction variable
17
Example 1: Linear recurrences pattern 1 a1a1 a0a0 + a2a2 1 x0x0 + 2 Original loop nest: a := 1 while (a<10) { x := a + 2 a := a+1 } SSA form: a 0 := 1 if (a 0 >=10) goto L2 L1: a 1 := (a 0, a 2 ) x 0 :=a 1 + 2 a 2 := a 1 +1 if (a 2 <10) goto L1 L2: Recurrence Relations Set: CR form for variable a 1 {1, +, 1}
18
Example 2: Non-linear recurrences pattern x := 0 i := 1 while (i<10) { x := x+i i := i+1 } x 0 := 0 i 0 := 1 if (i 0 >=10) goto L2 L1: x 1 := (x 0, x 2 ) i 1 := (i 0, i 2 ) x 2 := x 1 +i 1 i 2 := i 1 +1 if (i 2 <10) goto L1 L2: Recurrence Relations Set: CR form: i1: {1,+, 1} x1: {0, +, 1, +, 1} 1 i1i1 i0i0 + i2i2 1 x1x1 x0x0 0 + x2x2
19
Example 3: Conditional recurrences pattern 0 j1j1 j0j0 + j4j4 2 j2j2 j3j3 + 3 j := 0 i := 1 while (i<10) { if (p) then j := j+2 else j := j+3 i = i + 1 } j 0 := 0 i 0 := 1 if (i 0 >=10) goto L2 L1: i 1 := (i 0, i 2 ) j 1 := (j 0, j 4 ) if (p) j 2 := j 1 +2 goto L3 j 3 := j 1 +3 L3: j 4 := (j 2, j 3 ) i 2 := i 1 +1 if (i 2 <10) goto L1 L2: Recurrence Relations Set:,
20
Example 4: Conditional and Wrap Around Recurrences
21
Outline Motivation The CR# Algebra Flow-Sensitive Induction Variable Analysis Algorithms on SSA forms Application: Data Dependence Testing Conclusions
22
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 updated variables and pointers arithmetic.
23
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
24
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) = {x 0, +, 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
25
Example: Loop NestCR 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 P 1 : {A, +, 1} q 1 : Min CR: {A+n, +, 1} Max CR: {A+n, +, 2} Low({A+n, +, 1} – {A, +, 1}) = n > n -1 >= 0
26
Conclusions The CR-based compiler analysis framework supports: IV recognition Array dependence testing with affine, nonlinear, and symbolic dependence 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 compiler optimizations
27
Thanks
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.