-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
match an std::cmp::Ordering generates less optimized code in nightly #86511
Copy link
Copy link
Open
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-bugCategory: This is a bug.Category: This is a bug.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-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.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Milestone
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-bugCategory: This is a bug.Category: This is a bug.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-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.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I'm interested in this comment:
rust/library/core/src/slice/mod.rs
Lines 2204 to 2217 in 3824017
So I did some testing:
The following code snippet is the "bad" one (
matchanstd::cmp::Ordering) in above comment, but withfmanually inlined.In version 1.53.0-beta.12 (2021-06-12 e7a67cc), release mode, it generates the following x86 assembly (related parts only):
(Which is identical to manually expanding to
if..else if..else, however it's not the point of this issue)In version 1.55.0-nightly (2021-06-20 e82b650), release mode, the generated assembly code is:
It's same as the "bad" result in original comment, and obviously much unoptimized.
I think
matchanOrderingshould be a quite common use case, so shouldn't be deoptimized.Version it worked on
Rust Playground: 1.53.0
Rust Playground: 1.53.0-beta.12 (2021-06-12 e7a67cc)
Version with regression
a55748f