From Quasi Paragon
Jump to: navigation, search

Many compiler optimizations focus on loops. If you look at the literature, you'll see the vast majority of papers are 'I made a loop of $this form go faster'. Why is that?

Loops, by their nature, are blocks of code that are executed multiple times, possibly many millions of times. Thus any improvement to that code pays off a million times over. The general approach with loop optimizations is to move code from inside the loop to outside the loop — then it's only executed once. Two classic examples are Load Hoisting and Store Sinking. Loop optimizations can get quite complicated, and the semantics of the source language can make certain optimizations easier (or harder).