我刚刚在阅读gcc手册,想了解-O3
和-Ofast
之间的区别。
对于-O3
-O3
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the following optimization flags: -fgcse-after-reload -fipa-cp-clone -floop-interchange -floop-unroll-and-jam -fpeel-loops -fpredictive-commoning -fsplit-paths -ftree-loop-distribute-patterns -ftree-loop-distribution -ftree-loop-vectorize -ftree-partial-pre -ftree-slp-vectorize -funswitch-loops -fvect-cost-model -fversion-loops-for-strides
是GCC编译器的一个选项,它结合了其他优化选项以最大化代码执行速度,但其副作用是牺牲了代码大小和标准的符合性。使用此选项需要谨慎,因为某些代码可能会出现意外行为。
Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for
all standard-compliant programs. It turns on -ffast-math,
-fallow-store-data-races and the Fortran-specific -fstack-arrays, unless -fmax-stack-var-size is specified, and -fno-protect-parens
因此,我想知道-Ofast
是否比-O3
不安全,所以大多数情况下我应该坚持使用-O3
。您能澄清使用它们时的“实际差异”吗? -Ofast
是否真的安全?