[llvm] [IfConversion] Preserve debug info when flipping a branch (PR #114614)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 16:24:27 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Ellis Hoag (ellishg)

<details>
<summary>Changes</summary>

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
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,

``````````

</details>


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


More information about the llvm-commits mailing list