-O3
との違いを調べるために、gcc マニュアルを読んでいました-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
一方、-Ofast
-オファスト
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
実際に安全ですか?
ベストアンサー1
Ofast
は、浮動小数点セマンティクスの C 標準の要件に違反する最適化を有効にします。特に、-Ofast
(別名-ffast-math
) では、浮動小数点計算を自由に並べ替えます (一般にa + (b + c) != (a + b) + c != (a + c) + b
浮動小数点の場合、デフォルトでは禁止されています)。
特定のケースで安全かどうかは-Ofast
アルゴリズムによって異なりますが、いつものほとんどの非科学的なアプリケーションはこれで問題なく動作します。たとえば、ほとんどのゲーム エンジンは で構築されています-ffast-math
。
編集:
2021年以降、-Ofast
GCCでも-fno-semantic-interposition
詳細に説明されているように有効になりますここ。