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

    <tr>
        <th>Summary</th>
        <td>
            Miscompile with attributor-light and dse
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            miscompilation,
            llvm:optimizations
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          bevin-hansson
      </td>
    </tr>
</table>

<pre>
    In the following case, running `attributor-light` followed by `dse` results in a miscompilation:
```
define dso_local ptr @fun(ptr noundef %p) {
entry:
  %p.addr = alloca ptr, align 1
  store ptr %p, ptr %p.addr, align 1
  %0 = load ptr, ptr %p.addr, align 1
  ret ptr %0
}

define dso_local i16 @test_it() {
entry:
  %x = alloca i16, align 1
  %p = alloca ptr, align 1
  call void @llvm.lifetime.start.p0(i64 2, ptr %x)
  store i16 42, ptr %x, align 1
 call void @llvm.lifetime.start.p0(i64 2, ptr %p)
  %call = call ptr @fun(ptr noundef %x)
  store ptr %call, ptr %p, align 1
  %0 = load ptr, ptr %p, align 1
  %1 = load i16, ptr %0, align 1
  %cmp = icmp eq i16 %1, 42
  %conv = zext i1 %cmp to i16
  call void @llvm.lifetime.end.p0(i64 2, ptr %p)
  call void @llvm.lifetime.end.p0(i64 2, ptr %x)
  ret i16 %conv
}

declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)

declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
```
Executing `opt -passes='attributor-light,function(dse)' repr.ll` produces an IR where the `store i16 42` is eliminated, but the store is not dead.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVc2O4zgPfBr5IsSw6fjv4ENP5wswh--yLzCQLTrWQpa8Et0_8_QLKU5P0pPdzA7QQEtRsYpFMozwXp0MYsfKL6w8JGKlybquxxdldpMw3luT9Fa-d18Npwn5aLW2r8qc-CA8MnjmbjUm3FmVCSKn-pWs22l1mohV2RaAkvfvASI9hk8d-lWT58pwwWflBzsvSgtS1rDiiWUHlj2xKtv-4lXiqAxy6e03bQeh-UKOs302roZBEy7GrkbiyBmUC4OWs_rLORQNufcPXh4BqZDScVYcuNCBL9AFO0Krk-H5BerJOjxLRdbnj3MkuBPBoMwir7ZCXlgfBTmkC2azy-rDdrjvXuVVcE_o6ZsiBs0jx2_XZlVe3U99eVySQWjNX6ySQV_rlznVakRSM6aehKN0yRg0qtpzuLL-xqC9LWpwsP8E-Sz2e1rLlRaDMpIEW_Hwb2Pzc5IbY4i8Ffhvfb-Pz3_gt4Z8zMBd_DCf26PCAf86zwCUeUDv4RpozUtEfsc34iq_BJONQo8biUY-Lu3vxF9XOAz9ZiEk_A9zP2jh8NdmQM2zcKeLmrGDWGh1-CH5K5Q3mT8kvF1R_3vDYaVtGdqF-G4R3qNnxYFB_dN2hOdxNUPcedCExQgtg5o7XFyqdViTi7NyHdBzYfjXP_jrhA7jGmZVdvMlqjKuPEetZmUEoQwp9ytF7Ab03FjiEoVME9kVsi1akWCXV21elwVAlUxdiVCjrCTUjczGuhWiyou2afdC5j0OZaI6yKDImjzPc6izfdo0RSbLsaiGseyLfmD7DGehdBqrat0pUd6v2FX7Ki8SLXrUPv7YAHxa-xDGhAGEQFY82YXUrL7HNx8ey0PiuvC469eTD31TnvwPHVKksfv_hRT5q6KJfy46F0Zy6TFZne4mosWHLQlHBseTomnt08HODI4xi_O_3eLsnzgQg2P04hkco52_AwAA__-9KSye">