本文介绍了如何优化编译器决定何时以及多大展开循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编译器执行循环解开优化,它是如何由因素决定的展开循环或者是否展开整个循环?由于这是一个空间性能的权衡,平均在使这个程序优化技术是如何effictive有更好的表现?此外,在什么条件下是建议使用此方法(即某些操作或计算)?

此不必是特定于某个特定编译器。它可以是概述此技术背后的想法任何解释以及已在实践中已观察到。


解决方案

stack consumption and locality. instruction counts. ability to make/propagate optimizations based on the unrolled and inlined program. whether the loop size is fixed, or expected to be in a certain range. profile inputs (if applicable). operations which may be removed from the loop body. etc.

it depends largely on the input (your program). it can be slower (not typical) or it can be several times faster. writing a program to run optimally and which also enables the optimizer to do its job is learned.

generally, a large number of iterations on very small bodies, particularly that which is branchless and has good data locality.

if you want to know if the option helps your app, profile.

if you need more than that, you should reserve some time to learn how to write optimal programs, since the subject is quite complex.

这篇关于如何优化编译器决定何时以及多大展开循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:52