1 /* Source for debugging optimimzed code test. 2 3 cc -g -O -o optimize optimize.c 4 */ 5 int callee(); 6 int test_opt; 7 8 int main() 9 { 10 int a,b,c,d,e,f,g,h; 11 12 a = 10;; 13 14 /* Value propagate 15 */ 16 b = 2 * a + 1; 17 c = 3 * b + 2; 18 19 /* Re-use expressions 20 */ 21 d = (2 * a + 1) * (3 * b + 2); 22 e = (2 * a + 1) * (3 * b + 2); 23 24 /* Create dead stores--do lines still exist? 25 */ 26 d = (2 * a + 1) * (3 * b + 2); 27 e = (2 * a + 1) * (3 * b + 2); 28 d = (2 * a + 1) * (3 * b + 2); 29 e = (2 * a + 1) * (3 * b + 2); 30 31 /* Alpha and psi motion 32 */ 33 if( test_opt ) { 34 f = e - d; 35 f = f--; 36 } 37 else { 38 f = e - d; 39 f = f + d * e; 40 } 41 42 /* Chi and Rho motion 43 */ 44 h = 0; 45 do { 46 h++; 47 a = b * c + d * e; /* Chi */ 48 f = f + d * e; 49 g = f + d * e; /* Rho */ 50 callee( g+1 ); 51 test_opt = (test_opt != 1); /* Cycles */ 52 } while( g && h < 10); 53 54 /* Opps for tail recursion, unrolling, 55 * folding, evaporating 56 */ 57 for( a = 0; a < 100; a++ ) { 58 callee( callee ( callee( a ))); 59 callee( callee ( callee( a ))); 60 callee( callee ( callee( a ))); 61 } 62 63 return callee( test_opt ); 64 } 65 66 /* defined late to keep line numbers the same 67 */ 68 int callee( x ) 69 int x; /* not used! */ 70 { 71 test_opt++; /* side effect */ 72 73 return test_opt; 74 } 75 76 /* end */