Skip to content

Failure to infer that ctpop(y) == 1 implies y != 0 #115751

Closed
@Kmeakin

Description

@Kmeakin

If y.is_power_of_two() is true, then y cannot be 0, so the panic branch should be eliminated

https://godbolt.org/z/q9jhsnqs7

pub fn div(x: u32, y: u32) -> u32 {
    if y.is_power_of_two() {
        x / y
    } else {
        0
    }
}

pub fn rem(x: u32, y: u32) -> u32 {
    if y.is_power_of_two() {
        x % y
    } else {
        0
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions