<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97559>97559</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DebugInfo][SimpleLoopUnswitch] Missing debug location updates (Part 1)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
debuginfo,
llvm:transforms
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Apochens
</td>
</tr>
</table>
<pre>
[**SimpleLoopUnswitch-L1248**](https://github.com/llvm/llvm-project/blob/298e292a76289d93f7c1a80c26e354830c6080e4/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L1248C1-L1253C52)
```cpp
-> auto *MergePN =
PHINode::Create(I.getType(), /*NumReservedValues*/ 2, ".us-phi");
MergePN->insertBefore(MergeBB->getFirstInsertionPt());
I.replaceAllUsesWith(MergePN);
MergePN->addIncoming(&I, ExitBB);
MergePN->addIncoming(&ClonedI, ClonedExitBB);
```
[**SimpleLoopUnswitch-L1310**](https://github.com/llvm/llvm-project/blob/298e292a76289d93f7c1a80c26e354830c6080e4/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L1310)
```cpp
ClonedTerminator->eraseFromParent();
-> BranchInst::Create(ClonedSuccBB, ClonedParentBB);
```
[**SimpleLoopUnswitch-L2339**](https://github.com/llvm/llvm-project/blob/298e292a76289d93f7c1a80c26e354830c6080e4/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L2339)
This instruction `TI` is moved out of the loop (i.e., the hoisted conditional instruction in LoopUnswitch) without dropping its debug location.
```cpp
TI.moveBefore(*SplitBB, SplitBB->end());
```
[**SimpleLoopUnswitch-L2352**](https://github.com/llvm/llvm-project/blob/298e292a76289d93f7c1a80c26e354830c6080e4/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L2352)
```cpp
Value *Cond = skipTrivialSelect(BI->getCondition());
if (InsertFreeze)
-> Cond = new FreezeInst(Cond, Cond->getName() + ".fr", BI->getIterator());
BI->setCondition(Cond);
```
[**SimpleLoopUnswitch-L2440**](https://github.com/llvm/llvm-project/blob/298e292a76289d93f7c1a80c26e354830c6080e4/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L2440)
```cpp
// After MSSAU update, remove the cloned terminator instruction NewTI.
ParentBB->getTerminator()->eraseFromParent();
// Create a new unconditional branch to the continuing block (as opposed to
// the one cloned).
-> BranchInst::Create(RetainedSuccBB, ParentBB);
```
[**SimpleLoopUnswitch-L2709**](https://github.com/llvm/llvm-project/blob/298e292a76289d93f7c1a80c26e354830c6080e4/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp#L2709)
```cpp
-> PHINode *Phi =
PHINode::Create(SI->getType(), 2, "unswitched.select", SI->getIterator());
Phi->addIncoming(SI->getTrueValue(), ThenBB);
Phi->addIncoming(SI->getFalseValue(), HeadBB);
SI->replaceAllUsesWith(Phi);
SI->eraseFromParent();
```
godbolt: https://godbolt.org/z/dGGs89eKT (Note that the hoisted br instruction with `!dbg !8` in `%entry` is corresponding to L2339 and other instructions without `!dbg` are corresponding to other Lxxx)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV11zmzgU_TXyiyYMFsaGBz_4o7TMth5P7e4-C3QN2mKJkUSS9tfvXIEdO06b7nZfwmRiBklHh3vvObpwa2WlAOYkXpJ4PeKdq7WZL1pd1qDsqNDimx9jC8IWO3lsG_iodftF2Qfpyvru45hNkn6UxGvCktq51pJoQVhGWFZJV3dFUOojYVnT3J9-7lqj_4bSEZYVjS4Iy1iaAEsZn01Zkoo0OszKMU_Ckk0hiidJFJbTMAlhcoEjcd3ecGUP2hwtYdmu5A03eHPDNCjblrDI812NkXccrWJGWErCNQkXw_9p2P_hbP_kjkTvKO-cpoQtPoGpYLuhJFr3o_R8bT_kGy0A3zxarAxwB4QleVCB239r8R63YivqA7PYdMfPYMHcg_iTNx1YH8OMsn4KCzp719aSMM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