C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Machine-Independent Optimization
Code Optimization can perform in the following different ways: (1) Compile Time Evaluation:(a) z = 5*(45.0/5.0)*r (b) x = 5.7 (2) Variable Propagation:Before Optimization the code is: c = a * b x = a till d = x * b + 4 After Optimization the code is: c = a * b x = a till d = a * b + 4 Here, after variable propagation a*b and x*b identified as common sub expression. (3) Dead code elimination:Before elimination the code is: c = a * b x = b till d = a * b + 4 After elimination the code is: c = a * b till d = a * b + 4 Here, x= b is a dead state because it will never subsequently used in the program. So, we can eliminate this state. (4) Code Motion:
do { item = 10; value = value + item; } while(value<100); //This code can be further optimized as item = 10; do { value = value + item; } while(value<100); (5) Induction Variable and Strength Reduction:
Before reduction the code is: i = 1; while(i<10) { y = i * 4; } After Reduction the code is: i = 1 t = 4 { while( t<40) y = t; t = t + 4; }
Next TopicLoop optimization
|