<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Vikram,<div class=""><br class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 18, 2016, at 9:21 AM, Vikram TV via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi all,<div class=""><br class=""></div><div class="">I have created a patch (up for review at: <a href="http://reviews.llvm.org/D17386" class="">http://reviews.llvm.org/D17386</a>) that does Loop Fusion implementation.</div><div class=""><br class=""></div><div class="">Approach:</div><div class="">Legality: Currently it can fuse two adjacent loops whose iteration spaces are same and are at same depth. <br class=""></div><div class=""><br class=""></div><div class="">Dependence legality: Currently, dependence legality cannot be checked across loops. Hence the loops are cloned along a versioned path, unconditionally fused along that path and then the dependence legality is checked on the fused loop keeping the instructions from original loops in context. Fusion is illegal if there is a backward dependence between memory accesses whose source was in first loop and sink was in second loop.</div><div class="">Currently, LoopAccessAnalysis is used to check dependence legality.</div></div></div></blockquote><div><br class=""></div><div>Thanks for writing up the design here.</div><div><br class=""></div><div>I think we have a pretty strong policy against creating temporary instructions and here you actually create an entire loop just to check legality.</div><div><br class=""></div><div>It would probably be a better design to add the capability of adding two LAI objects together.  This would effectively simulate the fusion on the analysis side so you could query the legality from that.</div><div><br class=""></div><div>Specifically, you could check if you have backward dependences between instructions in L2 to instructions in L1 which would be illegal.</div><div><br class=""></div><div>As a side effect you’d also get the total set of memchecks which you could filter to only include checks where the participating pointers come from different loops.  (This is quite similar to LoopDistribution.)</div><div><br class=""></div><div>Also I don’t think it should be too hard to teach LVer to be able to version two consecutive loops (or arbitrary CFG?).</div><div><br class=""></div><div>Let me know what you think,</div><div>Adam</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">A basic diagram below tries to explain the approach taken to test dependence legality on two adjacent loops (L1 and L2).</div><div class=""><br class=""></div><div class=""><div class="">    L1PH        (PH: Preheader)</div><div class="">    |               </div><div class="">    L1              </div><div class="">    |               </div><div class="">    CB (L1Exit/L2PH: ConnectingBlock (CB) )</div><div class="">    |               </div><div class="">    L2              </div><div class="">    |               </div><div class="">    L2Exit</div></div><div class=""><br class=""></div><div class="">is versioned as:</div><div class=""><br class=""></div><div class=""><div class="">    BooleanBB      </div><div class="">          /\          </div><div class=""> L1PH  L1PH.clone</div><div class="">         |     |         </div><div class="">      L1    L1.clone  </div><div class="">         |     |         </div><div class="">      CB    CB.clone  </div><div class="">         |     |         </div><div class="">      L2    L2.clone  </div><div class="">          \  /          </div><div class="">       L2Exit</div></div><div class=""><br class=""></div><div class="">And fused as:</div><div class=""><div class=""><br class=""></div><div class="">  BooleanBB      </div><div class="">          /\</div><div class=""> L1PH  FusedPH</div><div class="">         |  |</div><div class="">      L1  L1Blocks</div><div class="">         |  |              \</div><div class="">     CB  L2Blocks |</div><div class="">         |  |             |/</div><div class="">      L2  |</div><div class="">         \ /</div><div class="">   CommonExit</div></div><div class=""><br class=""></div><div class="">Profitability: Yet to be added.</div><div class=""><br class=""></div><div class="">Further, based on legality and profitability success, the fused loop is either retained or removed. If runtime checks are necessary, both original and fused loops are retained; otherwise the original loops are removed.</div><div class=""><br class=""></div><div class="">Currently, I have scheduled the fusion pass after distribution pass. Such a schedule negates the effect of the other pass, but given that the distribution (and fusion) pass is experimental and off by default, I felt it was okay to schedule that way till a global profitability is implemented.</div><div class=""><br class=""></div><div class="">Please share your feedback about the design and implementation.</div><div class=""><br class=""></div><div class="">Thank you</div><div class="">-- <br class=""></div><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Good time...</div><div class="">Vikram TV</div><div class="">CompilerTree Technologies</div><div class="">Mysore, Karnataka, INDIA</div></div></div></div></div>
</div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></div></body></html>