[LLVMdev] Prerequisites for the LICM pass

Paul Colea colea.paul13 at gmail.com
Tue Feb 17 07:33:31 PST 2015


Hello,

I am currently in the process of understanding what are the loop-invariant
code motion (LICM) capabilities of the LLVM optimizer. Right now I am
working with a very simple example:

int f() {
  int a = 0;
  int x = 5;
  for (int i = 0; i < 10; i++) {
    a += x*x;
  }
  return a;
}

My intuition would be that applying the loop-invariant code motion pass
alone to this piece of code would store x*x in a temp and then use that in
the loop, instead of computing x*x for every iteration. However, this
doesn't happen for unoptimized clang-generated code (attached), and after
inspecting the LICM implementation and adding debug prints I managed to
understand why.

Of course, in this simple example the entire result can be precomputed
using constant propagation and similar techniques - which happens at any
level of optimization with clang. However, I was hoping that I could still
apply LICM individually and see its transformations in action.

My question is thus: Does LICM assume the IR it operates on has already
been transformed by other passes (apart from the ones listed as
dependencies)? And if yes, is there a place where I can find information on
the preferred pass scheduling for this case? I tried searching but didn't
manage to find anything.

Thank you in advance,
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150217/848ff221/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: singleNest.bc
Type: application/octet-stream
Size: 2056 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150217/848ff221/attachment.obj>


More information about the llvm-dev mailing list