[llvm] [DebugInfo][RemoveDIs] Final cleanup for enabling non-instr-debuginfo (PR #74497)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 09:04:16 PST 2023


https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/74497

Some final errors have turned up when doing stage2clang builds:
 * We can insert before end(), which won't have an attached DPMarker, thus we can have a nullptr DPMarker in Instruction::insertBefore. Add a null check there.
 * We need to use the iterator-returning form of getFirstNonPHI to ensure we don't insert any PHIs behind debug-info at the start of a block.

>From c68790766722ec05f3cd65c04cb07324260748d6 Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Tue, 5 Dec 2023 17:00:38 +0000
Subject: [PATCH] [DebugInfo][RemoveDIs] Final cleanup for enabling
 non-instr-debuginfo

Some final errors have turned up when doing stage2clang builds:
 * We can insert before end(), which won't have an attached DPMarker, thus
   we can have a nullptr DPMarker in Instruction::insertBefore. Add a
   null check there.
 * We need to use the iterator-returning form of getFirstNonPHI to ensure
   we don't insert any PHIs behind debug-info at the start of a block.
---
 llvm/lib/IR/Instruction.cpp         | 2 +-
 llvm/lib/Transforms/Utils/Local.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 920a2ecfb07ee..717e33f1857b8 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -218,7 +218,7 @@ void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I,
 
     // If we're inserting at point I, and not in front of the DPValues attached
     // there, then we should absorb the DPValues attached to I.
-    if (!InsertAtHead)
+    if (NextMarker && !InsertAtHead)
       DbgMarker->absorbDebugValues(*NextMarker, false);
   }
 
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index dfc78aa589ef8..51f39e0ba0cce 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1295,7 +1295,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
     // the same predecessors BB had.
     // Copy over any phi, debug or lifetime instruction.
     BB->getTerminator()->eraseFromParent();
-    Succ->splice(Succ->getFirstNonPHI()->getIterator(), BB);
+    Succ->splice(Succ->getFirstNonPHIIt(), BB);
   } else {
     while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
       // We explicitly check for such uses for merging phis.



More information about the llvm-commits mailing list