Files
BFM-decomp/cookbook/C0401.md
T

1.1 KiB

§360 — THE "COMPILER FOUND A SHORTER EQUIVALENT THAN THE TARGET" PAIR (P31 S68; main/func_800241C0, 68 ins, 68 → 19)

Use when the TARGET is longer than your draft and its extra instructions look redundant: gcc found a shorter equivalent and you must spell the source so it cannot.

  1. $0 opaque-copy — write x + zr with register s32 zr __asm__("$0") to force a real addu $vN,$aN,$zero where gcc would fuse the copy into the next instruction. It also splits an i = arg2 into the target's two-step instead of gcc's one-instruction addiu fusion.
  2. Hoist the narrowing cast to its own statement — srem = (s16)rem; standalone, pinned to the same register as a non-overlapping-lifetime neighbour, reproduces the target's early rem-shift scheduling.

⚠ A third lever was tried here and is REFUTED — see §361. Duplicating i = i - 1; into both if/else arms to bait cross_jump appeared to work (it is part of how 68 → 19 was reached) and was in fact the cause of the residual that remained. It is recorded here only so nobody re-derives it.