From 8109012fbeff173bfed0c30cd5895f000bd9099c Mon Sep 17 00:00:00 2001 From: Ellis Hoag Date: Fri, 1 Nov 2024 14:55:38 -0700 Subject: [PATCH] [IfConversion] Preseve debug info when flipping a branch --- llvm/lib/CodeGen/IfConversion.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/llvm/lib/CodeGen/IfConversion.cpp b/llvm/lib/CodeGen/IfConversion.cpp index ba5605ad5cb4a..bb9ca7edf7844 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,