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

Daniel Berlin dberlin at dberlin.org
Fri Jun 4 10:43:19 PDT 2010

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


More information about the llvm-dev mailing list