Package: gcc-16 Version: 16.2.0-3 Severity: normal X-Debbugs-Cc: [email protected]
The sh4 compiler crashes with an internal compiler error on valid C at -O2.
The cause appears to be the out-of-tree SH LRA support that Debian applies only
for sh4 (debian/patches/sh-lra-support.diff, which sets -mlra to Init(1)):
-mno-lra makes the crash disappear, and FSF releases/gcc-16 has -mlra off by
default.
Seen with the cross compiler from sid (gcc-16-sh4-linux-gnu 16.2.0-3cross1,
"Debian 16.2.0-3", Target: sh4-linux-gnu). I have no native sh4 machine, so I
have not tried the native compiler.
Reproducer (v3.c, valid C, compile only):
int idx0, idx1, frames;
float *gp;
void *alloc(int, int);
int convert(int, short, int, int, int *);
void f(void)
{
for (;;) {
float *input = alloc(frames, (int)*gp);
input[idx0] = 0.5f;
int output;
convert(idx1, 1, 4096, 4, &output);
}
}
$ sh4-linux-gnu-gcc -O2 -c v3.c -o /dev/null
v3.c: In function 'f':
v3.c:13:1: error: unable to find a register to spill
13 | }
| ^
v3.c:13:1: error: this is the insn:
(insn 22 72 25 4 (parallel [
(set (mem:SF (plus:SI (reg/f:SI 197 [ input ])
(reg:SI 206 [181])) [3 *_8+0 S4 A32])
(reg:SF 205))
(use (reg:SI 154 fpscr0))
(clobber (reg:SI 203))
]) "v3.c":9:21 222 {movsf_ie}
...
v3.c:13: confused by earlier errors, bailing out
Results (same compiler, same file):
-O2, -O3, -O2 -mlra ICE
-O2 -mno-lra compiles
-O0, -O1 compiles
No project options are needed; plain "sh4-linux-gnu-gcc -O2 -c" is enough, and
-Wall -Wextra gives no warnings. The reduction is fragile (renaming variables
makes it vanish), so it is sensitive to register pressure; the original file
below crashes at -O1, -O2, -O3 and -Os and compiles only at -O0 and -Og.
The original input is libfaar/tests/test_faar_quality.c from the
FreewareAdvancedAudio/faac project on GitHub (preprocessed, 4550 lines, with
the same ICE on the same insn pattern, movsf_ie) - attached as q.i.gz. It is a
float-heavy test program.
Not checked: whether FSF trunk (where LRA is permanent and movsf_ie_ra exists)
also crashes on this input, since I could not build trunk for sh4. If someone
can confirm that, the bug probably belongs upstream (cf. PR target/55212).
Separately, with the reload allocator I see sh4 test programs trap. On Ubuntu
GCC 13.3 and on this compiler with -mno-lra, I traced the fault to fldi1
executing with the PR bit of FPSCR set (double precision mode). Debian
trixie's GCC 14.2 also gets SIGILL, but I did not trace it. I can file that
separately if useful.
q.i.gz
Description: GNU Zip compressed data
v3.c
Description: Binary data

