Skip to content

Regression in debug codegen for simple division #111663

Open
@carbotaniuman

Description

@carbotaniuman

I tried this code:

pub fn num_pages(alloc: i32) -> i32 {
    num / 4096
}

I expected to see this happen: There not to be any excess code or panics for a simple division.

Instead, this happened: In 1.69, there are no panics of any kind, and rustc simply generates the division as it should. In the current nightly, rustc generates a panic call. I go through a lot of care in this code to only use raw pointers and such to avoid overhead for debug mode performance, and yet this constant division still exists. There's also no unchecked_div, so I can't even use unsafe to get out of this.

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (2c41369ac 2023-05-13)
binary: rustc
commit-hash: 2c41369acc445d04129db40ba998dd7a89fb0d2e
commit-date: 2023-05-13
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2
Compiler returned: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions