https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128787

            Bug ID: 128787
           Summary: ICE on RISC-V with an FP register variable when the F
                    extension is disabled
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mumumu0722 at gmail dot com
  Target Milestone: ---

On RISC-V without the F extension (e.g. -march=rv64imac, or with Zfinx), GCC
ICEs with "maximum number of generated reload insns" when a local register
variable in fa0 is used as an inline asm operand.

float f(float a)
{
    register float x __asm__("fa0") = a;
    __asm__ volatile("" : "+r"(x));
    return x;
}

$ riscv64-linux-gnu-gcc --version
riscv64-linux-gnu-gcc (GCC) 17.0.0 20261115 (experimental)

$ riscv64-linux-gnu-gcc -march=rv64imac -mabi=lp64  test.c 
during RTL pass: reload
test.c: In function 'f':
test.c:6:1: internal compiler error: maximum number of generated reload insns
per insn achieved (90)
    6 | }
      | ^


Output of `-freport-bug`:
// Target: riscv64-linux-gnu
// Configured with: /src/gcc/configure --target=riscv64-linux-gnu
--prefix=/opt/cross --enable-languages=c --without-headers --disable-bootstrap
--disable-multilib --disable-nls --disable-werror --with-arch=rv64gc
--with-abi=lp64d
// Thread model: posix
// Supported LTO compression algorithms: zlib
// gcc version 17.0.0 20261115 (experimental) (GCC) 
// 
// during RTL pass: reload
// test.c: In function 'f':
// test.c:6:1: internal compiler error: maximum number of generated reload
insns per insn achieved (90)
//     6 | }
//       | ^
// 0x341b1ed internal_error(char const*, ...)
//      /src/gcc/gcc/diagnostic-global-context.cc:787
// 0x14b646d lra_constraints(bool)
//      /src/gcc/gcc/lra-constraints.cc:6194
// 0x1499fe3 lra(_IO_FILE*, int)
//      /src/gcc/gcc/lra.cc:2511
// 0x144e9d7 do_reload
//      /src/gcc/gcc/ira.cc:6098
// 0x144e9d7 execute
//      /src/gcc/gcc/ira.cc:6286
// -quiet test.c -quiet -dumpdir a- -dumpbase test.c -dumpbase-ext .c
-march=rv64imac -mabi=lp64 -misa-spec=20191213 -mtls-dialect=trad
-march=rv64imac_zmmul_zca -freport-bug -o - -frandom-seed=0 -fdump-noaddr
// Please submit a full bug report, with preprocessed source.
// Please include the complete backtrace with any bug report.
// See <https://gcc.gnu.org/bugs/> for instructions.

// /opt/cross/libexec/gcc/riscv64-linux-gnu/17.0.0/cc1 -quiet test.c -quiet
-dumpdir a- -dumpbase test.c -dumpbase-ext .c -march=rv64imac -mabi=lp64
-misa-spec=20191213 -mtls-dialect=trad -march=rv64imac_zmmul_zca -freport-bug
-o - -frandom-seed=0 -fdump-noaddr

# 0 "test.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "test.c"
float f(float a)
{
    register float x __asm__("fa0") = a;
    __asm__ volatile("" : "+r"(x));
    return x;
}


Expected: an error at the declaration, since there are no FP registers, e.g.
"register specified for 'x' isn't suitable for data type". With -march=rv64gc
the code compiles.

Compiler Explorer (GCC trunk): https://godbolt.org/z/T63sKvrjs

This bug is found by automated testing.

Reply via email to