-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
precondition_check functions can survive MonoReachable #131578
Copy link
Copy link
Open
Labels
A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-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
Labels
A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-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.
The motivating example is this: https://rust.godbolt.org/z/cYvn1bxWs, the IR of the function at the top which is
IndexRange as SliceIndex<[T]>>::get_unchecked_mutcontains a precondition check. The fact that the call is in a block without any predecessors does not make this unimportant, #121421 is not working here.The MIR for the function in question looks like this:
The MIR optimization pipeline has helpfully hoisted the assignment of
UbChecks()to a local then consulted that twice. But mono-reachable traversal only understands that the very specific pattern inbb0, and does not figure out thatbb3is also a switch on a constant that it could handle.Post-mono GVN is really the way out of this. We'd love to have
switchInt(const true)orswitchInt(const false)in the MIR. Codegen could figure that out easily. I'm going to see what it takes to paper another hack over this instead, on the off-chance that it is highly effective and easy to do.