# Ch9c - 1 ! Code Generation&quot; Part III! Chapter 8&quot;...

This preview shows pages 1–7. Sign up to view the full content.

1 Code Generation Part III Chapter 8 (1 st ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Classic Examples of Local and Global Code Optimizations Local – Constant folding – Constant combining – Strength reduction – Constant propagation – Common subexpression elimination – Backward copy propagation Global – Dead code elimination – Constant propagation – Forward copy propagation – Common subexpression elimination – Code motion – Loop strength reduction – Induction variable elimination
3 Local: Constant Folding r7 = 4 + 1 r5 = 2 * r4 r6 = r5 * 2 src1(X) = 4 src2(X) = 1 Goal: eliminate unnecessary operations Rules: 1. X is an arithmetic operation 2. If src1(X) and src2(X) are constant, then change X by applying the operation

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Local: Constant Combining r7 = 5 r5 = 2 * r4 r6 = r5 * 2 r6 = r4 * 4 Goal: eliminate unnecessary operations First operation often becomes dead after constant combining Rules: 1. Operations X and Y in same basic block 2. X and Y have at least one literal src 3. Y uses dest(X) 4. None of the srcs of X have defs between X and Y (excluding Y)
5 Local: Strength Reduction r7 = 5 r5 = 2 * r4 r6 = r4 * 4 r6 = r4 << 2 r5 = r4 + r4 Goal: replace expensive operations with cheaper ones Rules (common): 1. X is an multiplication operation where src1(X) or src2(X) is a const 2 k integer literal 2. Change X by using shift operation 3. For k =1 can use add

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Local: Constant Propagation r1 = 5
This is the end of the preview. Sign up to access the rest of the document.

## Ch9c - 1 ! Code Generation&quot; Part III! Chapter 8&quot;...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online