aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CloneFunction.cpp
diff options
context:
space:
mode:
authorStephen Tozer <stephen.tozer@sony.com>2025-04-09 16:52:05 +0100
committerGitHub <noreply@github.com>2025-04-09 16:52:05 +0100
commit5039bf4e26f07f9082e42374a342b3f52236e3fc (patch)
tree02773a168045166541c4a97805a4264188884fa8 /llvm/lib/Transforms/Utils/CloneFunction.cpp
parenta00a61d59bf1c1f142c8e08b74a0f26991122f7a (diff)
downloadllvm-5039bf4e26f07f9082e42374a342b3f52236e3fc.zip
llvm-5039bf4e26f07f9082e42374a342b3f52236e3fc.tar.gz
llvm-5039bf4e26f07f9082e42374a342b3f52236e3fc.tar.bz2
[DebugInfo][Inline] Propagate source locs when simplifying cond branches (#134827)
During inlining, we may opportunistically simplify conditional branches (incl. switches) to unconditional branches if, after inlining, their destination is fixed. While we do this, we should propagate any DILocation attached to the original branch to the simplified branch, which this patch enables. Found using https://github.com/llvm/llvm-project/pull/107279.
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CloneFunction.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 9387797..3555064 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -607,7 +607,9 @@ void PruningFunctionCloner::CloneBlock(
// Constant fold to uncond branch!
if (Cond) {
BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
- VMap[OldTI] = BranchInst::Create(Dest, NewBB);
+ auto *NewBI = BranchInst::Create(Dest, NewBB);
+ NewBI->setDebugLoc(BI->getDebugLoc());
+ VMap[OldTI] = NewBI;
ToClone.push_back(Dest);
TerminatorDone = true;
}
@@ -622,7 +624,9 @@ void PruningFunctionCloner::CloneBlock(
if (Cond) { // Constant fold to uncond branch!
SwitchInst::ConstCaseHandle Case = *SI->findCaseValue(Cond);
BasicBlock *Dest = const_cast<BasicBlock *>(Case.getCaseSuccessor());
- VMap[OldTI] = BranchInst::Create(Dest, NewBB);
+ auto *NewBI = BranchInst::Create(Dest, NewBB);
+ NewBI->setDebugLoc(SI->getDebugLoc());
+ VMap[OldTI] = NewBI;
ToClone.push_back(Dest);
TerminatorDone = true;
}