<div dir="ltr">Hi Gerolf,<div><br></div><div>This patch was one of a sequence of changes to RuntimeUnrolling. We don't have performance data for just this change. The problem it was trying to solve was mitigating slowdown caused by being more aggressive with Runtime unrolling.</div><div><br></div><div>Without this change we still got an benefit however; of the order of 0.5-1.0% geomean improvement on the usual benchmark suites.</div><div><br></div><div>James</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, 15 Jul 2015 at 22:51 Gerolf Hoflehner <<a href="mailto:ghoflehner@apple.com">ghoflehner@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">What is the performance impact of this change?<div><br></div><div>Thanks</div><div>Gerolf</div><div><br><div><blockquote type="cite"></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div>On Mar 9, 2015, at 12:21 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div dir="ltr">Essentially every bot is broken from this commit onward. It seems like you didn't really try bootstrapping Clang and LLVM with this patch in place? For me at least it crashes in numerous places during a bootstrap.<div><br></div><div>I'll revert all of these patches shortly as the bots have already been red for an hour...</div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote">On Sun, Mar 8, 2015 at 11:14 PM, Kevin Qin <span dir="ltr"><<a href="mailto:Kevin.Qin@arm.com" target="_blank">Kevin.Qin@arm.com</a>></span> wrote:<br></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kevinqin<br>
Date: Mon Mar  9 01:14:07 2015<br>
New Revision: 231630<br>
<br></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D231630-26view-3Drev&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=A4JvT7geMFMtpCOFM5UexDcfCN-FhM1D2hV7dsp5dlE&s=QMVKrsnbtT1FXF7fCp236HEGNYTRLnnHM0_nf6MeIEA&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=231630&view=rev</a></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Log:<br>
Run LICM pass after loop unrolling pass.<br>
<br>
Runtime unrollng will introduce a runtime check in loop prologue.<br>
If the unrolled loop is a inner loop, then the proglogue will be inside<br>
the outer loop. LICM pass can help to promote the runtime check out if<br>
the checked value is loop invariant.<br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll<br>
Modified:<br>
    llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp<br>
    llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp<br></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Transforms_IPO_PassManagerBuilder.cpp-3Frev-3D231630-26r1-3D231629-26r2-3D231630-26view-3Ddiff&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=A4JvT7geMFMtpCOFM5UexDcfCN-FhM1D2hV7dsp5dlE&s=TUci7LcLnGsM4hQfCK7ErWjVE9wkgjrTjNSsO_L38yI&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=231630&r1=231629&r2=231630&view=diff</a></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Mon Mar  9 01:14:07 2015<br>
@@ -364,8 +364,14 @@ void PassManagerBuilder::populateModuleP<br>
   MPM.add(createCFGSimplificationPass());<br>
   MPM.add(createInstructionCombiningPass());<br>
<br>
-  if (!DisableUnrollLoops)<br>
+  if (!DisableUnrollLoops) {<br>
     MPM.add(createLoopUnrollPass());    // Unroll small loops<br>
+    // Runtime unrollng will introduce runtime check in loop prologue. If the<br>
+    // unrolled loop is a inner loop, then the prologue will be inside the<br>
+    // outer loop. LICM pass can help to promote the runtime check out if the<br>
+    // checked value is loop invariant.<br>
+    MPM.add(createLICMPass());<br>
+  }<br>
<br>
   // After vectorization and unrolling, assume intrinsics may tell us more<br>
   // about pointer alignments.<br>
