Опубликован: 12.07.2012 | Уровень: специалист | Доступ: платный
Лекция 4:

Optimizing compiler. Loop optimizations

< Лекция 3 || Лекция 4: 123456 || Лекция 5 >
Аннотация: This lecture is devoted to the loops and loop optimizations. Discussed topics are: the problem of classification and loop recognition; the reasons for loop optimization precise study; common loop optimizations; optimization examples; the notion of dependency and permutation; optimization admissibility criterion in terms of dependencies; compiler command line options.
Ключевые слова: presentation, CAN, MOST, hot spot, microprocessor, AND, compiler, attention, example, stream, detector, this, hardware, performance, processing, loop optimization, with, sequential, iteration, complexity, used, optimization, INDEX, constant, invariance condition, jump, loop body, ITS, estimation, loop unswitching, inverse, heuristic, loop distribution, memory reference, if, improve, Register, usage, useful, parallelization, vectorization, loop fusion, parallelism, level, Data, reusable, criteria, simplify, reduce, loop iteration, goal, loop unrolling, control instruction, branch, Instruction, expansion, loop interchange, cache performance, accessing, array element, space, chunk, stay, cache, array, fit, reuse, decrease, cache size, linear function, Calculated, previous, addition, very, complex, loop collapsing, CASE, prove, correctness, determine, calculate, output, VALUES, effective, change, SEQUENCE, permute, cause, dependence, Connection, statement, dependent, maintainer, result, concept, linearly dependent, GET, real, FROM, ALL, EXCEPT, First, control dependence, NOT, data dependency, classify, AS, analysis, step, form, nested loop, vector, dependency, SET OF, equivalence, computing process, compiler optimization, reordering, optimizing compiler, technique, storage, location, ONE, point, proper, find, important, remove, memory, ambiguous, non-overlapping, information, decision, difference, default, ANSI, aliasing, USER, require, practice, incompatible, option, compilation time, perform, special, language, facilitator, attribute, pointer, expression, explicit declaration, functional argument

The presentation can be downloaded here.


Рис. 4.1.

Loops

In most of the cases, the loops are "hot spots" of the program.

That's why microprocessor architects and compiler developers pay high attention to the loops.

For example, Loop Stream Detector eliminates the sampling and decoding of instructions for the small loops. This is the hardware solution for improving loop performance.

In a compiler, there are many optimizations provided specially for the loop processing.

Loop recognition and classification.

Loop optimizations usually can be performed only for loops with a certain number of iterations and sequentially changing iteration variables. There should no be transitions outside of the loop and calls to unknown functions.

"Good" loops:

for(i=0;i<U;i++)         for(i=0;i<U;i++) {
  a[i]=b[i];               a[j]=b[i];  
                           j+=c*i; } 
i=0;                     i=0; 
do {                     do { 
  a[i]=b[i];               a[i]=b[i];
  i++;} while(i<U);     if(i++>=n) break;
                         while(1);

"Bad" loops

for(i=0;i<3*i-n;i++) 
  a[i]=i;
for(i=0;i<n;i++) {
  a[i]=i;
  if(i<t)   break;}
for(i=0;i<n;i++) {
  a[i]=i;
  if(i==t)   goto loop_skip;}
for(i=0;i<n;i++) {
  a[i]=i;
  t=g(i);}

Consider the complexity of the used structures.

Avoid loops with an uncertain number of iterations.

Loop Optimizations

Loop invariant code motion is an optimization, which finds and brings outside of the loop expressions, independent of the loop index variables. Such expressions are constant on each iteration.


Рис. 4.2.

Loop unswitching is an optimization which takes invariant conditional jump out of the loop body by duplicating its code


Рис. 4.3.
< Лекция 3 || Лекция 4: 123456 || Лекция 5 >
8400 谭
8400 谭
Китай, 从化
JianZhang Xie
JianZhang Xie
Гонконг, HK