优化C++软件
Posted wuhui_gdnt
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了优化C++软件相关的知识,希望对你有一定的参考价值。
8.2. 不同编译器的比较
我在7个不同品牌的C++编译器上进行了一系列实验,看它们是否能够进行各种优化。结果汇总在表8.1中。这个表展示了在我的测试例子中,不同的编译器是否成功应用了各种优化方法以及代数约简。
这个表可以给出哪些优化你可以预期一个特定的编译器会进行,哪些优化你必须手动进行的某些预示。
必须强调,在不同的测试例子上,编译器行为会不同。你不能预期编译器的行为总是符合这个表。
优化方法 | Microsoft | Borland | Intel | Gnu | PathScale | PGI | Digital Mars | Watcom | Codeplay |
函数内联 | x | - | x | x | x | x | - | - | x |
常量折叠 | x | x | x | x | x | x | x | x | x |
常量传播 | x | - | x | x | x | x | - | - | x |
指针消除 | x | x | x | x | x | x | x | x | x |
|
|
|
|
|
|
|
|
|
|
公共子表达式消除,整形 | x | (x) | x | x | x | x | x | x | x |
公共子表达式消除,浮点 | x | - | x | x | x | x | - | x | x |
寄存器变量,整形 | x | x | x | x | x | x | x | x | x |
寄存器变量,浮点 | x | - | x | x | x | x | - | x | x |
生命期分析 | x | x | x | x | x | x | x | x | x |
合并相同的分支 | x | - | - | x | - | - | - | x | - |
消除跳转 | x | x | x | x | x | x | - | x | x |
消除分支 | x | - | x | x | x | x | - | - | - |
删除总是true/false的分支 | x | - | x | x | x | x | x | x | x |
循环展开 | x | - | x | x | x | x | - | - | x |
循环不变代码移动 | x | - | x | x | x | x | x | x | x |
数组元素归纳变量 | x | x | x | x | x | x | x | x | x |
其他整型表达式归纳变量 | x | - | x | x | x | - | x | x | x |
浮点表达式归纳变量 | - | - | - | - | - | - | - | - | - |
自动向量化 | - | - | x | x | x | x | - | - | x |
去虚拟化 | - | - | - | x | - | - | - | - | - |
分析指引(profile-guided)优化 | x | - | x | x | x | x | - | - | - |
整体程序优化 | x | - | x | x | x | - | - | - | - |
|
|
|
|
|
|
|
|
|
|
整形代数约简: |
|
|
|
|
|
|
|
|
|
a+b = b+a | x | (x) | x | x | x | x | - | x | x |
a*b = b*a | x | (x) | x | x | x | x | - | x | x |
(a+b)+c = a+(b+c) | x | - | x | x | - | - | x | x | - |
a+b+c = c+b+a | x | - | - | x | - | - | - | - | - |
a+b+c+d = (a+b)+(c+d) | - | - | x | x | - | - | - | - | - |
a*b+a*c = a*(b+c) | x | - | x | x | x | - | - | - | x |
a*x*x*x + b*x*x + c*x + d = ((a*x+b)*x+c)*x+d | x | - | x | x | x | - | - | - | x |
x*x*x*x*x*x*x*x = ((x2) 2) 2 | - | - | x | - | - | - | - | - | - |
a+a+a+a = a*4 | x | - | x | x | - | - | - | - | x |
-(-a) = a | x | - | x | x | x | x | x | x | - |
a-(-b) = a+b | x | - | x | x | x | x | - | x | - |
a-a = 0 | x | - | x | x | x | x | x | x | x |
a+0 = a | x | x | x | x | x | x | x | x | x |
a*0 = 0 | x | x | x | x | x | x | x | - | x |
a*1 = a | x | x | x | x | x | x | x | x | x |
(-a)*(-b) = a*b | x | - | x | x | x | - | - | - | - |
a/a = 1 | - | - | - | - | x | - | - | - | x |
a/1 = a | x | x | x | x | x | x | x | x | x |
0/a = 0 | - | - | - | x | - | - | - | x | x |
(-a == -b) = (a == b) | - | - | - | x | x | - | - | - | - |
(a+c == b+c) = (a == b) | - | - | - | - | x | - | - | - | - |
!(a < b) = (a >= b) | x | x | x | x | x | x | x | x | x |
(a<b && b<c && a<c) = (a<b && b<c) | - | - | - | - | - | - | - | - | - |
乘以常量 = 偏移与加法 | x | x | x | x | - | x | x | x | - |
除以常量 = 乘法与偏移 | x | - | x | x | x | (-) | x | - | - |
|
|
|
|
|
|
|
|
|
|
浮点代数约简: |
|
|
|
|
|
|
|
|
|
具有自动生成的 C 代码的大型 C++ dll 的性能损失 |