GCC 隐藏优化
GCC hidden optimizations
GCC manual 列出了应用于不同优化级别(-O1、-O2 等)的所有优化标志。然而,在编译和测量基准程序(例如 cBench 的 automotive_bitcount)时,应用优化级别而不是手动打开所有列出的优化时存在显着差异。对于带有 automotive_bitcount 程序的 -O1,我测得在使用 -O1 而不是手动应用所有列出的标志进行编译时,加速大约为 100%。那些“隐藏的”优化实际上似乎是 GCC 为 -O1 所做的优化工作的主要部分。手动应用标志时,与没有优化相比,我只获得了大约 10% 的加速。
当应用来自 gcc -c -Q -O3 --help=optimizers
.
的所有启用标志时,可以观察到同样的情况
在 GCC 手册中,我找到了解释此行为的部分:
Not all optimizations are controlled directly by a flag. Only optimizations that have a flag are listed in this section.
Most optimizations are completely disabled at -O0 or if an -O level is not set on the command line, even if individual optimization flags are specified.
由于找不到关于这些优化的任何进一步文档,我想知道是否有控制它们的方法以及优化的详细信息?
一些优化直接由 -O
标志门控,例如complete unroller:
{
public:
pass_complete_unrolli (gcc::context *ctxt)
: gimple_opt_pass (pass_data_complete_unrolli, ctxt)
{}
/* opt_pass methods: */
virtual bool gate (function *) { return optimize >= 2; }
virtual unsigned int execute (function *);
}; // class pass_complete_unrolli
对其他人来说 -O
会影响他们的内部算法,例如在 optimization of expressions:
/* If FROM is a SUBREG, put it into a register. Do this
so that we always generate the same set of insns for
better cse'ing; if an intermediate assignment occurred,
we won't be doing the operation directly on the SUBREG. */
if (optimize > 0 && GET_CODE (from) == SUBREG)
from = force_reg (from_mode, from);
没有办法解决这个问题,您必须使用 -O
。
GCC manual 列出了应用于不同优化级别(-O1、-O2 等)的所有优化标志。然而,在编译和测量基准程序(例如 cBench 的 automotive_bitcount)时,应用优化级别而不是手动打开所有列出的优化时存在显着差异。对于带有 automotive_bitcount 程序的 -O1,我测得在使用 -O1 而不是手动应用所有列出的标志进行编译时,加速大约为 100%。那些“隐藏的”优化实际上似乎是 GCC 为 -O1 所做的优化工作的主要部分。手动应用标志时,与没有优化相比,我只获得了大约 10% 的加速。
当应用来自 gcc -c -Q -O3 --help=optimizers
.
在 GCC 手册中,我找到了解释此行为的部分:
Not all optimizations are controlled directly by a flag. Only optimizations that have a flag are listed in this section. Most optimizations are completely disabled at -O0 or if an -O level is not set on the command line, even if individual optimization flags are specified.
由于找不到关于这些优化的任何进一步文档,我想知道是否有控制它们的方法以及优化的详细信息?
一些优化直接由 -O
标志门控,例如complete unroller:
{
public:
pass_complete_unrolli (gcc::context *ctxt)
: gimple_opt_pass (pass_data_complete_unrolli, ctxt)
{}
/* opt_pass methods: */
virtual bool gate (function *) { return optimize >= 2; }
virtual unsigned int execute (function *);
}; // class pass_complete_unrolli
对其他人来说 -O
会影响他们的内部算法,例如在 optimization of expressions:
/* If FROM is a SUBREG, put it into a register. Do this
so that we always generate the same set of insns for
better cse'ing; if an intermediate assignment occurred,
we won't be doing the operation directly on the SUBREG. */
if (optimize > 0 && GET_CODE (from) == SUBREG)
from = force_reg (from_mode, from);
没有办法解决这个问题,您必须使用 -O
。