[llvm] [LoopPeel] Added support for cases where PhiAnalyzer contains Induction PHI (PR #94900)

Moriyuki Saito via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 9 07:14:36 PDT 2024


m-sai wrote:

Thanks for your comment.

I thought of using loop peeling to convert if it can be simply expressed using induction variables after a few iterations.

Unfortunately, a small number of trip counts will result in full unrolling, which is illustrated in the following code example.
https://c.godbolt.org/z/eoecW1jvP

In that case, the status of each variable and argument per iteration is as follows
iteration 0: i=0, g(0,0,0,0), x=0, y=0, a=2 
iteration 1: i=1, g(1,0,0,2), x=0, y=2, a=3
iteration 2: i=2, g(2,0,2,3), x=2, y=3, a=4
iteration 3: i=3, g(3,2,3,4), x=3, y=4, a=5
iteration 4: i=4, g(4,3,4,5), x=4, y=5, a=6

I think this is equivalent to the following code.
``` C
  // loop peeling part
  for (int i = 0; i < 2; i++) {
    g(i, x, y, a);
    x = y;
    y = a;
    a = i + 2;
  }
  // simple loop part
  for (int i = 3; i < 1000; i++) {
    g(i, i-1, i, i+1);
  }
```


https://github.com/llvm/llvm-project/pull/94900


More information about the llvm-commits mailing list