Common branch folding for enum types fails when there are more than three enum variants. #121719
Labels
C-bug
Category: This is a bug.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-slow
Issue: Problems and improvements with respect to performance of generated code.
P-medium
Medium priority
regression-untriaged
Untriaged performance or correctness regression.
S-has-mcve
Status: A Minimal Complete and Verifiable Example has been found for this issue
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I tried this code:
https://godbolt.org/z/Yh7Px49jh
I expected to see this happen:
The
E::x
function gets optimized into a single add instruction since all the field has the same offsetInstead, this happened:
When the enum has four or more variants, the asm generated is
When the enum has three variants, the folding took effects but still generates strange stuff
When it has two variants, it finally produces idiomatic code
Interestingly, rustc will generate idiomatic code when:
y
is used to disrupt the layout.Meta
godbold rustc 1.76.0 with
-C opt-level=3 -C target-cpu=x86-64-v3
Edit: Tried more godbolt settings. This is a regression introduced sometime between rust 1.64 and rust 1.65.
The text was updated successfully, but these errors were encountered: