What does the compiler do in assembly when optimizing code? ie -O2 flag

前端 未结 2 1330
感情败类
感情败类 2020-12-29 12:42

So when you add an optimization flag when compiling your C++, it runs faster, but how does this work? Could someone explain what really goes on in the assembly?

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 13:18

    Most of the optimization happens in the compiler's intermediate representation before the assembly is generated. You should definitely check out Agner Fog's Software optimization resources. Chapter 8 of the 1st manual describes optimizations performed by the compiler with examples.

提交回复
热议问题