Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cranelift: shrink ABIArgSlot #8163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jameysharp
Copy link
Contributor

ABIArgSlot is currently 16 bytes with 4 bytes of padding. Shrinking the offset field in its Stack variant from i64 to i32 therefore reduces the enum to 8 bytes. It also reduces its alignment to 4 bytes, which might reduce padding in containing structures.

Some targets already limit stack frame sizes to 2GB or less, and in practice they must be much smaller than that, so an i32 is plenty.

By making this type only one word in size, we can put two of them in ABIArgSlotVec for free, which guarantees that such SmallVecs will never spill to the heap. In principle we could use arrayvec or something that doesn't support spilling to the heap at all.

There are many other places where we use i64 for stack frame offsets which would probably benefit from switching to i32, but I didn't want to change everything at once.

ABIArgSlot is currently 16 bytes with 4 bytes of padding. Shrinking the
offset field in its Stack variant from i64 to i32 therefore reduces the
enum to 8 bytes. It also reduces its alignment to 4 bytes, which might
reduce padding in containing structures.

Some targets already limit stack frame sizes to 2GB or less, and in
practice they must be much smaller than that, so an i32 is plenty.

By making this type only one word in size, we can put two of them in
ABIArgSlotVec for free, which guarantees that such SmallVecs will never
spill to the heap. In principle we could use arrayvec or something that
doesn't support spilling to the heap at all.

There are many other places where we use i64 for stack frame offsets
which would probably benefit from switching to i32, but I didn't want to
change everything at once.
@jameysharp jameysharp requested a review from a team as a code owner March 18, 2024 08:17
@jameysharp jameysharp requested review from elliottt and removed request for a team March 18, 2024 08:17
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels Mar 18, 2024
@@ -320,7 +320,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
Some((ty, slot_offset))
})
.map(|(ty, offset)| ABIArgSlot::Stack {
offset,
offset: i32::try_from(offset).unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't currently check that the stack frame size is less than 2GB, so this unwrap can panic: #7916

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good to know! I'll hold off on merging this until I have a chance to think more about that or somebody else fixes it.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assuming we unblock it.

@elliottt elliottt removed their request for review May 6, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants