2.2 KiB
§NNN — A DO-WHILE'S GUARD AND LATCH MUST REPEAT THE SAME BOUND EXPRESSION, NOT SHARE ONE LOCAL: THE REPETITION IS WHAT BUYS THE CSE'D COPY INTO A SECOND REGISTER (P31 S60; func_8017F2A4, ov_SC03_096, byte-proven 25/25)
Mechanism. For a do { ... } while (p < end) loop dominated by an entry guard
(if (p < end) { do {...} while (p < end); }), when BOTH occurrences of end are written as the
identical literal expression (base + K) rather than hoisted to a shared named local, cse commons the
two into ONE lui/addiu materialisation at the entry guard — but still emits a plain reg-reg COPY of
that value into a SECOND register for the latch test, because the register holding it at the guard
gets reused as scratch inside the loop body and is not live-range-safe to reuse directly at the
back-edge. A single shared local (s32 end = base + K; referenced at both sites) does not
reproduce this: it keeps one pseudo referenced directly at the latch with no extra copy — one
instruction shorter, and wrong.
Evidence. asm/ov_SC03_096/nonmatchings/ov_SC03_096_jr_8017BEBC/func_8017F2A4.s: entry —
addiu $v1,$a1,0x6480 ; sltu $v0,$a1,$v1 ; beqz $v0,.L8017F300; loop-prep —
addu $a2,$v1,$zero (the copy — $v1 gets reused inside the loop for lhu $v0,0($a1) /
lw $v1,0x20($a1)); latch — addiu $a1,$a1,0x10C ; sltu $v0,$a1,$a2 ; bnez $v0,.L8017F2C8. Banked
source, src/ov_SC03_096/ov_SC03_096_jr_8017BEBC.c:4560-4571, literally repeats
D_801202A0 + 0x6480 in both the if guard and the while condition — no shared local. 25/25 MATCH;
a shared-local rewrite measured one instruction short (24).
When it applies. Any do-while loop with an entry guard sharing a bound with its own back-edge
test, where the guard's bound register is reused for something else in the loop body. Tell: a
lone, otherwise-unexplained addu $rX,$rY,$zero (or OR-with-zero) between the guard's delay slot and
the loop label, copying the value the guard just tested — write the bound expression twice in source,
not once in a local.
(This candidate's harness-pitfall half — "a wrong-path first read poisons every later oracle verdict invisibly" — is COVERED by §238's existing "replayed previous attempt" / stale-shard tells; not repeated here.)