[llvm-dev] Loop splitting as a special case of unswitch

Jun Lim via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 22 13:15:23 PST 2018


For the example code below,
  int L = M + 10;
  for (k = 1 ; k <=L; k++) {
    dummy();
    if (k < M)
      dummy2();
  }
, we can split the loop into two parts like :

  for (k = 1 ; k != M; k++) {
    dummy();
    dummy2();
  }
  for (; k <=L; k++) {
    dummy();
  }

By splitting the loop, we can remove the conditional block in the loop and indirectly increase vectorization opportunities. If we know that a loop has a conditional branch that is always true for one part of the iteration space and false for the other, then we can split such loop into two parts. As far as I check, GCC seems to handle this already (-fsplit-loops). For me, it seem possible to handle this as a special case of the loop-unswitch. Does anyone have any opinion about this transformation? 

Thanks,
Jun



More information about the llvm-dev mailing list