<div dir="ltr">Hi Hal,<div><br></div><div>  Thanks for the response. I think I found the reason. ( not the debug message above)</div><div>  My loop count is from -n to n, and it fails the "isa<SCEVCouldNotCompute>(TripCountSC)" check and exit.</div><div>  </div><div><br></div><div>Thanks,</div><div>Frances</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 16, 2015 at 9:29 AM, 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"><span class="">----- Original Message -----<br>
> From: "Frances Tzeng" <<a href="mailto:francestzeng@gmail.com">francestzeng@gmail.com</a>><br>
> To: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>><br>
> Cc: <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> Sent: Friday, October 16, 2015 11:19:25 AM<br>
> Subject: Re: [llvm-dev] question about llvm partial unrolling/runtime unrolling<br>
><br>
><br>
> Hi Hal,<br>
><br>
><br>
><br>
> I did<br>
><br>
><br>
> opt.exe -S -debug -loop-unroll -unroll-runtime=true -unroll-count=4<br>
> csShader.ll<br>
><br>
><br>
><br>
> and it prints out:<br>
><br>
><br>
> Args: opt.exe -S -debug -loop-unroll -unroll-runtime=true<br>
> -unroll-count=4 csShader.ll<br>
><br>
><br>
> Loop Unroll: F[build_cs_5_0] Loop %loop_entry<br>
> Loop Size = 82<br>
> partially unrolling with count: 1<br>
><br>
><br>
<br>
</span>Why does it compute a count of 1? If you use a debugger (and/or insert some additional print statements) around here in lib/Transforms/Scalar/LoopUnrollPass.cpp you should be able to figure it out:<br>
<br>
  } else if (Unrolling == Runtime) {<br>
    ...<br>
    // Reduce unroll count to be the largest power-of-two factor of<br>
    // the original count which satisfies the threshold limit.<br>
    while (Count != 0 && UnrolledSize > PartialThreshold) {<br>
      Count >>= 1;<br>
      UnrolledSize = (LoopSize-2) * Count + 2;<br>
    }<br>
    if (Count > UP.MaxCount)<br>
      Count = UP.MaxCount;<br>
    DEBUG(dbgs() << "  partially unrolling with count: " << Count << "\n");<br>
  }<br>
<span class="HOEnZb"><font color="#888888"><br>
 -Hal<br>
</font></span><span class="im HOEnZb"><br>
><br>
><br>
> Thanks,<br>
> Frances<br>
><br>
><br>
> On Thu, Oct 15, 2015 at 9:35 PM, Hal Finkel < <a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a> ><br>
> wrote:<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
</span><div class="HOEnZb"><div class="h5">> From: "Frances Tzeng via llvm-dev" < <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a> ><br>
> To: <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> Sent: Monday, October 12, 2015 6:13:25 PM<br>
> Subject: [llvm-dev] question about llvm partial unrolling/runtime<br>
> unrolling<br>
><br>
><br>
> Hi,<br>
><br>
><br>
><br>
> I am trying to do loop unrolling with loops that don't have constant<br>
> loop counter. It is highly appreciated if anyone can help me on<br>
> this.<br>
><br>
><br>
><br>
><br>
> What I want to do is to turn<br>
><br>
><br>
> loop (n)<br>
> {<br>
> <loop body><br>
> }<br>
><br>
><br>
> into<br>
><br>
><br>
><br>
> loop (n/4)<br>
> {<br>
> <loop body><br>
> <loop body><br>
> <loop body><br>
> <loop body><br>
> }<br>
><br>
><br>
> loop (n%4)<br>
> {<br>
> <loop body><br>
> }<br>
><br>
><br>
> I set allowPartial and Runtime to both 1 (<br>
> llvm::createLoopUnrollPass(Threshold, count, 1, 1) )<br>
> Also overload the UnrollingPreferences structure to gives values to<br>
> all the Partial* members, but the loop still doesn't unroll.<br>
><br>
><br>
> The unrolling process hits this code in LoopUnrollRuntime.cpp<br>
><br>
><br>
><br>
> // Only unroll loops with a computable trip count and the trip count<br>
> needs<br>
> // to be an int value (allowing a pointer type is a TODO item)<br>
> const SCEV *BECountSC = SE->getBackedgeTakenCount(L);<br>
> if (isa<SCEVCouldNotCompute>(BECountSC) ||<br>
> !BECountSC->getType()->isIntegerTy())<br>
> return false;<br>
><br>
><br>
> BECountSC=0xcccccccc and returns false here.<br>
><br>
><br>
> Based on the comments it looks like I still need a constant loop<br>
> counter. Is there a way to unroll with non-constant loop counter as<br>
> in the example above? Computable is not the same as constant. With<br>
> runtime loop unrolling enabled, you can certainly unroll a loop with<br>
> a runtime trip count. If you run with -debug=loop-unroll, what does<br>
> it say regarding your loop?<br>
><br>
> -Hal<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> Thanks,<br>
> Frances<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
><br>
><br>
> --<br>
><br>
> Hal Finkel<br>
> Assistant Computational Scientist<br>
> Leadership Computing Facility<br>
> Argonne National Laboratory<br>
><br>
><br>
<br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</div></div></blockquote></div><br></div>