aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorShan Huang <52285902006@stu.ecnu.edu.cn>2024-07-19 13:17:21 +0800
committerGitHub <noreply@github.com>2024-07-19 13:17:21 +0800
commit2e5b4516b70be9b8d45d4ecd0bd72c41e91ce6fb (patch)
tree56b389f32f52f4428dcdc1c8e1c1264c21bfc21d /llvm/lib/Transforms
parent82af008d9891bc109ba218fb546170d83c5de9a2 (diff)
downloadllvm-2e5b4516b70be9b8d45d4ecd0bd72c41e91ce6fb.zip
llvm-2e5b4516b70be9b8d45d4ecd0bd72c41e91ce6fb.tar.gz
llvm-2e5b4516b70be9b8d45d4ecd0bd72c41e91ce6fb.tar.bz2
[DebugInfo][SimpleLoopUnswitch] Fix missing debug location updates for new terminators (#98789)
Fix #98787 .
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 6a3b0e1..c235d2fb 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -632,7 +632,8 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
} else {
// Create a new unconditional branch that will continue the loop as a new
// terminator.
- BranchInst::Create(ContinueBB, ParentBB);
+ Instruction *NewBI = BranchInst::Create(ContinueBB, ParentBB);
+ NewBI->setDebugLoc(BI.getDebugLoc());
}
BI.setSuccessor(LoopExitSuccIdx, UnswitchedBB);
BI.setSuccessor(1 - LoopExitSuccIdx, NewPH);
@@ -666,10 +667,12 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
// Finish updating dominator tree and memory ssa for full unswitch.
if (FullUnswitch) {
if (MSSAU) {
- // Remove the cloned branch instruction.
- ParentBB->getTerminator()->eraseFromParent();
- // Create unconditional branch now.
- BranchInst::Create(ContinueBB, ParentBB);
+ Instruction *Term = ParentBB->getTerminator();
+ // Remove the cloned branch instruction and create unconditional branch
+ // now.
+ Instruction *NewBI = BranchInst::Create(ContinueBB, ParentBB);
+ NewBI->setDebugLoc(Term->getDebugLoc());
+ Term->eraseFromParent();
MSSAU->removeEdge(ParentBB, LoopExitBB);
}
DT.deleteEdge(ParentBB, LoopExitBB);
@@ -861,8 +864,11 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
BasicBlock *NewPH = SplitEdge(OldPH, L.getHeader(), &DT, &LI, MSSAU);
OldPH->getTerminator()->eraseFromParent();
- // Now add the unswitched switch.
+ // Now add the unswitched switch. This new switch instruction inherits the
+ // debug location of the old switch, because it semantically replace the old
+ // one.
auto *NewSI = SwitchInst::Create(LoopCond, NewPH, ExitCases.size(), OldPH);
+ NewSI->setDebugLoc(SIW->getDebugLoc());
SwitchInstProfUpdateWrapper NewSIW(*NewSI);
// Rewrite the IR for the unswitched basic blocks. This requires two steps.
@@ -972,8 +978,9 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
/*KeepOneInputPHIs*/ true);
}
// Now nuke the switch and replace it with a direct branch.
+ Instruction *NewBI = BranchInst::Create(CommonSuccBB, BB);
+ NewBI->setDebugLoc(SIW->getDebugLoc());
SIW.eraseFromParent();
- BranchInst::Create(CommonSuccBB, BB);
} else if (DefaultExitBB) {
assert(SI.getNumCases() > 0 &&
"If we had no cases we'd have a common successor!");