<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98787>98787</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DebugInfo][SimpleLoopUnswitch] Missing debug location updates for the new terminators (Part 2)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
loopoptim,
debuginfo,
llvm:transforms
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Apochens
</td>
</tr>
</table>
<pre>
[**SimpleLoopUnswitch-L635**](https://github.com/llvm/llvm-project/blob/5e22a536981483d8411266dccee2ff3e5f31f4a1/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L635)
New branch instruction replaces the old terminator in the same block, without the debug location propagation.
```cpp
// Create a new unconditional branch that will continue the loop as a new
// terminator.
BranchInst::Create(ContinueBB, ParentBB);
```
[**SimpleLoopUnswitch-L672**](https://github.com/llvm/llvm-project/blob/5e22a536981483d8411266dccee2ff3e5f31f4a1/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L672)
New branch instruction replaces the old terminator in the same block, without the debug location propagation.
```cpp
// Remove the cloned branch instruction.
ParentBB->getTerminator()->eraseFromParent();
// Create unconditional branch now.
BranchInst::Create(ContinueBB, ParentBB);
```
[**SimpleLoopUnswitch-L865**](https://github.com/llvm/llvm-project/blob/5e22a536981483d8411266dccee2ff3e5f31f4a1/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L865)
New switch instruction replaces the old terminator in the same block, without the debug location propagation.
```cpp
// Split the preheader, so that we know that there is a safe place to insert
// the switch.
BasicBlock *OldPH = L.getLoopPreheader();
BasicBlock *NewPH = SplitEdge(OldPH, L.getHeader(), &DT, &LI, MSSAU);
OldPH->getTerminator()->eraseFromParent();
// Now add the unswitched switch.
->auto *NewSI = SwitchInst::Create(LoopCond, NewPH, ExitCases.size(), OldPH);
```
[**SimpleLoopUnswitch-L976**](https://github.com/llvm/llvm-project/blob/5e22a536981483d8411266dccee2ff3e5f31f4a1/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L976)
New branch instruction replaces the old terminator in the same block, without the debug location propagation.
```cpp
// Now nuke the switch and replace it with a direct branch.
SIW.eraseFromParent();
BranchInst::Create(CommonSuccBB, BB);
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVs1u6zYTfRp6Q8SQRpItLbzwT4wbIDdf8DkXXVPkyGJDkQJJxW2fviClXMdJGqDtoglg2DR_zpyZOTMY5pw8asQVKTak2M3Y4FtjV-ve8Ba1m9VG_B7PYE1gfZBdr_DWmP6HdifpeXt1u8iK8ZAUOwJl633vSLYmsCewP0rfDvWcm47AXqmn55-r3ppfkXsC-1qZmsC-QABWZIuqTPMyE2WeprBYCM4RoWkyLJosbXKWvsCR4d2DZdo1xnaOwP7AmWI2LN4QnfO-J5CNdCuS7EiyHr_v8ERryzRvqdTO24F7aTS12CvG0VHfIjVKUI-2k5p5Y6nUcdexDmmtDH8ksKUn6Vsz-HgisB6OVBnOIlZvTc-OcT1_aZoskvETyI07MWx0a5F5pIxqPNFBc6OFDK-ZeqbqW-bpSSpFudFe6gGjYWVMT5kbX15AnulPFDYR6EY7H9KVrUebBMrtBLjZBLfumUXtw7oi2eYV7wtnPlTJEr6USgLdT6-S_2Nnnsa8c2U0incYTkjPWbwi2fUR_cNPlgRKAlXYRssc7q3pxrvjwTnlF8J8V5LanP4LaZWLL9WAIt030hrvfAJpUTpl-tArOWL1FltkAm0w4szUepA-anMa__gWLVIZ2o5jDdJInHoT_EHrXyFH5mNMppMNc5Jvgh-UwPp_Stx_oyTb0dv5EX0I4v2ZwoUq6aund3iankb61-IYVBcBA_mI9-0lEGwpgcXuYVrc3oTF98Nh_ePCTET457Vz6f-dOVEmRIzDMKkDxWVIAigbvJmcOtyMTsUr79RViNHWaBHYxxiExfVv0m-ZQzd38g88OzyF49_UXLVcfKWai3Q_fTsPutDDI74oEMq0eCZFp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