top of page

Optimizations the compiler makes in the background

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

4 views0 comments

Recent Posts

See All

Closing Thoughts

For my final blog post I would like to discuss what I have learned and plan to utilize in the future from this course. So although I was not able to successfully improve my package to operate function

Stage 3 Optimization(COMPUTER ARCHITECTURE ENDIANESS)

Seeing as how the compiler flags did not provide any optimization I will on to my next attempt which is converting big endian to small endian. The aarch64 architecture uses the little endian byte orde

Stage 3 Optimization(Compiler Flags)

My first attempt to optimize the project will be to work with the compiler flag options. By default the compiler is set to compile in this manner "gcc -E -g -o2" The -E option represents preprocesses

bottom of page