Niche-filling layouts are picked over tagged ones even when detrimental. #63866
Labels
A-layout
Area: Memory layout of types
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
This prints the values in comments:
Note that
Foo
contains strictly more opportunities for optimization, but it's optimized worse.That's because it uses a "niche-filling" layout (using
0
in theNonZeroU8
field ofA
forB
), but the "tag" layout wouldn't be any larger, because it has enough space in8
bytes to fit the (byte-sized) tag,NonZeroU8
andu32
.Bar
uses the tagged layout since it has no other choice, and ends up with254
free values in the byte-sized tag, butFoo
"jumps the gun" on using a pre-existing niche.The text was updated successfully, but these errors were encountered: