<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/91574>91574</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [DebugInfo][JumpThreading] Missing debug location updates
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Apochens
      </td>
    </tr>
</table>

<pre>
    Four missing debug location updates for newly created instructions.

[JumpThreading-L1282](https://github.com/llvm/llvm-project/blob/b52fa9461ab73eaf2d04f32c806a1715b2595830/llvm/lib/Transforms/Scalar/JumpThreading.cpp#L1282): The newly created CastInst, which is inserted before the replaced old LoadInst `LoadI`.
```C++
if (AvailableVal->getType() != LoadI->getType())
      AvailableVal = CastInst::CreateBitOrPointerCast(
          AvailableVal, LoadI->getType(), "", LoadI->getIterator());
LoadI->replaceAllUsesWith(AvailableVal);
LoadI->eraseFromParent();
```

[JumpThreading-L2983](https://github.com/llvm/llvm-project/blob/b52fa9461ab73eaf2d04f32c806a1715b2595830/llvm/lib/Transforms/Scalar/JumpThreading.cpp#L2983): The newly created PHINode `NewPN`, which is inserted befor the replaced old SelectInst `SI`.
```cpp
PHINode *NewPN = PHINode::Create(SI->getType(), 2, "", SI->getIterator());
NewPN->addIncoming(SI->getTrueValue(), Term->getParent());
NewPN->addIncoming(SI->getFalseValue(), BB);
SI->replaceAllUsesWith(NewPN);
SI->eraseFromParent();
```

[JumpThreading-L3120](https://github.com/llvm/llvm-project/blob/b52fa9461ab73eaf2d04f32c806a1715b2595830/llvm/lib/Transforms/Scalar/JumpThreading.cpp#L3120): Newly created PHINode `NewPN`, which is inserted at the beginning of the parent block of the replaced Instruction `Inst`:
```cpp
BasicBlock::iterator InsertionPoint = BB->getFirstInsertionPt();
assert(InsertionPoint != BB->end() && "Empty block?");
 // Substitute with Phis & remove.
for (auto *Inst : reverse(ToRemove)) {
if (!Inst->use_empty()) {
  PHINode *NewPN = PHINode::Create(Inst->getType(), 2);
 NewPN->addIncoming(UnguardedMapping[Inst], UnguardedBlock);
 NewPN->addIncoming(GuardedMapping[Inst], GuardedBlock);
 NewPN->insertBefore(InsertionPoint);
 Inst->replaceAllUsesWith(NewPN);
}
  Inst->dropDbgRecords();
 Inst->eraseFromParent();
}
```

I will give a patch for them later.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVlFvozgQ_jXOi9UIhkDgIQ8h2ezltNurNtm7x5OBAXxnMLJNo_77k01Ik7Rpt6d92MoqkT3zeWb8zWczrXnVIi5ImJJwPWG9qaVaLDuZ19jqSSaLp8VG9oo2XGveVrTArK-okDkzXLa07wpmUNNSKtriQTzRXCEzWFDeaqP63FrpKfHWxFse_4fp733T7WuFrOBtdffFhxhIuCYQ18Z0mgRLAhsCm4qbus-muWwIbIR4HD93nZL_YG4IbDIhM_sJoWTJLPJZNg-QlVB4szKAPPYi5s_9MIMwCePAO8Ph1m-vWKtLqRpNYLPLmWCKwOYivGnedQSCIUhISLCk-xqvkl0xbbatNgRW9FDzvKZc2wqgsqsZllIhNTVShZ1gORZUioJ-kaywXpREnvtNIm8sVeQNY0UgtcPN8pISiJePjAuWCfyTiTsSfKrQ7J86JBATSCgBnwTrAfvFqh0Oibq_cyRqvU55BEsSLFcuu5SbP9SD5K1BZdct0hnGNY4twa3NV5QAuHFpszWomJHqOcjgmPHJ6li4pRDfNeq_uKmvKvGqFyqmcaNk88AUtuaIP5qdivw2PSGJg1-eni7IW_R8-G17Lwu0PLvHw8O9Tfk2U18SdYcCczNSdfcaT20Ybua0FyzdXo5Xx8lzWhGId69zBC6JsnufJW4ja8WKYtvmsuFtdYGvekuR_myTParmuHrBjQ-gbpjQ17Bpeo6wu03d4Rxe2P4UwgY-eL88YV2QA2Hv_x9ZmXFMzbDibWvvJlm6ic6VjmZC5v-Ocyc6b5-vJbuDE7vIsyW6weeUaZ6nFmtgL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