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

[SOL] Correctly copy 16-byte aligned memory #97

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

LucasSte
Copy link
Collaborator

Problem

When compiling a Rust struct marked with #[repr(C, align(16)], we force a 16-byte alignment for it and all the necessary copies. The compiler wasn't handling this case correctly and would panic if we try to call memcpy with 16-byte aligned memory.

Changes

The actual problem lies in SBFSelectionDAGInfo.cpp, which was not estimating the number of loads and stores correctly. It was using the alignment, not the number of bytes per operation, for the estimation. This has been fixed.

Although not used in production, the backend has an option -sbf-expand-memcpy-in-order to expand loads and stores with increasing offsets. The function that does so wasn't handling 16-byte aligned memory and was emitting inefficient code (more loads and stores than necessary). This problem has also been fixed.

There are tests for these two fixes included in this PR.

@LucasSte LucasSte marked this pull request as draft June 19, 2024 17:32
@LucasSte LucasSte requested a review from dmakarov June 19, 2024 20:42
@LucasSte LucasSte marked this pull request as ready for review June 19, 2024 20:42
@LucasSte LucasSte changed the title [SOL] Correctly load 16-byte aligned memory [SOL] Correctly copy 16-byte aligned memory Jun 20, 2024
@LucasSte LucasSte merged commit 7d055ed into anza-xyz:solana-rustc/17.0-2023-12-14 Jun 20, 2024
13 checks passed
@LucasSte LucasSte deleted the memcpy-16 branch June 20, 2024 19:00
LucasSte added a commit to LucasSte/llvm-project that referenced this pull request Jun 29, 2024
* Fix issue with copying 16-byte aligned memory
LucasSte added a commit that referenced this pull request Aug 19, 2024
* Fix issue with copying 16-byte aligned memory
LucasSte added a commit to LucasSte/llvm-project that referenced this pull request Feb 12, 2025
* Fix issue with copying 16-byte aligned memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants