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

    <tr>
        <th>Summary</th>
        <td>
            Merge `assume`d `icmp`s despite one being after a `trunc`
        </td>
    </tr>

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

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

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

<pre>
    In [playing around](https://rust.godbolt.org/z/fW9fjjb4M) with some Rust, I ended up with this LLVM IR:
```llvm
define noundef i8 @demo(i64 noundef %x) unnamed_addr #0 {
  %0 = tail call i64 @llvm.uadd.sat.i64(i64 %x, i64 48)
  %_6 = icmp ult i64 %0, 256
  tail call void @llvm.assume(i1 %_6)
  %_7 = trunc i64 %0 to i8
  %1 = icmp sgt i8 %_7, -1
  tail call void @llvm.assume(i1 %1)
  ret i8 %_7
}
```

I was surprised to see both `assume`s, since I know that LLVM is perfectly capable <https://llvm.godbolt.org/z/z85rnMhWK> of merging those checks where there aren't `assume`s involved.

Trunk appears not to be able to further simplify this either: <https://llvm.godbolt.org/z/YeWb45186>

It would, however, be equivalent to have only
```llvm
define noundef i8 @src(i64 noundef %x) unnamed_addr #1 {
start:
  %0 = tail call i64 @llvm.uadd.sat.i64(i64 %x, i64 48)
  %_6 = icmp ult i64 %0, 128
  tail call void @llvm.assume(i1 %_6)
  %_7 = trunc i64 %0 to i8
  ret i8 %_7
}
```
Which Alive confirms <https://alive2.llvm.org/ce/z/EiFHYQ> is sufficient to expose all the UB that was present in the original.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU9v47YT_TT0ZRCDomxZPuiQxDF-xm9z6KJtsKcFRY4kJhSp8o-93k9fUFIde_eSPbSAIUua0Zs3M--B3HvVGsSKrB_IerfgMXTWVV7YEHrRL2orz9XBAFk_DJqflWmBOxuNJOsdYWUXwuB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