-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Suboptimal debug codegen for integer division with a constant rhs #72751
Copy link
Copy link
Open
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Codegen for division in general needs to generate code to panic if the division will panic (e.g. divide by zero or integer overflow). In the case of constants, however, it looks like rustc almost optimizes debug codegen but not quite. For example this code:
generates this IR in debug mode:
It looks like rustc is "smart enough" to generate
%_5 = and i1 false, %_4, !dbg !14to realize the rhs is not negative one and it's not zero, but it's not quite smart enough to know thatfalse && xis alwaysfalse, so it still generates a branch to panic.