Issue 74302
Summary [InstCombine] Missing optimzation: fold `(b + ~a) > 0` to `b - a > -1`
Labels new issue
Assignees
Reporter XChy
    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.**
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to