如何优化编译器决定何时以及多大展开循环? [英] How do optimizing compilers decide when and how much to unroll a loop?

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

问题描述

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

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


解决方案

  

在编译器进行循环展开的优化,它是如何确定由要素展开循环或天气解开整个循环与否。


栈消费和局部性。指令计数。使能/传播的基础上展开的内联和程序优化。是否回路尺寸是固定的,或预期将在一定范围内。个人资料输入(如适用)。这可以从循环体被去除的操作。等等。


  

由于这是一个平均的空间性能权衡如何effictive是制作节目此优化技术有更好的表现?


它在很大程度上取决于输入(程序)。它可以是较慢的(不典型),或者也可以是多次更快。写一个程序以最佳性能运行,并且也使优化器能够完成其工作的经验教训。


  

此外,在什么条件下是建议使用此方法(即某些操作或计算)


通常,在非常小的体大量迭代,特别是它是无网点,并具有良好的数据局部性

如果你想知道,如果选项有助于您的应用程序,个人资料。

如果你需要比这更多,你应该预留一些时间来学习如何编写程序的最佳,因为这个问题是相当复杂的。

When a compiler performs a loop-unroll optimization, how does it determined by which factor to unroll the loop or whether to unroll the whole loop? Since this is a space-performance trade-off, on average how effictive is this optimization technique in making the program perform better? Also, under what conditions is it recommended to use this technique (i.e certain operations or calculations)?

This doesn't have to be specific to a certain compiler. It can be any explanation outlining the idea behind this technique and what has been observed in practice.

解决方案

When a compiler performs a loop unroll optimization, how does it determined by which factor to unroll the loop or weather to unroll the whole loop or not.

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.

Since this is a space-performance tradeoff on average how effictive is this optimization technique in making the program perform better?

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.

Also, under what conditions is it recommended to use this technique (i.e certain operations or calculations)

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