Chapter 13: Redundancy Elimination - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Chapter 13: Redundancy Elimination

Description:

Tries either to improve the program performance or to reduce the space it occupies ... redundancy elimination inserts and deletes computations in the flowgraph in ... – PowerPoint PPT presentation

Number of Views:118
Avg rating:3.0/5.0
Slides: 24
Provided by: csT4
Category:

less

Transcript and Presenter's Notes

Title: Chapter 13: Redundancy Elimination


1
Chapter 13Redundancy Elimination
  • Antti Tarvainen

2
Redundancy Elimination
  • Removes redundant computations
  • Tries either to improve the program performance
    or to reduce the space it occupies
  • Requires data-flow analysis
  • Done on either medium-level intermediate code or
    low-level intermediate code

3
Optimizations Covered
  • Common-Subexpression Elimination
  • Loop-Invariant Code Motion
  • Partial-Redundancy Elimination
  • Encompasses Common-Subexpression Elimination,
    Loop-Invariant Code Motion and more
  • Code Hoisting

4
1. Common-Subexpression Elimination
5
Definition Common subexpression
  • An occurrence of an expression is a common
    subexpression if there is another occurrence of
    the expression whose evaluation always precedes
    this one in execution order and if the operands
    of the expression remain unchanged between the
    two evaluations

6
Common-Subexpression Elimination (CSE)
  • CSE is usually done in two phases
  • Local CSE is done within each basic block while
    the intermediate code for the basic block is
    constructed
  • Global CSE is done later across an entire
    flowgraph representing a procedure

7
Local Common-Subexpression Elimination
  • (An example, fig. 13.3 - 13.7)

8
Global Common-Subexpression Elimination
  • (An example, fig. 13.8 - 13.10)

9
Global CSE with Copy Propagation
  • (An example, fig. 13.12 - 13.14)

10
Forward Substitution
  • Because CSE creates temporary variables to store
    values of expressions, it is a trade-off between
    register space and expression compactness
  • Sometimes we need to do it the other way around,
    i.e. replace a copy operation with a reevaluation
    of the expression
  • This is called forward substitution and is
    generally easy to do

11
2. Loop-Invariant Code Motion
12
Definition Loop-Invariant Instruction
  • An instruction is loop-invariant if, for each of
    its operands
  • The operand is constant or
  • All definitions that reach this use of the
    operand are located outside the loop or
  • There is exactly one definition of the operand
    that reaches the instruction and that definition
    is an instruction inside the loop that is itself
    loop-invariant.

13
Loop-Invariant Code Motion Example
  • (An example, fig. 13.18 - 13.22)

14
3. Partial-Redundancy Elimination
15
Definition Partial Redundancy
  • A partial redundancy is a computation that is
    done more than once on some path through a
    flowgraph.
  • Partial redundancy elimination inserts and
    deletes computations in the flowgraph in such a
    way that after the transformation each path
    contains no more and, generally,
    feweroccurences of any such computation than
    before

16
Partial Redundancy Elimination
  • Computationally optimal, i.e. after PRE the
    number of computations on each program path
    cannot be reduced anymore by means of safe code
    motion
  • Made more effective by
  • Critical edge splitting
  • Lazy code motion

17
Critical Edge Splitting Example
  • (An example, fig. 13.25)

18
Partial Redundancy Elimination Example 1
  • (An example, fig. 13.26 - 13.28)

19
Partial Redundancy Elimination Example 2
  • (An example, fig. 1 - 8)
  • (Source Knoop, Ruthing, Steffen Lazy Code
    Motion, in Proc. of SIGPLAN 92 Symp. on
    Programming Language Design and Implementation
    (1992))

20
4. Code Hoisting
21
Code Hoisting
  • Finds expressions that are always evaluated
    following some point in program and moves them to
    the latest point beyond which they would always
    be evaluated
  • These expressions are called very busy
    expressions
  • Almost always reduces space occupied by the
    program but may shorten or lengthen the execution
    time

22
Code Hoisting Example
  • (An example fig. 13.33 - 13.35)

23
Wrap-Up
Write a Comment
User Comments (0)
About PowerShow.com