{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture8 - Code Optimization I Machine Independent...

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

View Full Document Right Arrow Icon
Code Optimization I: Machine Independent Optimizations Code Optimization I: Machine Independent Optimizations Topics Topics Machine-Independent Optimizations Code motion Reduction in strength Common subexpression sharing Tuning Identifying performance bottlenecks
Background image of page 1

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

View Full Document Right Arrow Icon
– 2 – Great Reality Great Reality There’s more to performance than asymptotic There’s more to performance than asymptotic complexity complexity Constant factors matter too! Constant factors matter too! Easily see 10:1 performance range depending on how code is written Must optimize at multiple levels: algorithm, data representations, procedures, and loops Must understand system to optimize performance Must understand system to optimize performance How programs are compiled and executed How to measure program performance and identify bottlenecks How to improve performance without destroying code modularity and generality
Background image of page 2
– 3 – Optimizing Compilers Optimizing Compilers Provide efficient mapping of program to machine Provide efficient mapping of program to machine register allocation code selection and ordering eliminating minor inefficiencies Don’t (usually) improve asymptotic efficiency Don’t (usually) improve asymptotic efficiency up to programmer to select best overall algorithm big-O savings are (often) more important than constant factors but constant factors also matter Have difficulty overcoming “optimization blockers” Have difficulty overcoming “optimization blockers” potential memory aliasing potential procedure side-effects
Background image of page 3

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

View Full Document Right Arrow Icon
– 4 – Limitations of Optimizing Compilers Limitations of Optimizing Compilers Operate Under Fundamental Constraint Operate Under Fundamental Constraint Must not cause any change in program behavior under any possible condition Often prevents it from making optimizations when would only affect behavior under pathological conditions. Behavior that may be obvious to the programmer can be Behavior that may be obvious to the programmer can be obfuscated by languages and coding styles obfuscated by languages and coding styles e.g., data ranges may be more limited than variable types suggest Most analysis is performed only within procedures Most analysis is performed only within procedures whole-program analysis is too expensive in most cases Most analysis is based only on Most analysis is based only on static information information compiler has difficulty anticipating run-time inputs When in doubt, the compiler must be conservative When in doubt, the compiler must be conservative
Background image of page 4
– 5 – Machine-Independent Optimizations Machine-Independent Optimizations Optimizations you should do regardless of processor / compiler Code Motion Code Motion Reduce frequency with which computation performed If it will always produce same result Especially moving code out of loop for (i = 0; i < n; i++) for (j = 0; j < n; j++) a[n*i + j] = b[j]; for (i = 0; i < n; i++) { int ni = n*i; for (j = 0; j < n; j++) a[ni + j] = b[j]; }
Background image of page 5

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

View Full Document Right Arrow Icon
– 6 – Compiler-Generated Code Motion Compiler-Generated Code Motion
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}