Compiler Optimizations in Computer Architecture: Slides for CS 35101, Spring 2008 - Prof. , Study notes of Computer Architecture and Organization

Slides from the computer architecture course (cs 35101) held in spring 2008 at the university. The slides cover various compiler optimizations, including high-level optimizations, local and global optimizations, common subexpression elimination, strength reduction, constant propagation, copy propagation, dead store and dead code elimination, global loop optimizations, and code motion. The document also discusses why compilers cannot optimize optimally.

Typology: Study notes

Pre 2010

Uploaded on 02/25/2010

koofers-user-n61
koofers-user-n61 🇺🇸

10 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 35101.1 Spring 2008
CS 35101
Computer Architecture
Spring 2008
2.11
Slides by Shannon I. Steinfadt
[adapted from D. Patterson slides Revised 3rd Edition]
pf3
pf4
pf5
pf8

Partial preview of the text

Download Compiler Optimizations in Computer Architecture: Slides for CS 35101, Spring 2008 - Prof. and more Study notes Computer Architecture and Organization in PDF only on Docsity!

CS 35101

Computer Architecture

Spring 2008

Slides by Shannon I. Steinfadt [adapted from D. Patterson slides Revised 3rd Edition]

(2.11) Compiler Optimizations

Front end per language High-level optimizations Global optimizer Code generator Dependencies Language dependent; machine independent Function Transform language to common intermediate form Intermediate representation Somewhat language dependent; largely machine dependent For example, loop transformations and procedure inlining (procedure integration) Small language dependencies; machine dependences slight (e.g. register counts / types) Including global and local optimizations + register allocation Highly machine dependent; language dependent Detailed instruction selection and machine-dependent optimizations; may include or be followed by assembler

Local and Global Optimizations

 Local optimization

 Within a single basic block

 Often occurs as clean-up prior to and after global

optimization

 Global optimization

 Works across multiple basic blocks

 Global register allocation

 Allocates variables to registers for regions of code

 Crucial for good performance in modern processors

Global and Local Compiler Optimizations

 Common subexpression elimination

 a[i] = a[i] + 4

  • Address calculation occurs twice!

 Strength reduction

 Replace complex operations with simpler ones

 Shift left instead of multiplication

 Constant propagation

int x = 14; int y = 7 - x / 2; return y * (28 / x + 2);

 Applying constant propagation once yields:

int x = 14; int y = 7 - 14 / 2; return y * (28 / 14 + 2);

 Constant folding could be applied to simplify the expression

Global Loop Optimizations

 Code motion

 Finds any loop invariants and moves computations

outside of the loop

while (loop_count < n+m-1)

  • Where n and m are the size of the input strings and do not

change within the program

maxsize = n+m-

while (loop_count < maxsize)

 Induction variable elimination

 Combination of transformations that reduce

overhead on indexing arrays (replacing array

indexing with pointer accesses)

Why can’t compilers optimize optimally?

 Compilers must be conservative

 The compiler must produce running code that is

correct for any possible combination of inputs

 Programmers may have more knowledge about the

program that the compiler CANNOT assume:

  • Absence of aliasing between two pointers
  • Absence of side effects by a function call

 Most compilers translate and optimize one function

/ procedure at a time

  • Difficult to optimize this way