Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Dec 11, 2025

No description provided.

@jgarzik jgarzik requested a review from Copilot December 11, 2025 08:03
@jgarzik jgarzik self-assigned this Dec 11, 2025
@jgarzik jgarzik added the enhancement New feature or request label Dec 11, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements two-register struct returns for structs between 9-16 bytes in size, following the System V AMD64 ABI and AAPCS64 specifications. Previously, all structs larger than 8 bytes used the sret convention (hidden pointer parameter); now structs 9-16 bytes are returned efficiently in two general-purpose registers (RAX+RDX on x86-64, X0+X1 on AArch64).

Key Changes:

  • Increased max_aggregate_register_bits from 64 to 128 to enable two-register struct returns
  • Added is_two_reg_return flag to track instructions that use two-register returns
  • Implemented IR linearization logic to load 9-16 byte structs into two registers and emit return instructions with the new flag
  • Added architecture-specific codegen for both x86-64 and AArch64 to handle storing/loading two-register returns

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cc/target.rs Updated max_aggregate_register_bits from 64 to 128 bits and revised comments to reflect two-register return support
cc/ir/mod.rs Added is_two_reg_return field to Instruction struct to flag two-register struct returns
cc/ir/linearize.rs Implemented logic for detecting 9-16 byte struct returns, loading struct data into two temporaries, and emitting return/call instructions with the two-register flag
cc/arch/x86_64/codegen.rs Added x86-64 codegen for moving two-register returns (RAX+RDX) and storing them to stack locations
cc/arch/aarch64/codegen.rs Added AArch64 codegen for moving two-register returns (X0+X1) and storing them to stack locations
cc/tests/datatypes/struct_type.rs Added test cases for 16-byte structs (boundary case) and 24-byte structs (sret boundary)
cc/doc/C99.md Removed "Multi-Register Struct Returns" and "Array Parameter Qualifiers" sections since multi-register returns are now implemented
cc/README.md Removed "multi-register returns" from the list of unimplemented features

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jgarzik jgarzik merged commit b8280f4 into main Dec 11, 2025
4 checks passed
@jgarzik jgarzik deleted the updates branch December 11, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants