[llvm] [DebugInfo][RemoveDIs] Instrument loop-deletion for DPValues (PR #73042)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 21 14:12:31 PST 2023
================
@@ -642,12 +661,21 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
// be be replaced with undef. Loop invariant values will still be available.
// Move dbg.values out the loop so that earlier location ranges are still
// terminated and loop invariant assignments are preserved.
- Instruction *InsertDbgValueBefore = ExitBlock->getFirstNonPHI();
- assert(InsertDbgValueBefore &&
+ DIBuilder DIB(*ExitBlock->getModule());
+ BasicBlock::iterator InsertDbgValueBefore = ExitBlock->getFirstInsertionPt();
+ assert(InsertDbgValueBefore != ExitBlock->end() &&
"There should be a non-PHI instruction in exit block, else these "
"instructions will have no parent.");
+
for (auto *DVI : DeadDebugInst)
- DVI->moveBefore(InsertDbgValueBefore);
+ DVI->moveBefore(*ExitBlock, InsertDbgValueBefore);
+
+ // Due to the "head" bit in BasicBlock::iterator, we're going to insert
+ // each DPValue right at the start of the block, wheras dbg.values would be
+ // repeatedly inserted before the first instruction. To replicate this
+ // behaviour, do it backwards.
+ for (DPValue *DPV : llvm::reverse(DeadDPValues))
+ ExitBlock->insertDPValueBefore(DPV, InsertDbgValueBefore);
----------------
OCHyams wrote:
It's a shame we have to replicate weirdness. It would be ideal to fix the issue before hand, then apply the DPValue change to a good base. On the other hand, investigating every potential debug-info bug would probably be prohibitive to getting this finished.
https://github.com/llvm/llvm-project/pull/73042
More information about the llvm-commits
mailing list