This post is in regards to a lecture we had regarding different ways the compiler optimizes our code in the back end behind our eyes.
It is important to understand these optimizations so that we do not waste out time trying to optimize the code ourselves.
-----------------------------
How does a compiler optimize
----------------------------
TIPS TO PREVENT WRITING BAD OPTIMIZATION CODE
COMPILER OPTIMIZATIONS
Compiler does these for us AUTOMATICALLY
DO NOT DO ANY OF THESE OPTIMIZATION COMMANDS
1.Strength Reduction
Substitute an expensive operation for a cheaper
addition is cheaper than multiplication
+ is less expensive than +
2.Hoisting
means lifting up,
if we have a loop-invariant value we can move it out
3. Pre-Calculation of Constants
Does the calculations during compile time
4.Loop unswitching
5.Loop interchange
Reversing inner and outer loops, but make sure you are not writing from
6.Loop unrolling
transformation technique that attempts to optimize a program's execution speed at the expense of its binary size
7.Inlining
Jump Threading
compiler optimization of one jump directly to a second jump. If the second condition is a subset or inverse of the first, it can be eliminated, or threaded through the first jump
8.Short Circuit Evaluation
9.Dead store elimination
When we initialize a variable and assign a value
Comments