-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Suboptimal codegen when using unwrap_or_else with unreachable_unchecked #98468
Copy link
Copy link
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.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-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.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.
I tried this code:
I expected to see this happen: The
unwrap_or_elsecase generates branch-free assembly.Instead, this happened:
This was the generated assembly (opt-level 3):
Meta
Rust version rustc 1.61.0 (fe5b13d 2022-05-18) (on Compiler Explorer)
rustc --version --verbose:(not at my home machine right now, will fill in these details soon)
Context
The primary use case is to have an alternative version of
std::hint::unreachable_uncheckedthat is checked in debug builds viaunreachable!(), but unchecked in release builds.