GCC Optimization Option

I recently used GCC to compile a program, but when I used the -O1 optimization -O1 , it went wrong; there were no problems using -O0 . Therefore, I replaced -O1 with these parameters, as indicated in the official documentation, for example -fauto-inc-dec , -fcompare-elim , -fcprop-registers , etc. However, it works fine without errors, but the performance is not very good.

I want to know if -O1 those small compilation options?

+4
source share
2 answers

Enabling optimization in general ( -O1 vs -O0 ) changes the code generation in ways that do not control the -f flags. Check out this suggestion in the gcc documentation :

Not all optimizations are directly controlled by the flag. This section lists only optimizations that have a flag.

Some details depend on very specific gcc version numbers (e.g. gcc 4.2 vs gcc 4.5, 4.9, etc.).

+3
source

-O1 will enable the following optimization flags:

  -fauto-inc-dec -fcompare-elim -fcprop-registers -fdce -fdefer-pop -fdelayed-branch -fdse -fguess-branch-probability -fif-conversion2 -fif-conversion -fipa-pure-const -fipa-profile -fipa-reference -fmerge-constants -fsplit-wide-types -ftree-bit-ccp -ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre -ftree-phiprop -ftree-slsr -ftree-sra -ftree-pta -ftree-ter -funit-at-a-time 
+1
source

Source: https://habr.com/ru/post/1495443/


All Articles