Issue 122388
Summary [InstCombine] Missed fold: `umax(x *nuw 2, x + 1)` => `x == 0 ? 1 : x *nuw 2`
Labels llvm:instcombine, missed-optimization
Assignees
Reporter Kmeakin
    https://godbolt.org/z/TEzxx8vbj

```rust
#[inline(never)]
pub unsafe fn src(x: usize) -> usize {
    std::cmp::max(x.unchecked_mul(2), x + 1)
}

#[inline(never)]
pub unsafe fn tgt(x: usize) -> usize {
    match x {
        0 => 1,
        _ => x.unchecked_mul(2),
 }
}
```

https://alive2.llvm.org/ce/z/ijq6ZJ
```llvm
define noundef i64 @src(i64 noundef %x) {
  %x2 = shl nuw i64 %x, 1
  %x1 = add i64 %x, 1
 %max = tail call noundef i64 @llvm.umax.i64(i64 %x2, i64 %x1)
  ret i64 %max
}

define noundef range(i64 1, 0) i64 @tgt(i64 noundef %x) {
  %eq = icmp eq i64 %x, 0
  %x2 = shl nuw i64 %x, 1
  %max = select i1 %eq, i64 1, i64 %x2
  ret i64 %max
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to