<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58285>58285</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Presence of dbg.declare affects result from DeadStoreElimination
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mikaelholmen
</td>
</tr>
</table>
<pre>
llvm commit: ac47db6acad29
Reproduce with:```opt -passes="default<O2>" -S -o - bbi-74540_2.ll```
Result:
```
define i16 @m() local_unnamed_addr #0 {
[...]
if.then.i.i: ; preds = %entry
store i32 1, ptr getelementptr inbounds ([1 x [1 x [1 x i32]]], ptr @g, i64 1, i64 0, i64 0, i64 0), align 1
%t7.i.i = load i16, ptr @h, align 1
%0 = and i16 %t7.i.i, 1
store i16 %0, ptr @h, align 1
%tobool.not.i.i = icmp eq i16 %0, 0
br i1 %tobool.not.i.i, label %j.exit, label %if.then7.i.i
if.then7.i.i: ; preds = %if.then.i.i
%t8.i.i = load i64, ptr @i, align 1
%inc.i.i = add i64 %t8.i.i, 1
store i64 %inc.i.i, ptr @i, align 1
br label %j.exit
j.exit: ; preds = %entry.j.exit_crit_edge, %if.then.i.i, %if.then7.i.i
```
However, if we comment out the call to the dbg.declare in the input, we iinstead get:
```
define i16 @m() local_unnamed_addr #0 {
[...]
if.then.i.i: ; preds = %entry
store i32 1, ptr getelementptr inbounds ([1 x [1 x [1 x i32]]], ptr @g, i64 1, i64 0, i64 0, i64 0), align 1
%t7.i.i = load i16, ptr @h, align 1
%0 = and i16 %t7.i.i, 1
store i16 %0, ptr @h, align 1
br label %j.exit
j.exit: ; preds = %if.then.i.i, %entry.j.exit_crit_edge
```
So with the dbg.declare present, the bb if.then7.i.i and its contents are left in the code.
[bbi-74541.ll.gz](https://github.com/llvm/llvm-project/files/9754690/bbi-74541.ll.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llv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