<div dir="ltr">Hi Hal,<div><br></div><div><div>I did</div><div><br></div><div>opt.exe -S -debug -loop-unroll -unroll-runtime=true -unroll-count=4  csShader.ll<br></div><div><br></div><div>and it prints out:</div><div><br></div><div>Args: opt.exe -S -debug -loop-unroll -unroll-runtime=true -unroll-count=4 csShader.ll</div><div><br></div><div>Loop Unroll: F[build_cs_5_0] Loop %loop_entry</div><div>  Loop Size = 82</div><div>  partially unrolling with count: 1</div></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks,</div><div class="gmail_extra">Frances</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 15, 2015 at 9:35 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:#000000"><br><hr><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" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>To: </b><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><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<span class=""><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 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></span></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><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><span class="HOEnZb"><font color="#888888"><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></font></span></div></div></blockquote></div><br></div></div>