ABCD: Eliminating Array-Bounds Checks on Demand Rastislav Bodík Rajiv Gupta Vivek Sarkar U of Wisconsin U of Arizona IBM TJ Watson recent experiments.

Slides:



Advertisements
Similar presentations
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
Advertisements

School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Satisfiability Modulo Theories (An introduction)
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Carnegie Mellon Lecture 7 Instruction Scheduling I. Basic Block Scheduling II.Global Scheduling (for Non-Numeric Code) Reading: Chapter 10.3 – 10.4 M.
Stanford University CS243 Winter 2006 Wei Li 1 Register Allocation.
Inpainting Assigment – Tips and Hints Outline how to design a good test plan selection of dimensions to test along selection of values for each dimension.
Enforcing Sequential Consistency in SPMD Programs with Arrays Wei Chen Arvind Krishnamurthy Katherine Yelick.
Components of representation Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements occur in right order Data.
Program Representations. Representing programs Goals.
Discussion #33 Adjacency Matrices. Topics Adjacency matrix for a directed graph Reachability Algorithmic Complexity and Correctness –Big Oh –Proofs of.
Program Slicing Mark Weiser and Precise Dynamic Slicing Algorithms Xiangyu Zhang, Rajiv Gupta & Youtao Zhang Presented by Harini Ramaprasad.
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Recap from last time Saw several examples of optimizations –Constant folding –Constant Prop –Copy Prop –Common Sub-expression Elim –Partial Redundancy.
Administrative info Subscribe to the class mailing list –instructions are on the class web page, click on “Course Syllabus” –if you don’t subscribe by.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
Administrative info Subscribe to the class mailing list –instructions are on the class web page, which is accessible from my home page, which is accessible.
9. Optimization Marcus Denker. 2 © Marcus Denker Optimization Roadmap  Introduction  Optimizations in the Back-end  The Optimizer  SSA Optimizations.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
Another example p := &x; *p := 5 y := x + 1;. Another example p := &x; *p := 5 y := x + 1; x := 5; *p := 3 y := x + 1; ???
Validating High-Level Synthesis Sudipta Kundu, Sorin Lerner, Rajesh Gupta Department of Computer Science and Engineering, University of California, San.
Incremental Path Profiling Kevin Bierhoff and Laura Hiatt Path ProfilingIncremental ApproachExperimental Results Path profiling counts how often each path.
Java Alias Analysis for Online Environments Manu Sridharan 2004 OSQ Retreat Joint work with Rastislav Bodik, Denis Gopan, Jong-Deok Choi.
Intermediate Code. Local Optimizations
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Prof. Fateman CS164 Lecture 211 Local Optimizations Lecture 21.
Load-Reuse Analysis design and evaluation Rastislav Bodík Rajiv Gupta Mary Lou Soffa.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
PSUCS322 HM 1 Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
Recap from last time We saw various different issues related to program analysis and program transformations You were not expected to know all of these.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Eliminating Memory References Joshua Dunfield Alina Oprea.
Time-Constrained Flooding A.Mehta and E. Wagner. Time-Constrained Flooding: Problem Definition ●Devise an algorithm that provides a subgraph containing.
Adaptive Optimization in the Jalapeño JVM M. Arnold, S. Fink, D. Grove, M. Hind, P. Sweeney Presented by Andrew Cove Spring 2006.
Precision Going back to constant prop, in what cases would we lose precision?
15.082J, 6.855J, and ESD.78J September 21, 2010 Eulerian Walks Flow Decomposition and Transformations.
P ARALLEL P ROCESSING I NSTITUTE · F UDAN U NIVERSITY 1.
CSc 453 Final Code Generation Saumya Debray The University of Arizona Tucson.
Static Program Analysis of Embedded Software Ramakrishnan Venkitaraman Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Static Program Analyses of DSP Software Systems Ramakrishnan Venkitaraman and Gopal Gupta.
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
ABCD: Eliminating Array-Bounds Checks on Demand Rastislav Bodík Rajiv Gupta Vivek Sarkar U of Wisconsin U of Arizona IBM TJ Watson recent experiments.
Targeted Path Profiling : Lower Overhead Path Profiling for Staged Dynamic Optimization Systems Rahul Joshi, UIUC Michael Bond*, UT Austin Craig Zilles,
Static Program Analysis of Embedded Software Ramakrishnan Venkitaraman Graduate Student, Computer Science Advisor: Dr. Gopal Gupta
Advanced Computer Architecture Lab University of Michigan Compiler Controlled Value Prediction with Branch Predictor Based Confidence Eric Larson Compiler.
An Undergraduate Course on Software Bug Detection Tools and Techniques Eric Larson Seattle University March 3, 2006.
Targeted Path Profiling : Lower Overhead Path Profiling for Staged Dynamic Optimization Systems Rahul Joshi, UIUC Michael Bond*, UT Austin Craig Zilles,
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
Optimal Superblock Scheduling Using Enumeration Ghassan Shobaki, CS Dept. Kent Wilken, ECE Dept. University of California, Davis
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
CUTE: A Concolic Unit Testing Engine for C Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
An Offline Approach for Whole-Program Paths Analysis using Suffix Arrays G. Pokam, F. Bodin.
Week 5-6 MondayTuesdayWednesdayThursdayFriday Testing I No reading Group meetings MidtermNo Section Testing II Progress report due Readings out Testing.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Static Single Assignment
Machine-Independent Optimization
CS 201 Compiler Construction
Correcting the Dynamic Call Graph Using Control Flow Constraints
Register Allocation Hal Perkins Autumn 2005
Complete Removal of Redundant Expressions
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Practical Assignment Sinking for Dynamic Compilers
Presentation transcript:

