[Mips] Share the address of a global between repeated accesses on the R3000A (PS2-184) #9

Merged
techwritescode merged 2 commits from r3000a-shared-global-base into r5900-ee 2026-10-13 19:20:19 +00:00

Stacked on #8 (the diff against r5900-ee includes its commit until #8 merges).

IRX1 pairs every %hi with the %lo that follows it, so -mips-split-hi16 gives each access to a global its own lui. GCC builds the address once and reaches the members through register + offset. For code that touches a global's members many times that is two instructions per access against one.

A new shared-global-base subtarget feature, implied by r3000a only, makes the split pass share the address when a lui %hi(sym) feeds three or more plain %lo(sym+offset) users of the same global: one lui + addiu %lo(sym) (an adjacent HI16/LO16 pair that IRX1 accepts) and off($base) for every user. Two accesses cost the same either way and keep their own lui. Other CPUs are unchanged unless they request the feature. Test: CodeGen/Mips/r3000a-shared-global-base.ll.

Results (RiptOPL, all 47 IOP targets at -Oz; GCC at -Os): the 46 IRX files total 728,222 -> 684,894 bytes (-5.9%), GCC 650,850, so +11.9% -> +5.2% over GCC. At the default -Os the sdk-core audsrv IRX goes 21,271 -> 20,455 bytes. riptopl.elf 4,614,324 -> 4,579,624; packed 1,697,456 -> 1,689,488.

Tested

  • Mips CodeGen and MC lit suites: 1,516 passed, 23 expected failures, 0 failed.
  • sdk-core regression tests (8) and diff runs (15) in PCSX2 with the new compiler.
  • RiptOPL builds completely (892 steps) and all 46 IRX pass iopfixup --irx1.
  • On hardware (Deckard): iop-mmio, the sdsq/sdhd/reboot modules at -Os and -Oz, and audsrv.
  • Not tested: RiptOPL itself on hardware.

🤖 Generated with Claude Code

