Issue 102947
Summary Failure to recognize `llvm.ssub.with.overflow` idiom
Labels llvm:instcombine, missed-optimization
Assignees
Reporter Kmeakin
    InstCombine should recognize code of the form `x == SMIN ? default : -x` and canonicalize it to use `llvm.ssub.with.overflow(0, x)`

https://godbolt.org/z/MqfvKh74G
```rust
#[no_mangle]
#[inline(never)]
pub fn src1(x: i32) -> (i32, bool) {
 x.overflowing_neg()
}

#[no_mangle]
#[inline(never)]
pub fn tgt1(x: i32) -> (i32, bool) {
 0i32.overflowing_sub(x)
}

#[no_mangle]
#[inline(never)]
pub fn src2(x: i32) -> Option<i32> {
 x.checked_neg()
}

#[no_mangle]
#[inline(never)]
pub fn tgt2(x: i32) -> Option<i32> {
 0i32.checked_sub(x)
}

#[no_mangle]
#[inline(never)]
pub fn src3(x: i32) -> Option<i32> {
 x.checked_abs()
}

#[no_mangle]
#[inline(never)]
pub fn tgt3(x: i32) -> Option<i32> {
    if x >= 0 {
        Some(x)
    } else {
        0i32.checked_sub(x)
 }
}

#[no_mangle]
#[inline(never)]
pub fn src4(x: i32) -> (i32, bool) {
 x.overflowing_abs()
}

#[no_mangle]
#[inline(never)]
pub fn tgt4(x: i32) -> (i32, bool) {
    if x >= 0 {
        (x, false)
 } else {
        0i32.overflowing_sub(x)
    }
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to