Combining Analyses, Combining Optimizations
Total Page:16
File Type:pdf, Size:1020Kb
RICE UNIVERSITY Combining Analyses, Combining Optimizations by Clifford Noel Click, Jr. A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE Doctor of Philosophy APPROVED, THESIS COMMITTEE: Chair Keith D. Cooper Associate Professor of Computer Science Robert Bixby Professor of Computational and Applied Mathematics Mark W. Krentel Assistant Professor of Computer Science Linda Torczon Faculty Fellow of Computer Science Houston, Texas February, 1995 Combining Analyses, Combining Optimizations Clifford Noel Click, Jr. Abstract This thesis presents a framework for describing optimizations. It shows how to com- bine two such frameworks and how to reason about the properties of the resulting frame- work. The structure of the framework provides insight into when a combination yields better results. Also presented is a simple iterative algorithm for solving these frameworks. A framework is shown that combines Constant Propagation, Unreachable Code Elimina- tion, Global Congruence Finding and Global Value Numbering. For these optimizations, the iterative algorithm runs in O(n2) time. This thesis then presents an O(n log n) algorithm for combining the same optimiza- tions. This technique also finds many of the common subexpressions found by Partial Re- dundancy Elimination. However, it requires a global code motion pass to make the opti- mized code correct, also presented. The global code motion algorithm removes some Partially Dead Code as a side-effect. An implementation demonstrates that the algorithm has shorter compile times than repeated passes of the separate optimizations while produc- ing run-time speedups of 4% – 7%. While global analyses are stronger, peephole analyses can be unexpectedly powerful. This thesis demonstrates parse-time peephole optimizations that find more than 95% of the constants and common subexpressions found by the best combined analysis. Finding constants and common subexpressions while parsing reduces peak intermediate represen- tation size. This speeds up the later global analyses, reducing total compilation time by 10%. In conjunction with global code motion, these peephole optimizations generate ex- cellent code very quickly, a useful feature for compilers that stress compilation speed over code quality. Acknowledgments First and foremost I wish to thank Melanie, my wife of six years. Her courage and strength (and level-headedness!) has kept me plowing ahead. I must also mention Karen, my daughter of 1 year, whose bright smiles lighten my days. I wish to thank Keith Coo- per, my advisor, for being tolerant of my wild ideas. His worldly views helped me keep track of what is important in computer science, and helped me to distinguish between the style and the substance of my research. I also thank Mark Krentel and his “Big, Bad, Counter-Example Machine” for helping me with the devilish algorithmic details, Bob Bixby for his large numerical C codes, and Linda Torczon for her patience. While there are many other people in the Rice community I wish to thank, a few stand out. Michael Paleczny has been an invaluable research partner. Many of the ideas pre- sented here were first fleshed out between us as we sat beneath the oak trees. I hope that we can continue to work (and publish) together. Chris Vick has been a great sounding board for ideas, playing devil’s advocate with relish. Without Preston Briggs and the rest of the Massively Scalar Compiler Group (Tim Harvey, Rob Shillingsburg, Taylor Simp- son, Lisa Thomas and Linda Torczon) this research would never have happened. Lorie Liebrock and Jerry Roth have been solid friends and fellow students through it all. Last I would like to thank Rice University and the cast of thousands that make Rice such a wonderful place to learn. This research has been funded by ARPA through ONR grant N00014-91-J-1989. Table of Contents Abstract.....................................................................................................................ii Acknowledgements...................................................................................................iii Illustrations...............................................................................................................vi Preface.................................................................................................................... viii 1. Introduction 1 1.1 Background .........................................................................................................1 1.2 Compiler Optimizations........................................................................................2 1.3 Intermediate Representations ...............................................................................4 1.4 Organization ........................................................................................................6 2. The Optimistic Assumption 8 2.1 The Optimistic Assumption Defined .....................................................................9 2.2 Using the Optimistic Assumption .......................................................................12 2.3 Some Observations about the Optimistic Assumption .........................................14 3. Combining Analyses, Combining Optimizations 16 3.1 Introduction.......................................................................................................16 3.2 Overview ...........................................................................................................17 3.3 Simple Constant Propagation .............................................................................21 3.4 Finding the Greatest Fixed Point ........................................................................24 3.5 Efficient Solutions..............................................................................................25 3.6 Unreachable Code Elimination ...........................................................................26 3.7 Combining Analyses...........................................................................................27 3.8 Global Value Numbering....................................................................................31 3.9 Summary............................................................................................................35 4. An O(n log n) Conditional Constant Propagation and Global Value Numbering Algorithm 36 4.1 Introduction.......................................................................................................36 4.2 Hopcroft's Algorithm and Runtime Analysis .......................................................39 4.3 Adding Unreachable Code Elimination ...............................................................42 4.4 Adding in Constant Propagation.........................................................................45 4.5 Allowing Constants and Congruences to Interact................................................50 4.6 Subtract and Compare........................................................................................51 4.7 Adding the Identity Function Congruences.........................................................52 v 4.8 The Algebraic, 1-Constant Identities: x + 0 and x × 1 .........................................58 4.9 The Algebraic 2-Congruent-Input Identities: PHI and MAX.................................61 4.10 Using the Results .............................................................................................64 4.11 Summary..........................................................................................................64 5. Experimental Data 66 5.1 Experimental Method.........................................................................................66 5.2 Executing ILOC...................................................................................................66 5.3 The Test Suite....................................................................................................67 5.4 Comparing the Combined Algorithm ..................................................................68 5.5 The Experiments ................................................................................................71 5.6 The Compile-Time Numbers ..............................................................................79 6. Optimizing Without the Global Schedule 85 6.1 Removing the Control Dependence ....................................................................85 6.2 Improving Optimizations....................................................................................86 6.3 Finding a New Global Schedule..........................................................................87 6.4 Scheduling Strategies .........................................................................................98 7. Parse-time Optimizations 100 7.1 Introduction..................................................................................................... 100 7.2 The Parser Design............................................................................................100 7.3 The Peephole Optimizer...................................................................................104 7.4 Experimental Data............................................................................................107 7.5 Summary..........................................................................................................108 8. Summary and Future Directions 109 8.1 Future Directions .............................................................................................109