Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo][RemoveDIs] Final cleanup for enabling non-instr-debuginfo #74497

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

jmorse
Copy link
Member

@jmorse jmorse commented Dec 5, 2023

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.

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.
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-debuginfo

Author: Jeremy Morse (jmorse)

Changes

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.

Full diff: https://github.com/llvm/llvm-project/pull/74497.diff

2 Files Affected:

  • (modified) llvm/lib/IR/Instruction.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+1-1)
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.

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add/amend a unittest for the absorption fix?

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this check NextMarker != nullptr should move outside this if, to prevent creating a marker on this if there's nothing to absorb? YMMV, not essential.

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classic

EXPECT_EQ(Entry.getTrailingDPValues(), nullptr);
EXPECT_EQ(Exit.getTrailingDPValues(), nullptr);
EXPECT_FALSE(Ret->hasDbgValues());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we could also check there's no marker added. But that may not be possible / reasonable if marker usage is not optimized yet.

@jmorse
Copy link
Member Author

jmorse commented Dec 5, 2023

Both outstanding comments -> answer is that we're not shooting for marker-efficiency yet, which then means it's necessary for markers to exist on all instructions in DDD/RemoveDIs mode.

@jmorse jmorse merged commit 33af16f into llvm:main Dec 5, 2023
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants