SlideServe
Menu
Préférences
© SlideServe · v2026

Program Performance through Compiler Optimization Techniques

renee-donaldson avatar
17 diapositives · 340 Views · Nov 09, 2014

Compiler optimization techniques focus on improving program performance by optimizing various aspects of code execution. These techniques can reduce execution time, minimize memory usage, and lower power consumption. Key optimization strategies include constant folding, dead code elimination, and loop optimizations. Effective optimizations are performed at both the intermediate and machine-dependent levels to leverage specific hardware capabilities. This approach is particularly beneficial for low-power devices like smartphones, ensuring that applications run more efficiently while conserving resources.

Program Performance through Compiler Optimization Techniques - slide 1
01 / 17Program Performance through Compiler Optimization Techniques
1 / 17

Télécharger la présentation

Program Performance through Compiler Optimization Techniques
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Program Performance through Compiler Optimization Techniques

  2. Compiler Optimization • It is the process of improving the output of the compiler • To minimize execution time of the program • By removing repeated computation • To minimize amount of memory occupied by the program • By removing unnecessary code in the program • To minimize the power consumed by the program • By parallelizing the code among multiple cores • Beneficial for low power devices like cell phones

  3. When and where to optimize • Optimization can be performed on • Intermediate Code • In order to reduce size of Abstract Syntax Tree • Machine independent • Final Code generation • In-order to improve register usage • In order to better utilize pipeline • Machine dependent

  4. Types of Compiler Optimization Techniques • Local Optimization • Optimization performed exclusively on basic blocks. • Simplest type of optimization since no control flow information is considered • Some optimization techniques are • Constant Folding • Constant Propagation • Common Sub-expression Elimination • Dead Code Elimination • Copy Propagation • Loop Optimization

  5. Machine Dependent Optimization • Machine Optimization • This is done in final code generation phase • Specific machine features like specialized instructions, hardware pipeline abilities, register details etc are taken into account to produce code optimization for a particular machine architecture • Some optimization techniques are • Register Allocation • Instruction Selection • Instruction Scheduling

  6. Local Optimization Techniques • Constant Folding • It refers to the evaluation of expression whose operands are constants at compile time. • It evaluates the expression and replaces the expression by value • Example • i = 15 + 5 *10 = 65 • Conditional branch : if (a<b) goto L1 else goto L2 • If a and b are constants entire branch condition is transformed to either goto L1 or goto L2 depending on truth of condition

  7. Local Optimization Techniques (cont..) • Constant Propagation • If a variable is assigned a constant value, then later uses of that variable can be replaced by the constant as long as value of variable is not changed • Example int x = 14; int y = 7 - x / 2; return y * (28 / x + 2); Propagating x yields int x = 14; int y = 7 - 14 / 2; return y * (28 / 14 + 2);

  8. Local Optimization Techniques (cont..) • Copy Propagation • Similar to Constant Propagation • But generalized to non-constant values • Example

  9. Local Optimization Techniques (cont..) • Common Sub-expression Elimination • Two operations are common if they produce the same result. • It is efficient to compute the result once and reference it second time rather than re-computing it. • Expression is alive if operands used to compute it have not changed other it is dead. • Example • a = b * c + g; • d = b * c * d; • tmp = b * c; • a = tmp + g; • d = tmp * d;

  10. Example on constant folding, propagation and CSE

  11. Local Optimization Techniques (cont..) • Dead Code Elimination • If the result of a instruction is never used, the instruction is said to be dead and can be removed • Example int foo(void) { int a = 24; int b = 25; /* Assignment to dead variable */ int c; c = a << 2; return c; b = 24; /* Unreachable code */ return 0; }

  12. Local Optimization Techniques (cont..) • Loop Optimization • Loop Interchange • Loop invariant Code Motion • Loop Unrolling

  13. Loop Optimization • Loop Interchange • These optimizations exchange inner loops with outer loops. • When the loop variables index into an array, such a transformation can improve locality of reference, depending on the array's layout. • One major purpose of loop interchange is to improve the cache performance for accessing array elements. • Cache misses occur if the contiguously accessed array elements within the loop come from a different cache line. • Loop interchange can help prevent this.

  14. Loop Interchange Example • For example, in the code fragment: for i from 0 to 10 for j from 0 to 20 a[i,j] = i + j • loop interchange would result in: for j from 0 to 20 for i from 0 to 10 a[i,j] = i + j • Row major to column major format or vice versa

  15. Loop-invariant code motion • Loop-invariant code consists of statements or expressions which can be moved outside the body of a loop without affecting the semantics of the program. • Example for (inti = 0; i < n; i++) { x = y + z; a[i] = 6 * i + x * x; } x = y + z; t1 = x * x; for (inti = 0; i < n; i++) a[i] = 6 * i + t1;

  16. Loop unrolling • It is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size (space-time tradeoff). The transformation can be undertaken manually by the programmer or by an compiler optimization technique. • Advantages • branch penalty is minimized. • If the statements in the loop are independent of each other (i.e. where statements that occur earlier in the loop do not affect statements that follow them), the statements can potentially be executed in parallel. • Disadvantages • Increased program code size, which can be undesirable, particularly for embedded applications.

  17. Loop unrolling : Example