<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>This API needs some revisions. The current description/naming
leaves open the following questions:</p>
<ol>
<li>What is returned for a single loop which has no statically
known exit count?</li>
<li>In the case of a 3-deep nest, which parent loop is considered?</li>
</ol>
<p>Possible naming suggestions:</p>
<p>hasIterationCountInvariantInParent<br>
hasIterationCountInvariantInNest<br>
</p>
<br>
<div class="moz-cite-prefix">On 08/10/2018 11:57 PM, David Green via
llvm-commits wrote:<br>
</div>
<blockquote type="cite"
cite="mid:20180811065728.4152685F73@lists.llvm.org">
<pre wrap="">Author: dmgreen
Date: Fri Aug 10 23:57:28 2018
New Revision: 339500
URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project?rev=339500&view=rev">http://llvm.org/viewvc/llvm-project?rev=339500&view=rev</a>
Log:
[UnJ] Create a hasInvariantIterationCount function. NFC
Pulled out a separate function for some code that calculates
if an inner loop iteration count is invariant to it's outer
loop.
Differential Revision: <a class="moz-txt-link-freetext" href="https://reviews.llvm.org/D50063">https://reviews.llvm.org/D50063</a>
Modified:
llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h
llvm/trunk/lib/Transforms/Utils/LoopUnrollAndJam.cpp
llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h
URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h?rev=339500&r1=339499&r2=339500&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h?rev=339500&r1=339499&r2=339500&view=diff</a>
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h Fri Aug 10 23:57:28 2018
@@ -490,6 +490,10 @@ void addStringMetadataToLoop(Loop *TheLo
/// estimate can not be made.
Optional<unsigned> getLoopEstimatedTripCount(Loop *L);
+/// Check inner loop (L) backedge count is known to be invariant on all iterations
+/// of its outer loop. If the loop has no parent, this is trivially true.
+bool hasInvariantIterationCount(Loop *L, ScalarEvolution &SE);
+
/// Helper to consistently add the set of standard passes to a loop pass's \c
/// AnalysisUsage.
///
Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollAndJam.cpp
URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollAndJam.cpp?rev=339500&r1=339499&r2=339500&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollAndJam.cpp?rev=339500&r1=339499&r2=339500&view=diff</a>
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnrollAndJam.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUnrollAndJam.cpp Fri Aug 10 23:57:28 2018
@@ -754,20 +754,7 @@ bool llvm::isSafeToUnrollAndJam(Loop *L,
// Check inner loop backedge count is consistent on all iterations of the
// outer loop
- auto CheckInnerLoopIterationCountInvariant = [](Loop *SubLoop, Loop *OuterL,
- ScalarEvolution &SE) {
- BasicBlock *SubLoopLatch = SubLoop->getLoopLatch();
- const SCEV *SubLoopBECountSC = SE.getExitCount(SubLoop, SubLoopLatch);
- if (isa<SCEVCouldNotCompute>(SubLoopBECountSC) ||
- !SubLoopBECountSC->getType()->isIntegerTy())
- return false;
- ScalarEvolution::LoopDisposition LD =
- SE.getLoopDisposition(SubLoopBECountSC, OuterL);
- if (LD != ScalarEvolution::LoopInvariant)
- return false;
- return true;
- };
- if (!CheckInnerLoopIterationCountInvariant(SubLoop, L, SE)) {
+ if (!hasInvariantIterationCount(SubLoop, SE)) {
LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; Inner loop iteration count is "
"not consistent on each iteration\n");
return false;
Modified: llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
URL: <a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp?rev=339500&r1=339499&r2=339500&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp?rev=339500&r1=339499&r2=339500&view=diff</a>
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp Fri Aug 10 23:57:28 2018
@@ -1521,6 +1521,28 @@ Optional<unsigned> llvm::getLoopEstimate
return (FalseVal + (TrueVal / 2)) / TrueVal;
}
+bool llvm::hasInvariantIterationCount(Loop *InnerLoop,
+ ScalarEvolution &SE) {
+ Loop *OuterL = InnerLoop->getParentLoop();
+ if (!OuterL)
+ return true;
+
+ // Get the backedge taken count for the inner loop
+ BasicBlock *InnerLoopLatch = InnerLoop->getLoopLatch();
+ const SCEV *InnerLoopBECountSC = SE.getExitCount(InnerLoop, InnerLoopLatch);
+ if (isa<SCEVCouldNotCompute>(InnerLoopBECountSC) ||
+ !InnerLoopBECountSC->getType()->isIntegerTy())
+ return false;
+
+ // Get whether count is invariant to the outer loop
+ ScalarEvolution::LoopDisposition LD =
+ SE.getLoopDisposition(InnerLoopBECountSC, OuterL);
+ if (LD != ScalarEvolution::LoopInvariant)
+ return false;
+
+ return true;
+}
+
/// Adds a 'fast' flag to floating point operations.
static Value *addFastMathFlag(Value *V) {
if (isa<FPMathOperator>(V)) {
_______________________________________________
llvm-commits mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a>
</pre>
</blockquote>
<br>
</body>
</html>