For faster navigation, this Iframe is preloading the Wikiwand page for 循环不变代码外提.

循环不变代码外提

循环不变代码外提(英语:loop-invariant code motion,缩写LICM)在计算机编程中是指将循环不变的语句或表达式移到循环体之外,而不改变程序的语义。循环不变代码外提在英文中又被称为hoistingscalar promotion,是编译器中常见的优化方法。

示例

[编辑]

假设有如下代码:

for (int i = 0; i < n; i++) {
    x = y + z;
    a[i] = 6 * i + x * x;
}

其中x = y + zx * x这两步运算是循环不变的,会在优化中被移出循环体之外。经LICM优化后的代码为:

x = y + z;
t1 = x * x;
for (int i = 0; i < n; i++) {
    a[i] = 6 * i + t1;
}

参见

[编辑]

参考文献

[编辑]
  • Aho, Alfred V.; Sethi, Ravi; & Ullman, Jeffrey D. (1986). Compilers: Principles, Techniques, and Tools. Addison Wesley. ISBN 0-201-10088-6.
  • Compiler Optimizations — Hoisting
{{bottomLinkPreText}} {{bottomLinkText}}
循环不变代码外提
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?