Compiler Optimization: where / how can I understand what is the gain for different optimizations?

In my independent study of various compiler books and websites, I study many different ways that the compiler can optimize the code that compiles, but I find it difficult to understand what benefit for each optimization will tend to give.

How do most compiler authors decide which optimizations to implement first? Or which optimization is worth the effort or is it not worth the effort? I understand that this will differ between types of code and even individual programs, but I hope that there will be enough similarities between most programs, for example, that one of these techniques usually gives you better performance than the other method.

+5
source share
8 answers

I found that when implementing textbook compiler optimizations, some of them tended to override the improvements made by other optimizations. This entailed a lot of work, trying to find the right balance between them.

Thus, there really is no good answer to your question. All this is a compromise. Many optimizations work well on one type of code, but are pessimizations for other types. This is similar to designing a house - if you make the kitchen larger, the pantry will become smaller.

The real job of creating an optimizer is trying out various combinations, comparing the results and, like a chef, choosing the right combination of ingredients.

+13
source

Tongue on the cheek:

  • Arrogance
  • Benchmarks
  • Embarrassment

, . ...

" ":

" ":

bennchmarking.

; , .

, , . - , .

, . , SSA Briggs-Chaitin .

+4

"" , , ( "" "" ).

, (, SIMD ).

. .

, .

+3

, , ?

:

1) ,

2) -

3)

4) , 1; , .

5)

, .

, , . , , .

+2

, . LLVM, , , , . , , , . .

+2

, (,?) . , , , - , - , ( ..), , , , .

+1

, , , . , , - , -, , . , GCC , . . , rvalue ( ++ 0x). STL , .

* , . . ints , ints .

+1
source

One that can give great acceleration, but rarely done, is to insert memory prefetch instructions. The trick is to figure out which memory the program will program far enough forward, never ask for the wrong memory, and never overflow the D-cache.

0
source

All Articles