Presentation is loading. Please wait.

Presentation is loading. Please wait.

Value Range Analysis with Modulo Interval Arithmetic

Similar presentations


Presentation on theme: "Value Range Analysis with Modulo Interval Arithmetic"— Presentation transcript:

1 Value Range Analysis with Modulo Interval Arithmetic
Tsuneo Nakanishi and Akira Fukuda Nara Institute of Science and Technology, Japan

2 Topics Research Background Modulo Interval Arithmetic
Modulo Interval Propagation Conclusion

3 Research Background

4 Research Background (1)
Value ranges taken by variables and expressions of a given program is often required for Code Analyzing and Optimization by Compilers Debugging and Testing by Programmers What values does this variable take? DO I=1, 1000, 2 S1: TMP = A(3I-1)+A(3I)+A(3I+1) S2: A(I) = TMP / 3 EndDO What values does this expression take?

5 Research Background (2)
Most general value range representation is the interval. R a b [a, b] The interval is a sufficient representation as value range representation for compilers and programmers? Absolutely NO. For example, integers taken by loop indices and array subscripts have some strides. The interval cannot represent strides.  We proposed the modulo interval and modulo interval arithmetic.

6 Modulo Interval Arithmetic

7 Interval Arithmetic (1)
Interval on R R a b [a, b] [a, b] = { x  R | a  x  b } Interval Arithmetic Arithmetic defined on intervals of R, which was invented by Sunaga (Japan) in 50s and well-organized by Moore (US) in 60s. Used for floating-point error estimation.

8 Interval Arithmetic (2)
Arithmetic Operations Addition [a, b] + [c, d] = [a + b, c + d] [ 3, 8 ] + [ 5, 10 ] = [ 8, 18 ] Subtraction [a, b] – [c, d] = [a – d, b – c] [ 2, 9 ] – [ 4, 8 ] = [ –6, 5 ] Multiplication [a, b] * [c, d] = [min{ac, ad, bc, bd}, max{ac, ad, bc, bd}] [ 2, 3 ] * [ 3, 5 ] = [ 6, 15 ] Division, Exponentiation, etc.

9 Modulo Interval Arithmetic (1)
Modulo Interval on Z R [a, b] n r [a, b]n(r) [a, b]n(r) = { x  Z | a  x  b, x = nm + r, m  Z } [2, 17]5(2) = { 2, 7, 12, 17 } [7, 21]7(0) = { 7, 14, 21 }

10 Modulo Interval Arithmetic (2)
Arithmetic Operations Addition [a, b]m(r) + [c, d]n(s)  [a + c, b + d]gcd(m, n)(r + s) [ 2, 10 ]4(2) + [ 3, 23 ]4(3)  [ 5, 33 ]4(5) = [ 5, 33 ]4(1) Subtraction [a, b]m(r) – [c, d]n(s)  [a – d, b – c]gcd(m, n)(r – s) [ 2, 10 ]4(2) – [ 3, 21 ]6(3)  [ –19, 7 ]2(–1) = [ –19, 7 ]2(1) Multiplication [a, b]m(r) * [c, d]n(s)  [min{ac, ad, bc, bd}, max{ac, ad, bc, bd}]gcd(m, n)(rs) [ 2, 10 ]4(2) * [ 3, 21 ]4(3)  [ 6, 210 ]4(6) = [ 6, 210 ]4(2)

11 Modulo Interval Arithmetic (3)
Arithmetic Operations with Integers Addition [a, b]m(r) + z = [a + z, b + z]m(r + z) [ 2, 10 ]4(2) + 3 = [ 5, 13 ]4(5) = [ 5, 13 ]4(1) z + [a, b]m(r) = [z + a, z + b]m(z + r) 3 + [ 2, 10 ]4(2) = [ 5, 13 ]4(5) = [ 5, 13 ]4(1) Subtraction [a, b]m(r) – z = [a – z, b – z]m(r – z) [ 2, 10 ]4(2) – 3 = [ –1, 7 ]4(–1) = [ –1, 7 ]4(3) z – [a, b]m(r) = [z – b, z – a]m(z – r) 3 – [ 2, 10 ]4(2) = [ –7, 1 ]4(1) = [ –7, 1 ]4(1)

12 Modulo Interval Arithmetic (4)
Arithmetic Operations with Integers Multiplication [a, b]m(r) * z = [az, bz]mz(rz) [ 2, 10 ]4(2) * 3 = [ 6, 30 ]12(6) z * [a, b]m(r) = [az, bz]zm(zr) 3 * [ 2, 10 ]4(2) = [ 6, 30 ]12(6)

