Issue 115751
Summary Failure to infer that `ctpop(y) == 1` implies `y != 0`
Labels missed-optimization
Assignees
Reporter Kmeakin
    If `y.is_power_of_two()` is `true`, then `y` cannot be `0`, so the `panic` branch should be eliminated

```rust

#[no_mangle]
pub fn src1(x: u32, y: u32) -> u32 {
    if y.is_power_of_two() {
        x / y
    } else {
        0
    }
}

#[no_mangle]
pub fn tgt1(x: u32, y: u32) -> u32 {
    if y.is_power_of_two() {
        x >> y.trailing_zeros()
    } else {
        0
 }
}

#[no_mangle]
pub fn src2(x: u32, y: u32) -> u32 {
    if y.is_power_of_two() {
        x % y
    } else {
        0
 }
}

#[no_mangle]
pub fn tgt2(x: u32, y: u32) -> u32 {
    if y.is_power_of_two() {
        x & (y - 1)
    } else {
        0
 }
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to