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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Missing optimzation: fold `(b + ~a) > 0` to `b - a > -1`
        </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/VSii3o

### Description:
```llvm
define i1 @src(i32 %a, i32 %b) {
entry:
 %i10 = xor i32 %a, -1
  %sub2.le = add i32 %b, %i10
  %cmp = icmp sgt i32 %sub2.le, 0
  ret i1 %cmp
}
```
could be folded to:
```llvm
define i1 @src(i32 %a, i32 %b) {
entry:
  %notsub = sub i32 %a, %b
  %cmp = icmp slt i32 %notsub, 4294967295
  ret i1 %cmp
}
```

### Real-world motivation

This snippet of IR is derived from [redis/src/cluster.c@restoreCommand](https://github.com/redis/redis/blob/8a4ccb01b3ea3072eae6ef3e513b0b24b11a85ae/src/cluster.c#L197) (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:https://godbolt.org/z/Tz8sEfYEb

**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/eJy0VE1v4zYQ_TX0ZWBDGkqWdPAhiSMgwBYFtouiPZLiyGaXIgWScjY59LcXpJysN2h7KFCAEEXOmwe--RIh6JMlOrD6ntXHjVji2fnDbw_nl4106uVwZ_SFEGbv3Mj4HZxjnAPjdwx7hr3I1p0xl2nn_IlhPxDD_pVh_-svWnPHiiMr7q5f5OuCI4XB6zlqZxPVat0X60pk65WiUVsCXQKriuAHhq3mCAxrwfABrv-SYQesuV99yEb_8k6a7LosgPEjfHMebt235RWTbsIicWcoA4VSN9wPV44b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