<div dir="ltr">Thanks for the explanation. But I am a little confused with the following fact. Can't LLVM keep vectorizable_elements as a symbolic value and convert the loop to say;<div><br></div><div>for(unsigned i = 0; i < vectorizable_elements ; i += 2){</div><div> //main loop</div><div>}</div><div><br></div><div>for(unsigned i=0 ; i < vectorizable_elements % 2; i++){</div><div> //fix up</div><div>}</div><div><br></div><div>Why does it have to reason about the range of vectorizable_elements? Even if vectorizable_elements == SIZE_MAX the above decomposition would work?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 12, 2016 at 8:25 PM, Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span class="">
<div class="m_1300953538867614572moz-cite-prefix">On 10/12/2016 4:35 PM, Charith Mendis
via llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi all,
<div><br>
</div>
<div>Attached herewith is a simple vectorized function with
loops performing a simple shuffle.</div>
<div><br>
</div>
<div>I want all loops (inner and outer) to be unrolled by 2 and
as such used -unroll-count=2</div>
<div>The inner loops(with k as the induction variable and having
constant trip counts) unroll fully, but the outer loop with
(j) fails to unroll. </div>
<div><br>
</div>
<div>The llvm code is also attached with inner loops fully
unrolled.</div>
<div><br>
</div>
<div>To inspect further, I added the following to the
PassManagerBuilder.cpp to run some canonicalization routines
and redo unrolling again. I have set partial unrolling on +
have a huge threshold + allows expensive loop trip counts.
Still it didn't unroll by 2.</div>
<div><br>
</div>
<div>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">MPM.add(createLoopUnrollPass()<wbr>);</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">MPM.add(<wbr>createCFGSimplificationPass())<wbr>; </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">MPM.add(<wbr>createLoopSimplifyPass()); </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">MPM.add(createLoopRotatePass(<wbr>SizeLevel
== </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">2</span><span style="font-variant-ligatures:no-common-ligatures"> ? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">0</span><span style="font-variant-ligatures:no-common-ligatures"> : -</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">1</span><span style="font-variant-ligatures:no-common-ligatures">));</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">MPM.add(createLCSSAPass());</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">MPM.add(<wbr>createIndVarSimplifyPass());
</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)">//
Canonicalize indvars</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">MPM.add(createLoopUnrollPass()<wbr>);</span></p>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Digging deeper I found, that it fails in
UnrollRuntimeLoopRemainder function, where it is unable to
calculate the BackEdge taken amount.</div>
<div><br>
</div>
<div>Can anybody explain what is need to get the outer loop
unrolled by 2? It would be a great help.</div>
</div>
</blockquote>
<br></span>
Well, I can at least explain what is happening... runtime unrolling
needs to be able to symbolically compute the trip count to avoid
inserting a branch after every iteration. SCEV isn't able to prove
that your loop isn't an infinite loop (consider the case of
vectorizable_elements==SIZE_<wbr>MAX), therefore it can't compute the
trip count. Therefore, we don't unroll.<br>
<br>
There's a few different angles you could use to attack this: you
could teach the unroller to unroll loops with an uncomputable trip
count, or you can make the trip count of your loop computable
somehow. Changing the unroller is probably straightforward (see the
recently committed r284044). Making the trip count computable is
more complicated... it's probably possible to teach SCEV to reason
about the overflow in the pointer computation, or maybe you could
version the loop.<span class="HOEnZb"><font color="#888888"><br>
<br>
-Eli<br>
<pre class="m_1300953538867614572moz-signature" cols="72">--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Kind regards,<br>Charith Mendis<br><br>Graduate Student,<div>CSAIL,<br><div>Massachusetts Institute of Technology</div></div></div></div></div>
</div>