选择等效于-O1的gcc优化标志 [英] Selecting gcc optimisation flags equivalent to -O1

查看:66
本文介绍了选择等效于-O1的gcc优化标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型程序,当使用-O1进行编译时,它的性能要好得多,而不是没有优化.我很想知道编译器所做的哪些优化导致了这种加速.

I have small program that performs much better when compiled with -O1 as opposed to no optimisation. I am interested in knowing what optimisation(s) done by the compiler is leading to this speedup.

我想做的是获取与-O1等效的优化标志列表(从手册页和gcc -Q -v中都得到),然后从列表中挑选出性能如何变化.

What I thought I would do is to take the list of optimisation flags that -O1 is equivalent to (got both from the man page and from gcc -Q -v) and then to pick away at the list to see how the performance changes.

我发现,即使包括整个优化列表,仍然无法提供与-O1优化的程序一样出色的程序.

What I have found is that even including the whole list of optimisations still does not give me a program that performs as well as an -O1 optimised one.

换句话说

gcc -O0 -fcprop-registers -fdefer-pop -fforward-propagate -fguess-branch-probability \
    -fif-conversion -fif-conversion2 -finline -fipa-pure-const -fipa-reference \
    -fmerge-constants -fsplit-wide-types -ftoplevel-reorder -ftree-ccp -ftree-ch \
    -ftree-copy-prop -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse \
    -ftree-fre -ftree-sink -ftree-sra -ftree-ter myprogram.c

gcc -O1 myprogram.c

我正在使用gcc 4.5.3版

I am using gcc version 4.5.3

手册中与-O1相关的优化标志列表中是否还包含-O1以外的其他内容?

Is there something else that -O1 does that isn't included in the list of optimisation flags associated with -O1 in the manual?

推荐答案

使用-S选项检查生成的汇编程序如何?

How about using -S option to check the produced assembler?

从两个也使用"my_program.c"进行的实验看来,-O0选项将禁用所有优化,而与建议的算法列表无关.

From two experiments using also "my_program.c" it seems, that -O0 option disables all optimizations regardless of the long list of suggested algorithms.

这篇关于选择等效于-O1的gcc优化标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