On Sat, Oct 17, 2026 at 01:50:08PM +0200, Julius Bairaktaris wrote:
> mips16_gp_pseudo_reg emits the $gp load in the topmost sequence before
> its first real insn. The scan skips CODE_LABELs, so the load can land
> in a later block, and since r16-1398 that block can be expanded but not
> BB_RTL yet, where add_insn_after crashes on BB_END.
>
> Emit the load and the clobbers after entry_of_function () instead, as
> other ports do. Before construct_init_block that is not usable, but
> everything after the first insn of the topmost sequence then becomes
> the init block, so emit after that insn. The current sequence does not
> work there: expand_phi_nodes can call this while emitting the copies
> for one PHI edge. The entry edge does not work either: pass_expand
> puts those insns after the parameter setup, which can itself use $gp.
>
> Assisted-by: Claude:claude-opus-5-5
>
> PR target/125582
>
> gcc/ChangeLog:
>
> * config/mips/mips.cc (mips16_gp_pseudo_reg): Emit the $gp load
> and the clobbers after entry_of_function (), or after the first
> insn before the init block exists.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/mips/pr125582.c: New test.
>
> Suggested-by: Jakub Jelinek <[email protected]>
> Signed-off-by: Julius Bairaktaris <[email protected]>
LGTM.
Jakub