0

Sorry if this is documented somewhere, GCC has a page documenting what optimizations have been done in each optimization level, also gracefully with simple explanation on each. GCC supports levels including 0-3, s, and z, etc. In that page, it says when using -O1, you turn on flags from -fauto-inc-dec to -funit-at-a-time, and when using -O2, you turn on more like -falign-functions and I can read some explanation on them each below.

I know rustc has similar (at least in their names) optimization levels, and can be specified using -Copt-level=# way, I also know rustc's doc provides general explanation on each level, but I couldn't find out what specific optimizations (or, flags) have been done (or, set) in each of them.

Does rustc has something like doc of optimization flags that I can refer to? Or I could find them in LLVM's or Clang's doc?

I would like to dive into it because I wrote some codes (you bet, unsafe) that behaved differently in debug and release profile, so I want to know what optimization(s) might have caused this.

ElevenLee
  • 55
  • 4
  • There is only [a rough overview in the rustc book](https://doc.rust-lang.org/rustc/codegen-options/index.html?highlight=opt-level#opt-level) I don't know what you mean by "same grammar" other than that the levels (0, 1, 2, 3, ..) are loosely based on the ones that `gcc -O` has. – cafce25 Aug 10 '23 at 10:39
  • @cafce25 yes, I mean that both of them are called in the way you wrote (0, 1, 2, 3).To provide some more detail, I wrote a program containing some codes (unsafe though) that behaved differently in debug and release profile, I want to know which optimization might have caused this, so I want to know what optimizations in my `opt-level` had been done. – ElevenLee Aug 10 '23 at 15:41

0 Answers0