Skip to content

Conversation

@ellishg
Copy link
Contributor

@ellishg ellishg commented Nov 1, 2024

Grab the debug info location of a branch condition before we remove it and insert a flipped condition.

@arsenm
Copy link
Contributor

arsenm commented Nov 1, 2024

Testcase?

@llvmbot
Copy link
Member

llvmbot commented Nov 1, 2024

@llvm/pr-subscribers-debuginfo

Author: Ellis Hoag (ellishg)

Changes

Grab the debug info location of a branch condition before we remove it and insert a flipped condition.


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

1 Files Affected:

  • (modified) llvm/lib/CodeGen/IfConversion.cpp (+7-8)
diff --git a/llvm/lib/CodeGen/IfConversion.cpp b/llvm/lib/CodeGen/IfConversion.cpp
index ba5605ad5cb4a4..bb9ca7edf7844c 100644
--- a/llvm/lib/CodeGen/IfConversion.cpp
+++ b/llvm/lib/CodeGen/IfConversion.cpp
@@ -617,14 +617,13 @@ static MachineBasicBlock *findFalseBlock(MachineBasicBlock *BB,
 /// Reverse the condition of the end of the block branch. Swap block's 'true'
 /// and 'false' successors.
 bool IfConverter::reverseBranchCondition(BBInfo &BBI) const {
-  DebugLoc dl;  // FIXME: this is nowhere
-  if (!TII->reverseBranchCondition(BBI.BrCond)) {
-    TII->removeBranch(*BBI.BB);
-    TII->insertBranch(*BBI.BB, BBI.FalseBB, BBI.TrueBB, BBI.BrCond, dl);
-    std::swap(BBI.TrueBB, BBI.FalseBB);
-    return true;
-  }
-  return false;
+  if (TII->reverseBranchCondition(BBI.BrCond))
+    return false;
+  auto Dl = BBI.BB->findBranchDebugLoc();
+  TII->removeBranch(*BBI.BB);
+  TII->insertBranch(*BBI.BB, BBI.FalseBB, BBI.TrueBB, BBI.BrCond, Dl);
+  std::swap(BBI.TrueBB, BBI.FalseBB);
+  return true;
 }
 
 /// Returns the next block in the function blocks ordering. If it is the end,

@ellishg ellishg requested a review from jmorse November 4, 2024 14:58
Copy link
Member

@jmorse jmorse left a comment

Choose a reason for hiding this comment

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

Change looks good, with a test of course

@ellishg
Copy link
Contributor Author

ellishg commented Nov 4, 2024

I can't find a test case where the debug location was incorrect or missing before this change, but it is fairly easy to find a test that executes this code (some existing tests already do). Is this acceptable to land without a test?

@arsenm
Copy link
Contributor

arsenm commented Nov 4, 2024

I can't find a test case where the debug location was incorrect or missing before this change

Then what is the point?

@ellishg
Copy link
Contributor Author

ellishg commented Nov 4, 2024

I saw this comment in a few places and I figured it would be an easy improvement.

DebugLoc dl; // FIXME: this is nowhere

@arsenm
Copy link
Contributor

arsenm commented Nov 4, 2024

I saw this comment in a few places and I figured it would be an easy improvement.

DebugLoc dl; // FIXME: this is nowhere

Should be easily MIR testable?

@ellishg ellishg closed this Nov 20, 2024
@ellishg ellishg deleted the if-conversion-debug branch November 20, 2024 18:11
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.

4 participants