r/Compilers • u/BrainThinkerMan • 24d ago
Compilers add or remove perfomace?
isnt it that compilers change the code, as in not only transferring it into machine language, but before that changing the structure of the code. so how would one attempt to make performant code if the compiler changes sed code that i tried to make performant?
2
Upvotes
View all comments
Show parent comment
2
u/EggplantExtra4946 20d ago
There are many variants but most of them have the Static Single Assignment (SSA) property. The most common is the SSA CFG IR.
Yes, each optimization takes the IR as input and modifies it. Then an another optimization can optimize it more.
Some optimizations require the SSA IR to be shaped specially, for example some loop optimization work on the Loop Closed SSA IR:
https://llvm.org/docs/LoopTerminology.html
https://gcc.gnu.org/onlinedocs/gccint/LCSSA.html
Some high level optimizations work on an SSA IR but where the instructions are high level operations, check out the MLIR dialects. The compiler will do all the high level optimizations on that high level IR, then lower it to an IR with lower level instructions and perform low level optimizations.
https://mlir.llvm.org/docs/Dialects/
Some loop vectorizers transform loops bodies from a CFG IR representation into a predicated IR representation, to eliminate conditionals inside the loop.