pradeep's blog

Compiler Optimization Techniques PART -II

6. Loop Invariant Code Motion

Here, the part of code that remains unchanged by the iterations of its immediate loops, is moved out of the loop.
By doing so, the redundant computation is eliminated.

Ex:
int main ( void )
{
int i;
int a, b, c;

. . . .
for ( i = 0; i < x; i++ )
{
a[i] = b[i] + c[i];
z = y[x]; /* this statement is redundant here as it is independant of any computations within the loop */
}
. . . .

return i;
}

This can be simplified as follows :

Compiler Optimization Techniques PART -I

code optimization is a technique in which the code is transformed to improve the performance. Performance here can be execution time, code size or both.

Now, let me start away with the common techniques used.

Optimization Techniques -

1. Copy Propogation

copy propagation is the process of replacing the occurrences of targets of direct assignments with their values

ex :
int foo ( void )
{
int x, y = 3;
int z;

x = y;
z = 25 + x;
}

this can be optimized as follows :
int foo ( void )
{
int x, y = 3;

Syndicate content