https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127776
Bug ID: 127776
Summary: [14/15/16/17 Regression] [mips64] postreload
reload_cse_move2add deletes a constant load after an
insn that clobbers the register in a PARALLEL (*lea64
scratch), wrong code
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kaloz at dune dot hu
Target Milestone: ---
mips64-linux-gnuabi64 target with x86_64-linux-gnu host
Known to work (tested): 13.3.0, 13.4.0. Known to fail (tested): 14.1.0, 14.2.0,
14.3.0, 15.1.0, 15.2.0, 16.1.0.
Trunk (17.0.0, 2026-10-08): reload_cse_move2add is unchanged from 16.1.0 (not
run).
With -O2 -mabi=64 -mno-abicalls -fno-pic -march=r10000 the postreload move2add
pass deletes "return 0" (move $2,$0) although $2 was used as the scratch of a
64-bit symbol address load just before it. The function returns garbage instead
of 0.
Testcase:
__attribute__((noipa)) int f(void)
{
return 0;
}
__attribute__((noipa)) _Bool g(const char **w)
{
if (f() == 0) {
*w = "b";
return 0;
}
return 1;
}
int main(void)
{
const char *w;
return g(&w);
}
Command line:
$ mips64-linux-gnuabi64-gcc -O2 -mabi=64 -mno-abicalls -fno-pic -march=r10000
-static testcase.c
$ qemu-mips64 ./a.out; echo $?
mips64-linux-gnuabi64-gcc (Debian 14.2.0-13) 14.2.0 : exit status 184, expected
0
mips64-linux-gnuabi64-gcc-13 (Debian 13.3.0-12) 13.3.0 : exit status 0
Regression from r14-1526-g3991b2f623d2 ("reload_cse_move2add: Handle
trivial single_set:s"), which let PARALLELs into those paths. The fix for
PR101188 added the invalidation only to the REG + REG path; the SYMBOL_REF
and CONST_INT paths still skip it.
-fdbg-cnt=cse2_move2add:0 avoids it. Whether it triggers depends on register
allocation: -march=mips4/r10000-r16000 at -O2/-O3 fail, -march=mips64r2, -O1,
-Os and -msym32 pass.