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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Missed optimization: fold `a s> -1 ? 0 : (a | 3)` to `smin(0, a | 3)`
        </td>
    </tr>

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

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

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

<pre>
    Alive2 proof: https://alive2.llvm.org/ce/z/ehfCAm

### Motivating example 

```llvm
define i8 @src(i8 %inl) {
entry:
  %or = or i8 %inl, 3
  %cmp = icmp sgt i8 %inl, -1
  %s = select i1 %cmp, i8 1, i8 %or
 ret i8 %s
}
```
can be folded to:
```llvm
define i8 @tgt(i8 %inl) {
entry:
  %or = or i8 %inl, 3
  %s = call i8 @llvm.smin.i8(i8 %or, i8 1)
  ret i8 %s
}
```
this is correct because when `a > -1`, `a | 3 > 0`. 

### Real-world motivation

This snippet of IR is derived from [openssl/crypto/evp/bio_b64.c@b64_write](https://github.com/openssl/openssl/blob/dc9bc6c8e1bd329ead703417a2235ab3e97557ec/crypto/evp/bio_b64.c#L317) (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, email me please.

**Let me know if you can confirm that it's an optimization opportunity, thanks.**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVM-vozYQ_mucy-ghsCHAgUM2KdKTdlVp1UNvK2OGMF1jI9skzf71lSHv5aWqtj1UssA_Ps_4m5lvpPd0NogNKz6x4rSTSxita34_jrddZ_tbc9B0QQ6zs3Zg4gBjCLNn4sB4y3gr19NE68uUWHdmvFXIePuD8RbH4XiYWHpi6eH-5WIb8MUGushA5gz4p5xmjfAE3KfbiHa3rR4HMghUActT7xTjVZzzgoxmvAZWftqAaIK7xfetK4gQ64CJE1gHH64cQX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