<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"Frances Tzeng via llvm-dev" <llvm-dev@lists.llvm.org><br><b>To: </b>llvm-dev@lists.llvm.org<br><b>Sent: </b>Monday, October 12, 2015 6:13:25 PM<br><b>Subject: </b>[llvm-dev] question about llvm partial unrolling/runtime unrolling<br><br><div dir="ltr">Hi,<div><br></div><div><div style="font-size: 12.8px;">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.</div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;">What I want to do is to turn</div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;">   <font color="#0000ff"> loop (n)</font></div><div style="font-size: 12.8px;"><font color="#0000ff">    {</font></div><div style="font-size: 12.8px;"><font color="#0000ff">      <loop body></font></div><div style="font-size: 12.8px;"><font color="#0000ff">    }</font></div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;">into</div><div style="font-size: 12.8px;"><div><br></div><div>   <font color="#0000ff"> loop (n/4)</font></div><div><font color="#0000ff">    {</font></div><div><font color="#0000ff">      <loop body></font></div><div><font color="#0000ff">      <loop body></font></div><div><font color="#0000ff">      <loop body></font></div><div><font color="#0000ff">      <loop body></font></div><div><font color="#0000ff">    }<br></font></div></div><div style="font-size: 12.8px;"><div><font color="#0000ff">    loop (n%4)</font></div><div><font color="#0000ff">    {</font></div><div><font color="#0000ff">      <loop body></font></div></div><div style="font-size: 12.8px;"><font color="#0000ff">    }</font></div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;">I set allowPartial and Runtime to both 1 ( llvm::createLoopUnrollPass(Threshold, count, 1, 1) )</div><div style="font-size: 12.8px;">Also overload the UnrollingPreferences structure to gives values to all the Partial* members, but the loop still doesn't unroll.</div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;">The unrolling process hits this code in LoopUnrollRuntime.cpp</div><div style="font-size: 12.8px;"><font color="#38761d"><br></font></div><div style="font-size: 12.8px;"><div><font color="#38761d"> </font><font color="#93c47d"> // Only unroll loops with a computable trip count and the trip count needs</font></div><div><font color="#93c47d">  // to be an int value (allowing a pointer type is a TODO item)</font></div><div><font color="#93c47d">  const SCEV *BECountSC = SE->getBackedgeTakenCount(L);</font></div><div><font color="#93c47d">  if (isa<SCEVCouldNotCompute>(BECountSC) ||</font></div><div><font color="#93c47d">      !BECountSC->getType()->isIntegerTy())</font></div><div><font color="#93c47d">    return false;</font></div></div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;">BECountSC=0xcccccccc and returns false here.</div><div style="font-size: 12.8px;"><br></div><div id="DWT2199" style="font-size: 12.8px;">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?</div></div></div></blockquote>Computable is not the same as constant. With runtime loop unrolling enabled, you can certainly unroll a loop with a runtime trip count. If you run with -debug=loop-unroll, what does it say regarding your loop?<br><br> -Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div><div style="font-size: 12.8px;"></div></div><div><br></div><div>Thanks,</div><div>Frances</div></div>
<br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br></blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>