[llvm-dev] question about llvm partial unrolling/runtime unrolling

Frances Tzeng via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 12 16:13:25 PDT 2015


Hi,

I am trying to do loop unrolling with loops that don't have constant loop
counter. It is highly appreciated if anyone can help me on this.


What I want to do is to turn

    loop (n)
    {
      <loop body>
    }

into

    loop (n/4)
    {
      <loop body>
      <loop body>
      <loop body>
      <loop body>
    }
    loop (n%4)
    {
      <loop body>
    }

I set allowPartial and Runtime to both 1 (
llvm::createLoopUnrollPass(Threshold, count, 1, 1) )
Also overload the UnrollingPreferences structure to gives values to all
the Partial* members, but the loop still doesn't unroll.

The unrolling process hits this code in LoopUnrollRuntime.cpp

  // Only unroll loops with a computable trip count and the trip count needs
  // to be an int value (allowing a pointer type is a TODO item)
  const SCEV *BECountSC = SE->getBackedgeTakenCount(L);
  if (isa<SCEVCouldNotCompute>(BECountSC) ||
      !BECountSC->getType()->isIntegerTy())
    return false;

BECountSC=0xcccccccc and returns false here.

Based on the comments it looks like I still need a constant loop counter.
Is there a way to unroll with non-constant loop counter as in the example
above?

Thanks,
Frances
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151012/fca35421/attachment.html>


More information about the llvm-dev mailing list