【发布时间】:2019-02-25 09:10:30
【问题描述】:
在编译/链接适用于 ISA 的所有实现(例如 x86-64)的 C/C++ 库或程序时,从正确性和运行时性能的角度来看,哪些优化标志是安全的?我希望优化能够产生正确的结果,并且不会损害特定 CPU 的性能。例如,我想避免在第 8 代 Intel Core i7 上产生运行时性能改进,但在 AMD Ryzen 上导致性能下降的优化标志。
PGO、LTO 和-O3 安全吗?它是否仅依赖于-march 和-mtune(或不存在)?
【问题讨论】:
-
Are compiler optimizations safe?、When can I confidently compile program with -O3?、Safety-critical software and optimising compilers、Can compiler optimization introduce bugs?。所有
-Ox优化都是安全的。如果它们产生不同的结果,那么您的代码中可能存在错误/UB,或者是编译器错误
标签: gcc optimization