-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Suboptimal codegen for match from enum to almost-same-value usize (unnecessary table lookups) #136972
Copy link
Copy link
Open
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-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-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-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-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:
It gives (Compiler explorer):
I expect
convert_lento generate code likeconvert_len_optimal. No table lookup should be generated, especially not the first identity table. Though I don't expect performance to differ a lot when the cache is hot, but wasting cache on these trivial tables does not worth it.I'm not sure if LLVM or rustc is to blame here.
Meta
Reproduced on compiler Explorer's 1.84, latest nightly, and local nightly (
rustc 1.86.0-nightly (854f22563 2025-01-31))