Code optimization techniques
Compiler Design · Engineering
Study notes
Optimize 'for(i=0;i<n;i++) a[i] = 2*3 + b*c;': constant folding makes 6; loop-invariant hoisting moves b*c (if b,c unchanged) before the loop; strength reduction turns i*4 addressing into adds. The loop body shrinks from 5 operations to 2, running over twice as fast on large n.