ABCD: Eliminating Array-Bounds Checks on Demand Rastislav Bodík Rajiv Gupta Vivek Sarkar U of Wisconsin U of Arizona IBM TJ Watson recent experiments by Denis Gopan, U of Wisconsin

2 Motivation: type safety Pro: type-safe programs don’t “crash” Con: some violations checked at run time Direct cost: executing the checks checks are frequent, expensive Indirect cost: preventing optimization checks block code motion of side-effect instructions Our goal: safety without performance penalty How? remove redundant checks

3 Talk outline Why remove bounds checks? safety without performance penalty The need for dynamic optimization existing optimizers not suitable an ideal dynamic optimizer ABCD Experiments Summary

4 When to optimize the checks?

5

6 Existing check optimizers Emphasis: precision goal: all checks removed = statically type-safe theorem prover: [Necula, Lee], [Xu, Miller, Reps] range propagation: [Harrison, Patterson] types: [Xi, Phenning] Properties too heavy-weight limited notion of control flow: how to add profile feedback?

7 An ideal dynamic optimizer? A balance between power and economy powerful just enough  only common cases minimize analysis work  efficient IR reduce IR overhead  reuse the IR Scalable optimize only hot checks  profile-directed + demand-driven no whole-program analysis  use “local” info + insert (cold) checks

8 Why optimize on demand?  optimize only the few hot checks number of static checks % of dynamic checks mpegaudio 80 checks analyzed ( not necessarily removed)

9 Talk outline Motivation An ideal dynamic optimizer ABCD “tutorial” 1. Simple... standard SSA 2. Full... extended SSA 3. PRE... profile-directed 4. ABCDE... work in progress Experiments Summary

10 High-level algorithm for each hot array access A[i] do -- optimize upper-bound check ABCD( i < A.length ) -- optimize lower-bound check ABCD( 0  i ) end for this talk

11 1. Simple ABCD i  A.length while ( ) { --i..A[i].. } Simple ABCD = SSA + shortest path

12 1. Simple ABCD 1.build SSA 2.label edges with constraints 3.analyze A[i k ]: is i k < A.length always true?

13 Simple ABCD i 0  A.length – 0 i 2  i 1 – 1 i 1  i 0 – 0 i 1  ø(i 0,i 2 ) i 2  i 1 –1.. A[i 2 ].. i 0  A.length weight(A.length  i 2 ) = 1  i 2  A.length – 1 A.length i2i2 i0i0 i1i1 ø