<br>
Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp<br></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Transforms_Utils_LoopUnrollRuntime.cpp-3Frev-3D231630-26r1-3D231629-26r2-3D231630-26view-3Ddiff&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=A4JvT7geMFMtpCOFM5UexDcfCN-FhM1D2hV7dsp5dlE&s=FSkeFBCIuoCgLT_oOmwLe5jmK3guEj7JW-wcYxtPReo&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp?rev=231630&r1=231629&r2=231630&view=diff</a></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp Mon Mar  9 01:14:07 2015<br>
@@ -142,7 +142,7 @@ static void CloneLoopBlocks(Loop *L, Val<br>
                             BasicBlock *InsertTop, BasicBlock *InsertBot,<br>
                             std::vector<BasicBlock *> &NewBlocks,<br>
                             LoopBlocksDFS &LoopBlocks, ValueToValueMapTy &VMap,<br>
-                            LoopInfo *LI) {<br>
+                            LoopInfo *LI, LPPassManager *LPM) {<br>
   BasicBlock *Preheader = L->getLoopPreheader();<br>
   BasicBlock *Header = L->getHeader();<br>
   BasicBlock *Latch = L->getLoopLatch();<br>
@@ -153,10 +153,7 @@ static void CloneLoopBlocks(Loop *L, Val<br>
   Loop *ParentLoop = L->getParentLoop();<br>
   if (!UnrollProlog) {<br>
     NewLoop = new Loop();<br>
-    if (ParentLoop)<br>
-      ParentLoop->addChildLoop(NewLoop);<br>
-    else<br>
-      LI->addTopLevelLoop(NewLoop);<br>
+    LPM->insertLoop(NewLoop, ParentLoop);<br>
   }<br>
<br>
   // For each block in the original loop, create a new copy,<br>
@@ -390,7 +387,7 @@ bool llvm::UnrollRuntimeLoopProlog(Loop<br>
   // the loop, otherwise we create a cloned loop to execute the extra<br>
   // iterations. This function adds the appropriate CFG connections.<br>
   CloneLoopBlocks(L, ModVal, UnrollPrologue, PH, PEnd, NewBlocks, LoopBlocks,<br>
-                  VMap, LI);<br>
+                  VMap, LI, LPM);<br>
<br>
   // Insert the cloned blocks into function just before the original loop<br>
   F->getBasicBlockList().splice(PEnd, F->getBasicBlockList(), NewBlocks[0],<br>
<br>
Added: llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll<br></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_LoopUnroll_runtime-2Dloop4.ll-3Frev-3D231630-26view-3Dauto&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=A4JvT7geMFMtpCOFM5UexDcfCN-FhM1D2hV7dsp5dlE&s=Rch6ef4mBLiV7WcmXrIY7HNhM_r4ci_7phgEXGnLD_w&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll?rev=231630&view=auto</a></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll (added)<br>
+++ llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll Mon Mar  9 01:14:07 2015<br>
@@ -0,0 +1,43 @@<br>
+; RUN: opt < %s -S -O2 -unroll-runtime=true | FileCheck %s<br>
+<br>
+; Check runtime unrolling prologue can be promoted by LICM pass.<br>
+<br>
+; CHECK: entry:<br>
+; CHECK: %xtraiter<br>
+; CHECK: %lcmp.mod<br>
+; CHECK: loop1:<br>
+; CHECK: br i1 %lcmp.mod<br>
+; CHECK: loop2.prol:<br>
+<br>
+define void @unroll(i32 %iter, i32* %addr1, i32* %addr2) nounwind {<br>
+entry:<br>
+  br label %loop1<br>
+<br>
+loop1:<br>
+  %iv1 = phi i32 [ 0, %entry ], [ %inc1, %loop1.latch ]<br>
+  %offset1 = getelementptr i32, i32* %addr1, i32 %iv1<br>
+  store i32 %iv1, i32* %offset1, align 4<br>
+  br label %loop2.header<br>
+<br>
+loop2.header:<br>
+  br label %loop2<br>
+<br>
+loop2:<br>
+  %iv2 = phi i32 [ 0, %loop2.header ], [ %inc2, %loop2 ]<br>
+  %offset2 = getelementptr i32, i32* %addr2, i32 %iv2<br>
+  store i32 %iv2, i32* %offset2, align 4<br>
+  %inc2 = add i32 %iv2, 1<br>
+  %exitcnd2 = icmp uge i32 %inc2, %iter<br>
+  br i1 %exitcnd2, label %exit2, label %loop2<br>
+<br>
+exit2:<br>
+  br label %loop1.latch<br>
+<br>
+loop1.latch:<br>
+  %inc1 = add i32 %iv1, 1<br>
+  %exitcnd1 = icmp uge i32 %inc1, 1024<br>
+  br i1 %exitcnd1, label %exit, label %loop1<br>
+<br>
+exit:<br>
+  ret void<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div>
_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></div></blockquote></div></div></div>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>