<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><base href="x-msg://1797/"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.apple-style-span
{mso-style-name:apple-style-span;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple style='word-wrap: break-word;-webkit-nbsp-mode: space;-webkit-line-break: after-white-space'><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Here’s the latest patch containing the code to implement loop unrolling for run-time trip counts. I apologize for taking so long with making the suggested changes and submitting a new patch. I think I’ve addressed all of Andy’s comments (much appreciated) below and made the appropriate changes. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The main changes include creating a separate file, called LoopUnrollRuntime.cpp, to separate the code for unrolling loops with run-time or compile-time trip counts. Also, I fixed the implementation so that the loop simplify analysis is preserved.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The only suggestion I didn’t include was using “LVMap.swap(VMap)” instead of copying the map. The ValuetoValueMapTy class doesn’t contain a swap method. Instead, I was able to change the code to reduce the amount of copying that occurs.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The patch passes make check-all and the I’ve run the tests in projects/test-suite with different unroll factors. Also, the ability to unroll loops with run-time trip counts is turned off by default. It is enabled with the –unroll-runtime flag.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I’d appreciate any further comments, etc. on the patch. The turnaround time for any additional changes should be much faster.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Brendon<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-size:10.5pt;font-family:Consolas;color:#1F497D'>--<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:Consolas;color:#1F497D'>Qualcomm Innovation Center, Inc is a member of Code Aurora Forum<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Andrew Trick [mailto:atrick@apple.com] <br><b>Sent:</b> Tuesday, November 15, 2011 11:59 PM<br><b>To:</b> Brendon Cahoon<br><b>Cc:</b> llvm-commits@cs.uiuc.edu LLVM<br><b>Subject:</b> Re: [llvm-commits] [PATCH] Loop unrolling for run-time trip counts<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>For the purpose of code review, I'll ignore the issue of<o:p></o:p></p></div><div><p class=MsoNormal>unroll-runtime profitability, which is obviously left for later. I<o:p></o:p></p></div><div><p class=MsoNormal>will say that this is only half the framework because to achieve<o:p></o:p></p></div><div><p class=MsoNormal>data-alignment we would need to emit an epilog as well. Also, I<o:p></o:p></p></div><div><p class=MsoNormal>misread your original message, and assumed you were adding a prolog<o:p></o:p></p></div><div><p class=MsoNormal>*loop*. That would be nice for targets that care about code<o:p></o:p></p></div><div><p class=MsoNormal>size. There are cases when unrolling the main loop can be done without<o:p></o:p></p></div><div><p class=MsoNormal>increasing the size of the loop body. Your design would not always be<o:p></o:p></p></div><div><p class=MsoNormal>well suited for those cases. On the other hand, your design is a much<o:p></o:p></p></div><div><p class=MsoNormal>simpler CFG transform. We have less SSA/LoopInfo updating to worry<o:p></o:p></p></div><div><p class=MsoNormal>about this way.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Never mind my earlier comment about DominatorTree. I forgot we always<o:p></o:p></p></div><div><p class=MsoNormal>recompute it. You're welcome to fix that :)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>It does seem like your transform should preserve LoopSimplify. I'm<o:p></o:p></p></div><div><p class=MsoNormal>guessing you just need a unique loop exit block--just split the<o:p></o:p></p></div><div><p class=MsoNormal>exit. Can you please do that?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>In general, your implementation looks quite nice.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I am concerned that you're doubling the size of LoopUnroll.cpp for a<o:p></o:p></p></div><div><p class=MsoNormal>feature that most people won't need to look at. I'd be ok with you<o:p></o:p></p></div><div><p class=MsoNormal>creating a new .cpp file. Or at least make it blatantly obvious that<o:p></o:p></p></div><div><p class=MsoNormal>all the new code is specific to runtime-unroll. For example, you can<o:p></o:p></p></div><div><p class=MsoNormal>add function-level comments like "Support for -runtime-unroll", and<o:p></o:p></p></div><div><p class=MsoNormal>code sections like:<o:p></o:p></p></div><div><p class=MsoNormal>//===----------------------------------------------------------------------===//<o:p></o:p></p></div><div><p class=MsoNormal>// Implementation of -runtime-unroll.<o:p></o:p></p></div><div><p class=MsoNormal>//===----------------------------------------------------------------------===//<o:p></o:p></p></div><div><p class=MsoNormal><your code><o:p></o:p></p></div><div><p class=MsoNormal>//===----------------------------------------------------------------------===//<o:p></o:p></p></div><div><p class=MsoNormal>// Driver for loop unrolling transformations.<o:p></o:p></p></div><div><p class=MsoNormal>//===----------------------------------------------------------------------===//<o:p></o:p></p></div><div><p class=MsoNormal>...<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Formatting: You have two 80-col violations, but otherwise looks great.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Typo:<o:p></o:p></p></div><div><p class=MsoNormal>+ // ... loop<o:p></o:p></p></div><div><p class=MsoNormal>+ // loop prologue<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>---<o:p></o:p></p></div><div><p class=MsoNormal>In EmitRuntimePrologueFixup:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>+/// extraiters = tripcount % loopfactor<o:p></o:p></p></div><div><p class=MsoNormal>+/// if (extraiters == 0) jump Loop:<o:p></o:p></p></div><div><p class=MsoNormal>+/// if (extraiters == loopfactor) jump L1<o:p></o:p></p></div><div><p class=MsoNormal>+/// if (extraiters == loopfactor-1) jump L2<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>You may want to comment that you expect a later pass to convert this<o:p></o:p></p></div><div><p class=MsoNormal>to a switch.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Before you erase PH->terminator, maybe you should assert that it has one<o:p></o:p></p></div><div><p class=MsoNormal>successor pointing to PEnd.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>+ std::vector<BasicBlock*> NewBlocks(LoopBlocks.size());<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>No need to initialize the vector, then immediately clear it. You can use<o:p></o:p></p></div><div><p class=MsoNormal>NewBlocks.reserve(LoopBlocks.size()).<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>+ for (unsigned i = Count-1; i > 0; --i) {<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>This is a large, complex loop. To be more self-documenting, use a<o:p></o:p></p></div><div><p class=MsoNormal>meaningful variable like "leftOverIters". Then it will be clear why<o:p></o:p></p></div><div><p class=MsoNormal>you're counting down, and the nested loop won't hide the variable.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>+ if (i != Count-1) {<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>My personal preference, I'd like to see the i == Count-1 case first<o:p></o:p></p></div><div><p class=MsoNormal>since that's what happens first.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>---<o:p></o:p></p></div><div><p class=MsoNormal>In CloneLoopBlocks:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>+ LPM->cloneBasicBlockSimpleAnalysis(LoopBlocks[j], NewBB, L);<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I'm not sure this makes sense given that the new block is in the<o:p></o:p></p></div><div><p class=MsoNormal>parent loop. It may happen to work for the only user, LICM. Since<o:p></o:p></p></div><div><p class=MsoNormal>you're not doing anything to enforce safety in the API, I would add<o:p></o:p></p></div><div><p class=MsoNormal>comments in your code, in the API declaration, and in LICM that 'L' is<o:p></o:p></p></div><div><p class=MsoNormal>the "From" block's loop, not necessarily the "To" block's loop.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>+ if (InsertTop != 0) {<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Why isn't InsertTop set to PH for the first copy?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>+ // Update our running map of newest clones<o:p></o:p></p></div><div><p class=MsoNormal>+ for (ValueToValueMapTy::iterator VI = VMap.begin(), VE = VMap.end();<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>If possible, avoid copying the map. For example, call LVMap.swap(VMap)<o:p></o:p></p></div><div><p class=MsoNormal>later, after you're done with the current loop iteration, before<o:p></o:p></p></div><div><p class=MsoNormal>RemapInstrucion. You might need more explicit handling of header phis<o:p></o:p></p></div><div><p class=MsoNormal>and latch terminators, but it's probably worth it both in efficiency<o:p></o:p></p></div><div><p class=MsoNormal>and code clarity. I realize the current unroller does this, but it<o:p></o:p></p></div><div><p class=MsoNormal>think the copying wasn't removed only because it does membership<o:p></o:p></p></div><div><p class=MsoNormal>checks on LastValueMap, which you don't need.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>In runtime-loop3.ll please use FileCheck instead of grep. We're trying<o:p></o:p></p></div><div><p class=MsoNormal>to minimize dependence on external tools in the unit tests.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>-Andy<o:p></o:p></p></div></div></div></body></html>