Induction%20Variable%20and%20Strength%20Reduction - PowerPoint PPT Presentation

About This Presentation
Title:

Induction%20Variable%20and%20Strength%20Reduction

Description:

the set of induction variables A such that each time A is assigned in the loop, ... Select an induction variable A in the family of B, preferably with simple ... – PowerPoint PPT presentation

Number of Views:176
Avg rating:3.0/5.0
Slides: 12
Provided by: altair8
Category:

less

Transcript and Presenter's Notes

Title: Induction%20Variable%20and%20Strength%20Reduction


1
Induction Variableand Strength Reduction
  • Overview of Optimization
  • Algorithm to find induction variables
  • Dragon Ch. 10.4 (pp. 643-648)

2
Example
  • For i 0 to 100
  • Ai 0
  • --------------------------------------------------
    --------------------------------------------------
    ---------------------------------
  • i0 / Deleted /
  • t1 4 i 0 / Deleted /
  • i 0 t2 4 i A A
  • t3 4100 A
  • L2 if (i gt 100) goto L1 L2 if (t2 gt t3)
  • t1 4 i t1 t1 / Deleted /
  • t2 A t gt t2
    t2 / Propagated into /
  • t2 0 t2 0 / t2 0 /
  • i i 1 i i 1 / Deleted /
  • goto L2 t1 t1 4 / Deleted /
  • L1 t2 t2 4
  • goto L2
  • L1

3
Definition
  • A basic induction variable is a variable X
  • whose only definitions within the loop are
    assignment of the form X X c or X X - c,
    where c is either a constant or a loop-invariant
    variable
  • An induction variable is
  • a basic induction variable
  • a variable defined once within the loop, whose
    value is a linear function of some basic
    induction variable at the time of definition A
    c1 ? B c2
  • The family of a basic induction variable B
  • the set of induction variables A such that each
    time A is assigned in the loop, the value of A is
    a linear function of B

4
Optimization
  • Strength Reduction
  • Let A be an induction variable in family of basic
    induction variable B (i.e., A c1 ? B c2)
  • Create a new variable A
  • Initialization in preheader A c1 ? B c2
  • Track value of B add after B B x A A
    x ? c1
  • Replace assignment to A A A

5
Optimization (cont.)
  • Optimizing Non-basic Induction Variables
  • Copy propagation
  • Dead code elimination
  • Optimizing Basic Induction Variables Eliminates
    BIVs used only for calculating other induction
    variables and loop tests
  • Select an induction variable A in the family of
    B, preferably with simple constants (e.g., A c1
    ? B c2)
  • Replace a comparison such as if B gt X goto L1
    by if (A gt c1 ? x c2) goto L1,
    assuming c1 is positive
  • if B is llive at any exit from the loop,
    recompute it from A after the exit, B (A -
    c2) / c1

6
Basic Induction Variables
  • Algorithm can be detected by scanning the loop
  • Example
  • k 0
  • for (i 0 i lt n i)
  • k k 3
  • .. m
  • if (x lt y)
  • k k 4
  • if (a lt b)
  • m 2 k
  • k k - 2
  • .. m
  • / Each iteration may execute a different number
    of increments/decrements /

7
Strength Reduction Algorithm
  • Key Idea
  • For each induction variable A, ( A c1 ? B c2
    at time of def.)
  • variable A hods expression c1 ? B c2 at all
    times
  • replace definition of A with A A only when
    executed
  • Result
  • Program is correct
  • Definition of A does not need to refer to B

8
Finding Induction Variable Families
  • Let B be a basic induction variable
  • Find all induction variables A in Family of B
    A c1 ? B c2, where B refers to the
    value when at time of definition
  • Conditions
  • If A has a single assignment in the loop L, and
    assignment is one of
  • A B c A c B
  • A B / c
  • A B c A c B
  • A B - c
  • A c - B

9
  • Let D be an induction variable in the family of B
    (D c1 ? B c2)
  • If A has a single assignment in the loop L, and
    assignment is one of
  • A B c A c B
  • A B / c
  • A B c A c B
  • A B - c
  • A c - B
  • No definition of D outside L reaches the
    assignment to A
  • Between the lone point of assignment to D in L
    and the assignment to A, there are no definitions
    of B

10
Homework 2
  • Finding Loops Due Nov. 10 (Friday)
  • Your mission is to locate loops from Sparc
    assembly code
  • You should start from the code that you wrote in
    HW 1
  • Find dominators using the dataflow framework in
    HW 1, detect natural loops for each back edge,
    and properly nest the loops that you have found.
    A loop is defined to be nested within another if
    the first loops header block is a member of the
    second loop

11
  • Printouts (example)
  • Loop Hierarchy Tree / Lx means the loop number
    x which is numbered from 0 according to the
    rPostorder of the loop header /
  • L0
  • L1 L3
  • L2 L4 L6
  • L5
  • Member Basic Blocks
  • MemL0 B0, B1, B2, B3, .. / basic block
    numbers in rPostorder /
  • MemL1 B1, B2, B4, B5
  • MemL2 B2
  • MemL3 B3, B7
Write a Comment
User Comments (0)
About PowerShow.com