diff options
author | Sam Parker <sam.parker@arm.com> | 2017-09-04 08:12:16 +0000 |
---|---|---|
committer | Sam Parker <sam.parker@arm.com> | 2017-09-04 08:12:16 +0000 |
commit | 7cd826a321d96af6581e0b1a5d6ec9ad26dcc6c1 (patch) | |
tree | f23d88c5d107378b4c4b0127a9ea4011be21093a /llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp | |
parent | 69e22789e1e8e65ec14b31586be76ce698933521 (diff) | |
download | llvm-7cd826a321d96af6581e0b1a5d6ec9ad26dcc6c1.zip llvm-7cd826a321d96af6581e0b1a5d6ec9ad26dcc6c1.tar.gz llvm-7cd826a321d96af6581e0b1a5d6ec9ad26dcc6c1.tar.bz2 |
[LoopUnroll][DebugInfo] Don't add metadata to unrolled remainder loop
Debug information can be, and was, corrupted when the runtime
remainder loop was fully unrolled. This is because a !null node can
be created instead of a unique one describing the loop. In this case,
the original node gets incorrectly updated with the NewLoopID
metadata.
In the case when the remainder loop is going to be quickly fully
unrolled, there isn't the need to add loop metadata for it anyway.
Differential Revision: https://reviews.llvm.org/D37338
llvm-svn: 312471
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp index cd5e977..01c9362 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -394,6 +394,12 @@ CloneLoopBlocks(Loop *L, Value *NewIter, const bool CreateRemainderLoop, if (CreateRemainderLoop) { Loop *NewLoop = NewLoops[L]; assert(NewLoop && "L should have been cloned"); + + // Only add loop metadata if the loop is not going to be completely + // unrolled. + if (UnrollRemainder) + return NewLoop; + // Add unroll disable metadata to disable future unrolling for this loop. SmallVector<Metadata *, 4> MDs; // Reserve first location for self reference to the LoopID metadata node. @@ -414,13 +420,11 @@ CloneLoopBlocks(Loop *L, Value *NewIter, const bool CreateRemainderLoop, } LLVMContext &Context = NewLoop->getHeader()->getContext(); - if (!UnrollRemainder) { - SmallVector<Metadata *, 1> DisableOperands; - DisableOperands.push_back(MDString::get(Context, - "llvm.loop.unroll.disable")); - MDNode *DisableNode = MDNode::get(Context, DisableOperands); - MDs.push_back(DisableNode); - } + SmallVector<Metadata *, 1> DisableOperands; + DisableOperands.push_back(MDString::get(Context, + "llvm.loop.unroll.disable")); + MDNode *DisableNode = MDNode::get(Context, DisableOperands); + MDs.push_back(DisableNode); MDNode *NewLoopID = MDNode::get(Context, MDs); // Set operand 0 to refer to the loop id itself. @@ -536,6 +540,8 @@ bool llvm::UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, bool PreserveLCSSA) { DEBUG(dbgs() << "Trying runtime unrolling on Loop: \n"); DEBUG(L->dump()); + DEBUG(UseEpilogRemainder ? dbgs() << "Using epilog remainder.\n" : + dbgs() << "Using prolog remainder.\n"); // Make sure the loop is in canonical form. if (!L->isLoopSimplifyForm()) { @@ -892,6 +898,7 @@ bool llvm::UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, } if (remainderLoop && UnrollRemainder) { + DEBUG(dbgs() << "Unrolling remainder loop\n"); UnrollLoop(remainderLoop, /*Count*/Count - 1, /*TripCount*/Count - 1, /*Force*/false, /*AllowRuntime*/false, /*AllowExpensiveTripCount*/false, /*PreserveCondBr*/true, |