循环不变代码外提
示例
假设有如下代码:
for (int i = 0; i < n; i++) {
x = y + z;
a[i] = 6 * i + x * x;
}
其中x = y + z
与x * 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
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.