Stacked on #8 (the diff against `r5900-ee` includes its commit until #8 merges). IRX1 pairs every `%hi` with the `%lo` that follows it, so `-mips-split-hi16` gives each access to a global its own `lui`. GCC builds the address once and reaches the members through register + offset. For code that touches a global's members many times that is two instructions per access against one. A new `shared-global-base` subtarget feature, implied by `r3000a` only, makes the split pass share the address when a `lui %hi(sym)` feeds three or more plain `%lo(sym+offset)` users of the same global: one `lui` + `addiu %lo(sym)` (an adjacent HI16/LO16 pair that IRX1 accepts) and `off($base)` for every user. Two accesses cost the same either way and keep their own `lui`. Other CPUs are unchanged unless they request the feature. Test: `CodeGen/Mips/r3000a-shared-global-base.ll`. **Results** (RiptOPL, all 47 IOP targets at `-Oz`; GCC at `-Os`): the 46 IRX files total 728,222 -> 684,894 bytes (-5.9%), GCC 650,850, so +11.9% -> +5.2% over GCC. At the default `-Os` the sdk-core audsrv IRX goes 21,271 -> 20,455 bytes. `riptopl.elf` 4,614,324 -> 4,579,624; packed 1,697,456 -> 1,689,488. **Tested** - Mips CodeGen and MC lit suites: 1,516 passed, 23 expected failures, 0 failed. - sdk-core regression tests (8) and diff runs (15) in PCSX2 with the new compiler. - RiptOPL builds completely (892 steps) and all 46 IRX pass `iopfixup --irx1`. - On hardware (Deckard): iop-mmio, the sdsq/sdhd/reboot modules at `-Os` and `-Oz`, and audsrv. - Not tested: RiptOPL itself on hardware. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
[Mips] Share the address of a global between repeated accesses on the R3000A
Some checks failed
action.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (push) Failing after 0s
release-binaries-all.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (push) Failing after 0s
release-binaries.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (push) Failing after 0s
release-documentation.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (push) Failing after 0s
release-sources.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (push) Failing after 0s
Check for private emails used in PRs / validate_email (pull_request) Has been skipped
action.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (pull_request) Failing after 0s
Check LLVM ABI annotations / Check LLVM_ABI annotations with ids (pull_request) Has been skipped
CI Checks / Build and Test Linux (pull_request) Has been skipped
CI Checks / Build and Test Windows (pull_request) Has been skipped
CI Checks / Compute macOS Projects (pull_request) Has been skipped
CI Checks / Build and Test macOS arm64 (pull_request) Has been skipped
release-binaries-all.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (pull_request) Failing after 0s
release-binaries.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (pull_request) Failing after 0s
release-documentation.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (pull_request) Failing after 0s
release-sources.yml / [Mips] Share the address of a global between repeated accesses on the R3000A (pull_request) Failing after 0s
Labelling new pull requests / greeter (pull_request_target) Has been cancelled
Labelling new pull requests / automate-prs-labels (pull_request_target) Has been cancelled
ce021f9566
IRX1 pairs every %hi with the %lo that follows it, so -mips-split-hi16 gives each
access to a global its own lui. When a function reaches one global three or
more times through plain %lo(sym+offset) operands, build the address once with
an adjacent lui and addiu pair and reach the members through register +
offset, as GCC does. Add a shared-global-base subtarget feature, implied by
r3000a.
[Mips] Permit tail calls on the R3000A
Some checks failed
Check for private emails used in PRs / validate_email (pull_request) Has been skipped
action.yml / [Mips] Permit tail calls on the R3000A (pull_request) Failing after 0s
Check LLVM ABI annotations / Check LLVM_ABI annotations with ids (pull_request) Has been skipped
CI Checks / Build and Test Linux (pull_request) Has been skipped
CI Checks / Build and Test Windows (pull_request) Has been skipped
CI Checks / Compute macOS Projects (pull_request) Has been skipped
CI Checks / Build and Test macOS arm64 (pull_request) Has been skipped
release-binaries-all.yml / [Mips] Permit tail calls on the R3000A (pull_request) Failing after 0s
release-binaries.yml / [Mips] Permit tail calls on the R3000A (pull_request) Failing after 0s
release-documentation.yml / [Mips] Permit tail calls on the R3000A (pull_request) Failing after 0s
release-sources.yml / [Mips] Permit tail calls on the R3000A (pull_request) Failing after 0s
action.yml / [Mips] Permit tail calls on the R3000A (push) Failing after 0s
release-binaries-all.yml / [Mips] Permit tail calls on the R3000A (push) Failing after 0s
release-binaries.yml / [Mips] Permit tail calls on the R3000A (push) Failing after 0s
release-documentation.yml / [Mips] Permit tail calls on the R3000A (push) Failing after 0s
release-sources.yml / [Mips] Permit tail calls on the R3000A (push) Failing after 0s
Add buildbot information to first PRs from new contributors / buildbot_comment (pull_request_target) Has been skipped
Labelling new pull requests / greeter (pull_request_target) Has been cancelled
Labelling new pull requests / automate-prs-labels (pull_request_target) Has been cancelled
267389ace7
Tail calls are off by default in the MIPS backend because of $gp handling in
position independent code. Add a tail-calls subtarget feature, implied by
r3000a, that turns them on, and drop the requirement for a local callee when
the code has no SVR4 abicalls: without $gp there is nothing to restore. A caller
that ends in a call then needs neither a frame nor callee-saved registers to
hold its arguments across it. The mips-tail-calls option still overrides the
feature.
techwritescode changed target branch from r3000a-load-delay-fill to r5900-ee 2026-10-13 19:19:27 +00:00
techwritescode deleted branch r3000a-shared-global-base 2026-10-13 19:20:25 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ps2/llvm!9
No description provided.