Optimization Compiler Optimization – optimizes the speed of compilation Execution Optimization – optimizes the speed of execution.

Slides:



Advertisements
Similar presentations
CSC 4181 Compiler Construction Code Generation & Optimization.
Advertisements

Code Optimization and Performance Chapter 5 CS 105 Tour of the Black Holes of Computing.
Compiler Support for Superscalar Processors. Loop Unrolling Assumption: Standard five stage pipeline Empty cycles between instructions before the result.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
Instruction Set Design
Course Outline Traditional Static Program Analysis Software Testing
Loops or Lather, Rinse, Repeat… CS153: Compilers Greg Morrisett.
19 Classic Examples of Local and Global Code Optimizations Local Constant folding Constant combining Strength reduction.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
1 Lecture 5: Static ILP Basics Topics: loop unrolling, VLIW (Sections 2.1 – 2.2)
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
1 Chapter 8: Code Generation. 2 Generating Instructions from Three-address Code Example: D = (A*B)+C =* A B T1 =+ T1 C T2 = T2 D.
Programmability Issues
1 Lecture: Static ILP Topics: loop unrolling, software pipelines (Sections C.5, 3.2)
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
1 Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
1 Classical Optimization Types of classical optimizations  Operation level: one operation in isolation  Local: optimize pairs of operations in same basic.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
Friday, September 15, 2006 The three most important factors in selling optimization are location, location, location. - Realtor’s creed.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Hardware-Software Interface Machine Program Performance = t cyc x CPI x code size X Available resources statically fixed Designed to support wide variety.
Compiler Code Optimizations. Introduction Introduction Optimized codeOptimized code Executes faster Executes faster efficient memory usage efficient memory.
5.3 Machine-Independent Compiler Features
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Chapter 25: Code-Tuning Strategies. Chapter 25  Code tuning is one way of improving a program’s performance, You can often find other ways to improve.
CPSC 388 – Compiler Design and Construction Optimization.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Slides Prepared from the CI-Tutor Courses at NCSA By S. Masoud Sadjadi School of Computing and Information Sciences Florida.
High-Level Transformations for Embedded Computing
Chapter 10 Code Optimization Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
Solving by Elimination Example 1: STEP 2: Look for opposite terms. STEP 1: Write both equations in Standard Form to line up like variables. STEP 5: Solve.
7.4. 5x + 2y = 16 5x + 2y = 16 3x – 4y = 20 3x – 4y = 20 In this linear system neither variable can be eliminated by adding the equations. In this linear.
CS 153: Concepts of Compiler Design November 25 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x.
Optimization of C Code The C for Speed
Programming for Performance CS 740 Oct. 4, 2000 Topics How architecture impacts your programs How (and how not) to tune your code.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
ARM7 Architecture What We Have Learned up to Now.
Elimination Method - Systems. Elimination Method  With the elimination method, you create like terms that add to zero.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Code Optimization Overview and Examples
Code Optimization.
Solving Systems of Linear Equations in 3 Variables.
Simone Campanoni Loop transformations Simone Campanoni
Optimization Code Optimization ©SoftMoore Consulting.
Basic Block Optimizations
Princeton University Spring 2016
Eugene Gavrin – MSc student
Code Generation Part III
Lecture: Static ILP Topics: compiler scheduling, loop unrolling, software pipelining (Sections C.5, 3.2)
Lecture: Static ILP Topics: loop unrolling, software pipelines (Sections C.5, 3.2) HW3 posted, due in a week.
Compiler Code Optimizations
Code Generation Part III
Solve Linear Equations by Elimination
Fall Compiler Principles Lecture 10: Loop Optimizations
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Solving Systems of Linear Equations in 3 Variables.
Loop Optimization “Programs spend 90% of time in loops”
Tour of common optimizations
Tour of common optimizations
Lecture 11: Machine-Dependent Optimization
Tour of common optimizations
The Substitution Method
CMPE 152: Compiler Design April 30 Class Meeting
Basic Block Optimizations
Code Optimization.
Presentation transcript:

Optimization Compiler Optimization – optimizes the speed of compilation Execution Optimization – optimizes the speed of execution

Turn Optimization On/OFF For university projects – optimize compilation speed. Fast execution speed is unnecessary. For most computer applications produced by software vendors, fast execution is essential. Since they are usually compiled before the customer gets them, compilation speed is incidental. Optimizations are usually invoked with compiler directives such as UNIX dash options.

Constant Folding a = 17; b = a – 15; c = a * b; Original TriplesOptimized Triples (1)= a 17(1) = a 17 (2)– (1) 15c 2 (3)= b (2)(3) = b 2 (4)* (1) (3)c 34 (5)= c (4)(5) = c 34

Code Motion/Loop Invariants Unoptimized Code: for (int a=0;a<10000;a++) { c = 8;/* loop invariant is located inside the loop */ b= a + c; cout << b; } Optimized Code: c = 8; /* loop invariant is moved outside loop */ for (int a=0;a<10000;a++) { b= a + c; cout << b; } Saves loads and 9999 stores.

Reduction in Strength Substitute a less expensive statement for a more expensive one: Example 1: substitute b=a<<1 for b=2*a Trade multiply for a shift

Reduction-in-Strength (cont) Unoptimized code:Optimized code: int i, j, k, a[601], b[601]; int k, a[601],b[601]; k=25; k=0; i=1; while(k<=600) { while(i<25) {k+=25; j=k*i; a[k]=b[k]; } a[j]=b[j]; i++; } Reduction in strength – traded 24 adds for 24 multiplies Dead variable elimination – i=1 saved 2 loads and 1 store i++ saved 48 loads, 24 adds, and 24 stores

Loop Unrolling Unoptimized Code:Optimized Code: int k, a[601],b[601]; int j, k, a[601],b[601]; k=0; k=0; while(k<=600) { while(k<=600) { k+=25; k+=50; a[k]=b[k]; } j=k – 25; a[k]=b[k]; a[j]=b[j]; } Savings: fewer branches (half the number in this case). Fewer branch penalties in pipelining.