Skip to content

[SOL] Implement hints of stack stores and loads #163

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

Merged
merged 1 commit into from
Jul 18, 2025

Conversation

LucasSte
Copy link
Collaborator

@LucasSte LucasSte commented Jul 17, 2025

Summary

LLVM has its internal passes InlineSpiller and StackSlotColoring, which determine the stack layout and possible spills. These passes use isStoreToStackSlot and isLoadFromStackSlot as hints, but they were not implemented.

Solution

Implement the two functions and their variants, and add a test.

Remarks

There is still a third variation of those functions isStoreToStackSlotPostFE and isLoadFromStackSlotPostFE (post PE means post frame pointer elimination). They follow a different logic and I left them out for another moment.

Benchmarks

This is a benchmark of the solana program entrypoint. There is one less CU for each account (the delta is based on the LLVM master branch):

Name CUs Delta
Account (0) 116 --
Account (1) 315 -1
Account (2) 479 -2
Account (3) 643 -3
Account (4) 807 -4
Account (5) 971 -5
Account (6) 1135 -6
Account (7) 1299 -7
Account (8) 1463 -8
Account (16) 2775 -16
Account (32) 5399 -32
Account (64) 10647 -64

This is Agave's printout of the assert_instruction_count function (again the diff is based on the LLVM master branch):

  SBF program                          expected actual  diff
  solana_sbf_rust_128bit                    786   786    +0 ( +0%)
  solana_sbf_rust_alloc                    4803  4803    +0 ( +0%)
  solana_sbf_rust_custom_heap               279   279    +0 ( +0%)
  solana_sbf_rust_dep_crate                   2     2    +0 ( +0%)
  solana_sbf_rust_iter                     1413  1413    +0 ( +0%)
  solana_sbf_rust_many_args                1281  1281    +0 ( +0%)
  solana_sbf_rust_mem                      1198  1198    +0 ( +0%)
  solana_sbf_rust_membuiltins               294   294    +0 ( +0%)
  solana_sbf_rust_noop                      309   308    -1 ( -0%)
  solana_sbf_rust_param_passing             108   108    +0 ( +0%)
  solana_sbf_rust_rand                      257   257    +0 ( +0%)
  solana_sbf_rust_sanity                  17101 17101    +0 ( +0%)
  solana_sbf_rust_secp256k1_recover       88988 88412  -576 ( -1%)
  solana_sbf_rust_sha                     22758 22163  -595 ( -3%)

@LucasSte LucasSte changed the title Implement hints of stack stores and loads [SOL] Implement hints of stack stores and loads Jul 17, 2025
@LucasSte LucasSte requested a review from Lichtso July 18, 2025 02:15
@LucasSte LucasSte marked this pull request as ready for review July 18, 2025 02:15
@LucasSte LucasSte merged commit faf354e into anza-xyz:solana-rustc/19.1-2024-12-03 Jul 18, 2025
17 checks passed
@LucasSte LucasSte deleted the mem-info branch July 18, 2025 14:01
LucasSte added a commit to LucasSte/llvm-project that referenced this pull request Aug 12, 2025
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