13 Modulo Interval Arithmetic (5)
Set Operations: Intersection [a, b]m(r)  [c, d]n(s) If b – c is divisible by gcd(m, n), [a, b]m(r)  [c, d]n(s) = [max{a, c}, min{b, d}]lcm(m, n)(z) z is an integer such that z  r (mod m), z  s (mod n). If b – c is not divisible by gcd(m, n), [a, b]m(r)  [c, d]n(s) =  Set Operations: Union [a, b]n(r) = [a, b]nm(r)  [a, b]nm(n+r)  …  [a, b]nm(n(m1) + r) [ 2, 17 ]5(2) = [ 2, 17 ]10(2)  [ 2, 17 ]10(7)

14 Modulo Interval Propagation

15 Monotonic Data Flow System
A unified algorithm for data flow analysis and optimization problems: Constant Propagation, Live Variable Analysis, Definition Reachability Analysis, etc. Propagating and processing data flow information held at each node of a given control flow graph until convergence.

16 Data Flow Information Data Flow Information for Modulo Interval Propagation: A set of tuples consisting of variable names and modulo intervals representing the value ranges of the variables. (x, [1, 99]2(1)) (y, [–32, 32]2(0))

17 Modulo Interval Propagation (1)
Assignment Statement (x1, X1), (x2, X2), … y = g(x1, x2, …) (x1, X1), (x2, X2), …, (y, g(X1, X2, …))

18 Modulo Interval Propagation (2)
Assignment Statement (ex.) (x, [1, 99]2(1)) (y, [–32, 32]2(0)) z = x + y * 2 z = [1, 99]2(1) + [–32, 32]2(0) * 2 (x, [1, 99]2(1)) (y, [–32, 32]2(0)) (z, [–63, 163]4(1))

19 Modulo Interval Propagation (3)
Conditional Branch (x1, X1), (x2, X2), … if (p(x, y)) T F {(x1, X1), (x2, X2), …,}  {(x, Xi): p(X1, X2, …) = true} {(x1, X1), (x2, X2), …,}  {(xi, Xi): p(X1, X2, …) = false}

20 Modulo Interval Propagation (4)
Conditional Branch (x, [1, 99]2(1)) (y, [1, 99]2(1)) if (x + y  100) {(x, [1, 99]2(1)), (y, [1, 99]2(1)), …,}  {(x, X)  (y, Y): x  X, y  Y, x + y  100} T F {(x, [1, 99]2(1)), (y, [1, 99]2(1)), …,}  {(x, X)  (y, Y): x  X, y  Y, not x + y  100}

21 Modulo Interval Propagation (5)
Condition: x + y  100 Input Data Flow Information: (x, [1, 99]2(1)), (y, [1, 99]2(1)) Bound x to [1, 99]2(1) . y  100 – [1, 99]2(1) y  [–∞, 99]1(0) Bound y to [1, 99]2(1) . x  [–∞, 99]1(0) Output Data Flow Information of True Clause:

22 Induction Variable Problem (1)
for (i = 1, sum=0; i <= 100; i++) { sum = sum + i; } Induction variables require considerable computation time to obtain their value ranges by modulo interval propagation. Value ranges of induction variables can be too overestimated by modulo interval propagation. (In the above example, tha value range of sum is estimated as [0, 10000]1(0) , whereas it is [0, 5050]1(0).)

23 Induction Variable Propagation (2)
Apply modulo interval propagation after eliminating induction variables (or with supposing that induction variable was eliminated). Before elimination sum = sum + i After elimination sum = (i + 1) * i / 2 Make special treatment for some typical inductive operations such as summation, minimum, and maximum.

24 Related Works W. H. Harrison, “Compiler Analysis of the Value Ranges for Variables,” IEEE Trans. on Software Engineering, Vol.SE-3, No.3, pp.243–250, May 1977. O. Ogawa et al., “Hardware Synthesis from C Programs with Elimination of Bit Length of Variables,” IEICE Trans. On Fundamentals, Vol.E82-A, No.11, pp.2338–2346, Nov A monotone data flow system based algorithm A value range analysis with intervals ( modulo intervals) Simple conditional expressions only ( complicated conditional expressions) Induction variable problem (= not be solved yet)

25 Conclusion

26 Conclusion Introduce Modulo Interval Arithmetic
An extension of Interval Arithmetic Simple representation of a set of integers for program analysis Concrete arithmetic system on a set of integers Propose Modulo Interval Propagation A value range analysis technique with modulo interval arithmetic A monotone data flow system based algorithm Induction variable problem


Download ppt "Value Range Analysis with Modulo Interval Arithmetic"

Similar presentations


Ads by Google