<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/139219>139219</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DebugInfo][CodeGenPrepare] Debug value loss caused by deleting the and instruction
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:codegen,
debuginfo
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Apochens
</td>
</tr>
</table>
<pre>
CodeGenPrepare pass deletes the `and` instruction without salvaging the debug value: https://godbolt.org/z/3d5f7v3oG
https://github.com/llvm/llvm-project/blob/fa2a6d68c6f35e478af3425760ae39e866049eee/llvm/lib/CodeGen/CodeGenPrepare.cpp#L2274
IR before CodeGenPrepare:
```llvm
entry:
%and = and i32 %a, 4, !dbg !13
#dbg_value(i32 %and, !9, !DIExpression(), !13)
br i1 %c, label %bb0, label %bb2, !dbg !14
```
IR after CodeGenPrepare:
```llvm
entry:
#dbg_value(i32 poison, !9, !DIExpression(), !11)
br i1 %c, label %bb0, label %bb2, !dbg !12
```
I'd like to give a PR to fix it.
cc @OCHyams, could you please give me an example of how regression tests check the debug info in CodeGen? (I'm not very familiar with CodeGen...)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVNuO4zYM_Rr5hWggU74--CE7qbcDFOhif6DQhbbVVSzDkrOTfn0hJ-lMp_PQYoEg1OWQ4TkKjwzBjjNRx8pPrDxlcouTX7vj4vVEc8iUN9fuyRv6TPOXlRa5EiwyBDDkKFKAOBGwisvZsIqDnUNcNx2tn-G7jZPfIgTpLnK087hjDalthIt0GzFxhCnGJTBxZNgz7EdvlHfx4NeRYf8nw16Ycqgvwn9m_Mj48R3cxmlTB-3PDHvnLo_w07L6P0hHhr1yXjHsB4myMlWjq0GUVNSNHESBZV1xSaKlpqp40RLRmzo25d2Zv67uGhz0sjAUvyLWxa2z56-gaPArwT-RqVl-ZBW_ffbq_EhzXK-3KwCGpZwNMHGCFK3A_YjhExTpi2Fu1JhCLlICQ2HU-PtNQ2we-Nncwe09np5_fllWCsH6mWHD8HGRi7ROP61WsHnK1unKSUUu7ZTi7_b4rpHiLam_FZBDpPVjAf6tAcBbFT4gtXgbUuf_kVT-IPUDtPADWgxrA85-I4geRnshkPDla9oM9gVsPNxwWgMr-G9Pv1zlOaSy2m_OwNVvsDiSgW65ZwI5A73I8-II_ACT_w4rjXdKECnEAHoi_e3NvNh58GDnh7RM9MCwSa2dYfYRLrReYZBn66xc98l7QA-HA8M2M50wrWhlRl1eF1Vd1xxFNnVVjU2dD6aWbS1VXpSDQa71kFPTNqrKM9shx5KXvOV1yVEc0GipSahclaXJqWIFp7O07pCeNU1uZkPYqMtFi3mb7WKH3V4Q95cXR-0NjWmqkvwMceeYKKaT8pSt3T7FahsDK7izIYbX6tFGt9vVKWU9p6zyxMpP7_515QlOr1YDzocAWm6BDKjrzb0elrQP3atxZdvquv9tNDvpwLC_8750-FcAAAD__3rAnws">