EXERCISES

  1. The GNU gcc compiler provides a number of options to control the nature of optimization that is attempted on a given source code. Study the man-page of gcc to get acquainted with the optimization options available. Remember that some of the options are specific to a particular processor. Try to test all possible situations where various techniques of optimization are applicable. At the minimum, compile the following C programs with a command like gcc <optimization options> −S mytest.c, using O1, O2, O3, Os and “unwinding loops” options, to obtain the assembly language output.
    (a)  int main(){
    	int i, j, k;
    	k = 5;
    	i = (k + 5) * (k + 5);
    	j = k + 5;
    	printf(“%d %d %d”, i, j, k);
         }
    (b)  int main(){
    	int i, j, k;
    	for(i = 0; i < 4; i++){
    	    j = 9;
    	    k = i + 4;
    	}
         }
    (c)  int main(){
    	int i, j, k;
    	for(i = 0; i < 4; i++){
    	    j = 9;
    	    k = i + 4;
    	printf(“%d %d %d”, i, j, k); 
    	}
         }
    
  2. Suresh wrote an optimizer for his compiler which did constant folding and propagation and transformed
         i = 0;
    LOOP: i = i + 1;
          …   …
          if(i < 10) goto LOOP;
    into:
         i = 0;
    LOOP: i = 1;
          …   …
          if(1 < 10) goto LOOP;
    
    What is wrong, if any, with this optimization? What is the basic problem?
  3. Apply as many optimization methods as are applicable to the following 4-tuple IR code:
    1:  SUB  4    2  T1
    2:  DIV  T1   2  T2
    3:  MUL  a   T2  T3
    4:  MUL  T3  T1  T4
    5:  ADD  T4   b  T5
    6:  MUL  T3  T1  T6
    7:  ADD  T6   b  T7
    8:  MUL  T5  T7  c
    
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.36