[Mips] Add -mips-split-hi16 for PS2 IOP modules #4

Merged
techwritescode merged 1 commit from ps2-iop-split-hi into r5900-ee 2026-10-12 04:45:33 +00:00

PS2 IOP modules built with LLVM were rejected by the boot ROM (error -201, ELF type 0xFF81). Cause: one lui shared by several accesses leaves more R_MIPS_LO16 than R_MIPS_HI16 relocations, which IRX1 cannot represent, so the fixup tool falls back to IRX2.

-mllvm -mips-split-hi16 (hidden, off by default):

  • MipsSplitHi16 (pre-RA): clone the %hi lui in front of every user. The clones carry an implicit $zero use so MachineLateInstrsCleanup does not merge them again.
  • MipsSinkHi16 (pre-emit): move each lui down to the instruction that reads it.
  • MipsELFObjectWriter::sortRelocs: pair each HI16 with the first following unclaimed LO16 of the same symbol and place it directly before it.

Tests: CodeGen/Mips/split-hi16.ll, split-hi16-reloc.ll. Verified end to end: usbd, bdm, bdmfs_fatfs, usbmass_bd, iomanx, filexio built with this load in PCSX2, and the std::filesystem example passes with 0 failures using them.

🤖 Generated with Claude Code

PS2 IOP modules built with LLVM were rejected by the boot ROM (error -201, ELF type 0xFF81). Cause: one lui shared by several accesses leaves more R_MIPS_LO16 than R_MIPS_HI16 relocations, which IRX1 cannot represent, so the fixup tool falls back to IRX2. `-mllvm -mips-split-hi16` (hidden, off by default): - MipsSplitHi16 (pre-RA): clone the %hi lui in front of every user. The clones carry an implicit $zero use so MachineLateInstrsCleanup does not merge them again. - MipsSinkHi16 (pre-emit): move each lui down to the instruction that reads it. - MipsELFObjectWriter::sortRelocs: pair each HI16 with the first following unclaimed LO16 of the same symbol and place it directly before it. Tests: CodeGen/Mips/split-hi16.ll, split-hi16-reloc.ll. Verified end to end: usbd, bdm, bdmfs_fatfs, usbmass_bd, iomanx, filexio built with this load in PCSX2, and the std::filesystem example passes with 0 failures using them. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
[Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16
Some checks failed
action.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (push) Failing after 0s
release-binaries-all.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (push) Failing after 0s
release-binaries.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (push) Failing after 0s
release-documentation.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (push) Failing after 0s
release-sources.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (push) Failing after 0s
Check for private emails used in PRs / validate_email (pull_request) Has been skipped
action.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (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] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (pull_request) Failing after 0s
release-binaries.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (pull_request) Failing after 0s
release-documentation.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (pull_request) Failing after 0s
release-sources.yml / [Mips] Add -mips-split-hi16: one lui per %hi use, HI16 right before its LO16 (pull_request) 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
619102f222
The PS2 IOP module format (IRX1) pairs each R_MIPS_HI16 with the single
R_MIPS_LO16 that follows it. Instruction selection shares one lui between
every access to the same symbol, and the ELF writer groups all HI16
relocations ahead of the LO16 ones, so such code cannot be turned into an
IRX1 module.

With the option, a pre-RA pass gives every user of a %hi lui its own copy,
a pre-emit pass moves each lui down to its user, and the ELF writer puts each
HI16 directly before its LO16.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
techwritescode deleted branch ps2-iop-split-hi 2026-10-12 04:45:34 +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!4
No description provided.