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

            Bug ID: 128779
           Summary: ICE on big-endian targets for an asm with a "double"
                    output matched to a "long long" input
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mumumu0722 at gmail dot com
  Target Milestone: ---

On big-endian 32-bit targets (ARM -mbig-endian, PowerPC -m32, MIPS o32), GCC
ICEs with "unrecognizable insn" when a double output in a general register is
matched with a long long input. The same code compiles on the little-endian
variants of these targets.

double f(long long x)
{
    double r;
    __asm__("" : "=r"(r) : "0"(x));
    return r;
}

$ arm-linux-gnueabihf-gcc -mbig-endian -S test.c
test.c: In function 'f':
test.c:6:1: error: unrecognizable insn:
    6 | }
      | ^
(insn 8 21 22 2 (set (reg:DF 0 r0 [orig:96 r ] [96])
        (asm_operands:DF ("") ("=r") 0 [
                (reg:DI 0 r0 [orig:96 r ] [96])
            ]
             [
                (asm_input:DI ("0") test.c:4)
            ]
             [] test.c:4)) "test.c":4:5 -1
     (nil))
during RTL pass: reload
test.c:6:1: internal compiler error: in extract_constrain_insn, at
recog.cc:2856

Output of -freport-bug (GCC 13.3, arm-linux-gnueabihf-gcc-13 -mbig-endian
-freport-bug -S test.c):

// Target: arm-linux-gnueabihf
// Configured with: ../src/configure -v --with-pkgversion='Ubuntu
13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-13 --enable-shared
--enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace
--enable-gnu-unique-object --disable-libitm --disable-libquadmath
--disable-libquadmath-support --enable-plugin --enable-default-pie
--with-system-zlib --enable-libphobos-checking=release
--without-target-system-zlib --enable-multiarch --disable-sjlj-exceptions
--with-arch=armv7-a+fp --with-float=hard --with-mode=thumb --disable-werror
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf-
--includedir=/usr/arm-linux-gnueabihf/include
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
// Thread model: posix
// Supported LTO compression algorithms: zlib zstd
// gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) 
// 
// test.c: In function 'f':
// test.c:6:1: error: unrecognizable insn:
//     6 | }
//       | ^
// (insn 8 37 38 2 (set (reg:DF 0 r0 [orig:116 r ] [116])
//         (asm_operands:DF ("") ("=r") 0 [
//                 (reg:DI 0 r0 [orig:116 r ] [116])
//             ]
//              [
//                 (asm_input:DI ("0") test.c:4)
//             ]
//              [] test.c:4)) "test.c":4:5 -1
//      (nil))
// during RTL pass: mach
// test.c:6:1: internal compiler error: in extract_constrain_insn, at
recog.cc:2692
// 0x172609b internal_error(char const*, ...)
//      ???:0
// 0x6359e4 fancy_abort(char const*, int, char const*)
//      ???:0
// 0x61357d _fatal_insn(char const*, rtx_def const*, char const*, int, char
const*)
//      ???:0
// 0x61359f _fatal_insn_not_found(rtx_def const*, char const*, int, char
const*)
//      ???:0
// Please submit a full bug report, with preprocessed source.
// Please include the complete backtrace with any bug report.
// See <file:///usr/share/doc/gcc-13/README.Bugs> for instructions.

// /usr/libexec/gcc-cross/arm-linux-gnueabihf/13/cc1 -quiet -imultilib .
-imultiarch arm-linux-gnueabihf test.c -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64
-quiet -dumpbase test.c -dumpbase-ext .c -mbig-endian -mfloat-abi=hard
-mtls-dialect=gnu -mthumb -mlibarch=armv7-a+fp -march=armv7-a+fp -freport-bug
-o - -fstack-protector-strong -Wformat -Wformat-security -frandom-seed=0
-fdump-noaddr

# 0 "test.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/arm-linux-gnueabihf/include/stdc-predef.h" 1 3
# 0 "<command-line>" 2
# 1 "test.c"
double f(long long x)
{
    double r;
    __asm__("" : "=r"(r) : "0"(x));
    return r;
}

Expected: the code compiles, as it does with -mlittle-endian (both values are 8
bytes and fit in the same register pair), or a normal error if the operand
types are not allowed to match.

Also reproduced with GCC 17.0.0 20261110 (trunk) for arm-linux-gnueabihf with
-mbig-endian and for powerpc64-linux-gnu with -m32, MIPS GCC 16.1
(mips-linux-gnu, o32), and ARM GCC 16.1 (-mbig-endian).


Compiler Explorer (GCC trunk, ARM): https://godbolt.org/z/3d6KjfjMY

Reply via email to