简体   繁体   English

GCC精心挑选的优化

[英]GCC handpicking Optimizations

I see this thread, and I had the same question, but this one isn't really answered: GCC standard optimizations behavior 我看到了这个线程,并且我有同样的问题,但是这个问题并未得到真正的回答: GCC标准优化行为

I'm trying to figure out exactly what flag is causing an incredible boost in performance, in O1. 我试图弄清楚到底是什么标志在O1中引起了不可思议的性能提升。 I first found out which flags are set, using g++ -O1 -Q --help=optimizers and then got each of the enabled ones and used them to compile with g++. 我首先使用g++ -O1 -Q --help=optimizers找出设置了哪些标志,然后获取每个已启用的标志,并使用它们与g ++进行编译。 But the output results were different (the binary itself was of difference sizes). 但是输出结果不同(二进制文件本身的大小不同)。

How do I handpick optimizations for g++ or is this not possible? 我该如何为g ++进行优化选择?

Not all optimizations have individual flags, so no combination of them will generate the same code as using -O1 or any other of the general optimization enabling options ( -Os , -O2 , etc...). 并非所有优化都有单独的标志,因此它们的组合不会生成与使用-O1或任何其他常规优化启用选项( -Os-O2等)相同的代码。 Also I imagine that a lot of the specific optimization options are ignored when you use -O0 (the default) because they require passes that are skipped if optimization hasn't generally enabled. 我还想像到,当您使用-O0 (默认值)时,许多特定的优化选项会被忽略,因为如果通常未启用优化功能,则它们会忽略通过的传递。

To try to narrow down your performance increase you can try using -O1 and then selectively disabling optimizations. 若要缩小性能提升的范围,可以尝试使用-O1 ,然后有选择地禁用优化。 For example: 例如:

g++ -O1 -fno-peephole -fno-tree-cselim -fno-var-tracking ...

You still might not have better luck this way though. 但是您可能仍然没有这种运气。 It might be multiple optimizations in combination are producing your performance increase. 可能是多种优化结合在一起可以提高性能。 It could also be the result of optimizations not covered by any specific flag. 这也可能是任何特定标志未涵盖的优化的结果。

I also doubt that better cache locality resulted in your "incredible boost in performance". 我还怀疑更好的缓存局部性会导致您的“令人难以置信的性能提升”。 If so it was likely a coincidence, especially at -O1 . 如果是这样,那可能是巧合,尤其是在-O1 Big performance increases usually come about because GCC was able eliminate a chunk of your code either because it didn't actually have any net effect, always resulted in the same value being computed or it invoked undefined behaviour. 通常,由于GCC能够消除您的代码块,或者是因为它实际上没有任何净效果,总是导致计算出相同的值或调用了未定义的行为,所以通常会带来性能的大幅提高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM