Files
BFM-decomp/cookbook/C0470.md
T

1.1 KiB

§422 ★★ — QImode ARITHMETIC VIA (u8)(x - K), AND flag ^ 1 NEEDS ITS OWN TEMP (P31 S71; byte-proven resident/func_800D06E8, 344 ins)

1. A raw-$a0 addiu on a byte value comes from doing the arithmetic in QImode. mips.h defines no PROMOTE_MODE, so a u8 local really is QImode. Write the range test in QImode — (u8)(c - 3) < 2 — and widen_operand hands the subtraction a paradoxical subreg (the raw $a0), after which combine.c:9246's A - C1 vs C2 rule drops the truncation before the sltiu. Every earlier probe on this function used (u32)(c - 3), which re-widens and loses it. The cast is not cosmetic: it selects the mode the arithmetic happens in.

2. s1 = (cmp) ^ 1 puts the comparison in the DESTINATION pseudo. That is expand-time subtarget reuse, and it produces a $s1/$v0 pair the target does not have. Give the flag its own temp:

t  = (u32)(r - 0x64) < 0x1E;
s1 = t ^ 1;

Both are one-line respellings that no permuter reaches, because both change which RTL the expander builds rather than the order of anything.