[LLVMdev] Speculative phi elimination at the top of a loop?

Nick Lewycky nlewycky at google.com
Mon Jun 7 13:21:11 PDT 2010

On 4 June 2010 10:43, Daniel Berlin <dberlin at dberlin.org> wrote:

> On Fri, Jun 4, 2010 at 8:18 AM, Pekka Nikander
> <pekka.nikander at nomadiclab.com> wrote:
> > I am working on heavily optimising unusually static C++ code, and have
> encountered a situation where I basically want an optimiser that would
> speculatively unroll a loop to see if the first round of the loop could be
> optimised further.  (I happen to know that it is possible.)  The previous
> optimisations that produce the loop in the first place already do a magical
> job (relying heavily on constant propagation), transforming cross-class tail
> recursion into the loop that I am now addressing. Hence, there is probably
> little than can be done in the previous optimisations.
> >
> > So, has anyone worked on an optimisation where the optimiser unrolls a
> loop so a way that allows it to speculatively try if the first round can be
> further simplified?
> >
> > In my case, the loop actually calls a C++ virtual method, but since the
> instance object is a *constant* on the first round of the loop, it is
> possible to resolve the method call into a static function, and then inline
> the static function, which in this case essentially eliminates the first
> round of the loop.
> The combination of GVN-PRE and SCCVN in GCC will do this, and we
> actually block it from doing this in a lot of cases.
> Basically, it can discover some value is constant on the first run
> through a loop, and will create additional phi nodes to represent
> those values.
> In most cases, this is not that valuable (IE it would discover i = i +
> 1 is 2 on the first run through the loop, and replace it with a phi of
> (2, <new calculation>) , and in fact, was significantly confusing to
> SCEV analysis. So we blocked it. In your case, it would be valuable
> however.

I would suggest trying to do this on any pointer-typed const-expr. Thoughts?


> --Dan
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100607/d1ab8be1/attachment.html>

More information about the llvm-dev mailing list