https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128992
Bug ID: 128992
Summary: [sparc64] "insn does not satisfy its constraints"
(SFmode in %f32) for struct { float; _Complex float; }
passed in slot 15
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: lzy20000419 at outlook dot com
Target Milestone: ---
Target: sparc64-linux-gnu
Fails with a sparc64-linux-gnu cross trunk build (gcc 17.0.0 20261124,
537d251e84e6) and with every tested release from 12.2.0 to 16.2.0, so it is not
a regression.
Target: sparc64-linux-gnu.
struct S { float a; _Complex float c; };
void g (long, long, long, long, long, long, long, long,
long, long, long, long, long, long, long, struct S);
void
f (struct S *p)
{
g (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, *p);
}
sparc64-linux-gnu-gcc -O2 -c t.c
t.c: In function 'f':
t.c:10:1: error: insn does not satisfy its constraints:
(insn 31 30 32 2 (set (reg:SF 64 %f32)
(reg:SF 40 %f8 [...])) ... {*movsf_insn}
t.c:10:1: internal compiler error: in extract_constrain_insn, at
recog.cc:2856
Expected: successful compilation. Every -O level fails, and so does the callee
side.
Godbolt (16.2.0): https://godbolt.org/z/8161xEjb4
The 12-byte struct goes in slot 15, the last FP slot: a in %f30 and the real
part of c in %f31. The imaginary part is at offset 8, in slot 16, so it must go
on the stack. GCC puts it in %f32, where SFmode is not allowed. struct { float
a, b, c; } in the same position works; that is the PR69706 testcase.
Cause: compute_fp_layout (config/sparc/sparc.cc) computes the slots a field
needs as
nslots = CEIL_NWORDS (nregs * GET_MODE_SIZE (mode));
if (nslots > SPARC_FP_ARG_MAX - this_slotno)
and ignores the field's offset inside its first slot. A _Complex float at bit
position 32 needs 2 slots but is counted as 1, so the check passes at slot 15.
assign_fp_registers then starts at %f31 and gives %f32 to the imaginary part.
Possible fix: in compute_fp_layout, add the field's offset within its first
slot into the nslots and nregs calculations (CEIL_NWORDS (offset + nregs *
GET_MODE_SIZE (mode)), and subtract that offset when computing how many
registers still fit). With that change on trunk, the testcase and the
callee-side variant compile at -O0 through -Os, the imaginary part is passed on
the stack, and a runtime test of the caller and the callee, linked statically,
passes under qemu-sparc64 at -O0 through -Os. The PR69706 testcase still
compiles.
Related: PR69706.
Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.