14 1. Simple ABCD 1.build SSA 2.label edges with constraints 3.analyze A[i k ]: input: a bounds check i k < A.length algorithm: find shortest path p from A.length to i k output: check is redundant if weight(p) > 0

15 2. Full ABCD for (i=0; i < A.length; i++)..A[i].. Full ABCD = SSA ++ + “shortest” path

16 2. Full ABCD 1.build extended SSA: naming of standard SSA not fine-grain enough  add dummy  assignments 2.label edges with constraints 3.analyze: shortest path  optimal path in a hyper-graph

17 Extending the SSA form ø 0 i0i0 i1i1 0 0 –1 0 i2i2 i 1  ø(i 0,i 2 ).. A[i 1 ].. i 2  i 1 +1 i 0  0 T F i 1  A.length–1 A.length – –  i  A.length– 1

18 Extending the SSA form ø 0 i2i2 i0i0 i1i1 0 0 –1 0 0 i3i3 i 1  ø(i 0,i 3 ).. A[i 2 ].. i 3  i 2 +1 i 0  0 T F i 1  A.length–1 A.length 1 i 2  (i 1 )   =shortest  =longest hyper-graph: has two kinds of nodes

19 3. ABCD with PRE f(int A[], int n) { for (i=0; i < n; i++)..A[i].. } if (n <= A.length) unoptimized loop false ABCD with PRE = Full ABCD + profile feedback PRE = partial redundancy elimination

20 3. ABCD with PRE 1.build extended SSA 2.label edges with constraints 3.analyze A[i k ]: Algorithm: i) find paths with “bad” length ii) fix their length by inserting run-time checks Issues: What check to insert? Where to insert the check? When is insertion profitable?

21 ABCD with PRE ø 0 i2i2 i0i0 i1i1 0 0 –1 0 0 i3i3 1 nA.length f(int A[], int n) { for (i=0; i<n; i++).. A[i].. } 0 if (n <= A.length – 0) DONE! constraint edges can be added by inserting run-time checks 

22 4. ABCDE f(int A[], int n, i, j) { for ( ; i < n; i++, j++).. A[j].. } if ( n <= A.length–(j-i)) unoptimized loop When does ABCD fail?

23 ABCDE i2i2 i0i0 i1i1 0 –1 0 0 i3i3 1 n A.length j2j2 j0j0 j1j1 0 –1 0 0 j3j3 0 for (i=j=0 ; i<n; i++,j++) {.. A[j].. } c = j 2 -i 2 if (n <= A.length-( j 2 -i 2 )) c = j 0 -i 0 if (n <= A.length-( j 0 -i 0 ))

24 ABCD is simple yet powerful...

25 A complex example from paper limit = a.length st = –1 while (st < limit) st++ limit – – for (j = st; j < limit; j++) { A[j] += A[j+1] }

26 A complex example from paper limit = a.length st = –1 while (st < limit) st++ limit –– for (j = st; j < limit; j++) { A[j] += A[j+1] }

27 How powerful is ABCD? checks removed [% of all dynamic checks] SPECjvm Symantec Misc. Java 100%

28 Classification of hot checks JIT-like ABCD ABCDE examined AVG checks removed [% of all dynamic checks] “removable”

29 Summary Current speedup: modest, up to about 5% direct cost: in Jalapeno, checks already very efficient indirect cost: few global optimizations implemented (11/99) Analysis time 4 ms / check = visit 10 SSA nodes / check recall 20 checks yields 80% dynamic coverage  80 ms to analyze a large benchmark ! Precision: can be improved with few extensions (ABCD  ABCDE) remaining checks appear beyond compiler analysis  Use ABCD for your bounds-check optimization

30 Classification of hot checks 1. for ()

31 Summary optimize only hot statements demand-driven reduce analysis work sparse IR profile-driven powerful just enough tuned simplicity minimize IR overhead via IR reuse use SSA not interprocedural PRE

32 Lower-bounds checks JIT-esque ABCD ABCDE examined AVG checks removed [% of all checks (dynamic count)]

33 Summary of ABCD local constraints constraint format useful statements global constraint system extended SSA inequality graph solving the constraint system traversing the graph partially redundant checks