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

    <tr>
        <th>Summary</th>
        <td>
            Presence of dbg.declare affects result from LICM
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    llvm commit: 885dadf648
Reproduce with:```opt bbi-75146.ll "-passes=default<O2>"  -S -o -```
Result:
```
entry:
  %f.promoted = load i16, ptr @f, align 1
  %.pre = load i32, ptr @c, align 1
  %a.promoted = load i32, ptr @a, align 1
  %d.promoted14 = load i32, ptr @d, align 1
  %e.promoted19 = load i32, ptr @e, align 1
  br label %for.cond1thread-pre-split

for.cond1thread-pre-split:                        ; preds = %entry, %for.end14
  %dec.lcssa21 = phi i32 [ %e.promoted19, %entry ], [ %dec.lcssa20, %for.end14 ]
  %d.promoted18 = phi i32 [ %d.promoted14, %entry ], [ %d.promoted15, %for.end14 ]
[...]
```
However, if we comment out the call to the dbg.declare in the input, we instead get:
```
entry:
  %f.promoted = load i16, ptr @f, align 1
  %.pre = load i32, ptr @c, align 1
  %a.promoted = load i32, ptr @a, align 1
  %e.promoted14 = load i32, ptr @e, align 1
  %d.promoted17 = load i32, ptr @d, align 1
  br label %for.cond1thread-pre-split

for.cond1thread-pre-split:                        ; preds = %entry, %for.end14
  %d.promoted21 = phi i32 [ %d.promoted17, %entry ], [ %d.promoted18, %for.end14 ]
  %dec.lcssa16 = phi i32 [ %e.promoted14, %entry ], [ %dec.lcssa15, %for.end14 ]
[...]
```
(more differences as well)
[bbi-75146.ll.gz](https://github.com/llvm/llvm-project/files/9858533/bbi-75146.ll.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVtuOmzAQ_Rp4sUBgbuaBh7101UqtWrVfYPAQ3JoYYbPR9us7OJuERGQvfaoaocTOzJn7yaTW4qlS6rEnje57ab3khjCWCS7aPGVedO9FN99hGLWYGiA7aTvU8PJo_-jBkrqWQZHFaR4qRTxKg4EbA8ZL7gW0fFJo8u4r9ZIPKCMk-EECTYKjhYMH4xRv9tcLKWzt-HQUEnSStSGG1GsLgqAjojQXRMa5R-_IYEfipVE7n7mSmy2JF0DEwQKS0AWkWYfwNV9nQL4OFEdgnF6DinUonKDlNSisQOuRKF6DcjXSY9jorYhtNwIXAWYemEFhj_dFdu_XlXAQrry85JagnjAusjla1yCM5tkroL10WQhoQtUYw2nsIEMn51yIl91eJvtsxVlE-b2779VOVqJLX05ztfBszeGyMS85PKll1z2ichiGp-v57H7UO3iEcYbLluzA0QydET1ZYju8c6SN1e4s6k2IWSqOMyq37iu5HSY7o3fz2VjsEdnAf0cVeANV1ub9vEvFe1j2j1LlmM06V5bZvm102WtkOdAqzl8h54tcOVr5a6p4lPUaR07ItoURtg0Ywg0OvlIeLY8Wlvsm3Px2YbDO2sHMc08f8NngmppqbFaPl3m5PX9gy_RPaJBPD61UuKPoQ8kyliUJni7tHlz6UMU5vlieF6UvqkSUScl9K62C6tsIZo6U6PaMvRxTaKwho1tspMUSks-f7r7406iqdwcrjZlctBgry_2uytuMCZY2SZtDLEAkcZHlZZYUbdE2WZP6brJNheXC-viyohGlcUSziCVxXIZFTAueNVHKWJQmtZjZ1XOpwtlxqMeNP7o_BUE9bQwKlTTWnIS44JFKAAf7fLKdHqte_uKgOq3wB853MVcu4D9ADmO_">