[llvm] r359993 - [NFC][Utils] deleteDeadLoop(): add an assert that exit block has some non-PHI instruction
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sun May 5 11:59:13 PDT 2019
Author: lebedevri
Date: Sun May 5 11:59:12 2019
New Revision: 359993
URL: http://llvm.org/viewvc/llvm-project?rev=359993&view=rev
Log:
[NFC][Utils] deleteDeadLoop(): add an assert that exit block has some non-PHI instruction
Summary:
If `deleteDeadLoop()` is called on such a loop, that has "bad" exit block,
one that e.g. has no terminator instruction, the `DIBuilder::insertDbgValueIntrinsic()`
will be told to insert the Dbg Value Intrinsic after `nullptr`
(since there is no first non-PHI instruction), which will cause it to not insert
those instructions into any basic block. The instructions will be parent-less,
and IR verifier will complain. It is rather obvious to track down the root cause
when that happens, so let's just assert it never happens.
Reviewers: sanjoy, davide, vsk
Reviewed By: vsk
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61008
Modified:
llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
Modified: llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp?rev=359993&r1=359992&r2=359993&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp Sun May 5 11:59:12 2019
@@ -584,10 +584,14 @@ void llvm::deleteDeadLoop(Loop *L, Domin
// dbg.value truncates the range of any dbg.value before the loop where the
// loop used to be. This is particularly important for constant values.
DIBuilder DIB(*ExitBlock->getModule());
+ Instruction *InsertDbgValueBefore = ExitBlock->getFirstNonPHI();
+ assert(InsertDbgValueBefore &&
+ "There should be a non-PHI instruction in exit block, else these "
+ "instructions will have no parent.");
for (auto *DVI : DeadDebugInst)
- DIB.insertDbgValueIntrinsic(
- UndefValue::get(Builder.getInt32Ty()), DVI->getVariable(),
- DVI->getExpression(), DVI->getDebugLoc(), ExitBlock->getFirstNonPHI());
+ DIB.insertDbgValueIntrinsic(UndefValue::get(Builder.getInt32Ty()),
+ DVI->getVariable(), DVI->getExpression(),
+ DVI->getDebugLoc(), InsertDbgValueBefore);
// Remove the block from the reference counting scheme, so that we can
// delete it freely later.
More information about the llvm-commits
mailing list