foss-for-synopsys-dwc-arc-processors/toolchain

truncdfhf2.c:52:1: internal compiler error: in as_a, at machmode.h:381

Opened this issue · 11 comments

On attempt to compile ARC GNU tools for ARC-V using GCC from https://github.com/foss-for-synopsys-dwc-arc-processors/gcc-arcv/commit/97a9f06441fd59c6f87803ded8410536495d145e got the following ICE.

Consider preprocessed input file truncdfhf2.zip and compile it in the following way:

.../riscv32-elf/build/build-cc-gcc-core/./gcc/xgcc -B.../riscv32-elf/build/build-cc-gcc-core/./gcc/ -g -mcmodel=medlow -O2 truncdfhf2.i -c

during RTL pass: vartrack
.../riscv32-elf/src/gcc/libgcc/soft-fp/truncdfhf2.c: In function '__truncdfhf2':
.../riscv32-elf/src/gcc/libgcc/soft-fp/truncdfhf2.c:52:1: internal compiler error: in as_a, at machmode.h:381
   52 | }
      | ^
0xa99b42 scalar_int_mode as_a<scalar_int_mode>(machine_mode)
        .../riscv32-elf/src/gcc/gcc/machmode.h:381
0xa9a05f scalar_int_mode as_a<scalar_int_mode>(machine_mode)
        .../riscv32-elf/src/gcc/gcc/rtl.h:3213
0xa9a05f num_sign_bit_copies1
        .../riscv32-elf/src/gcc/gcc/rtlanal.cc:5476
0x128543e num_sign_bit_copies1
        .../riscv32-elf/src/gcc/gcc/rtlanal.cc:5669
0x1285231 num_sign_bit_copies1
        .../riscv32-elf/src/gcc/gcc/rtlanal.cc:5527
0x12c99c8 simplify_const_relational_operation(rtx_code, machine_mode, rtx_def*, rtx_def*)
        .../riscv32-elf/src/gcc/gcc/simplify-rtx.cc:6380
0x12c386e simplify_context::simplify_relational_operation(rtx_code, machine_mode, machine_mode, rtx_def*, rtx_def*)
        .../riscv32-elf/src/gcc/gcc/simplify-rtx.cc:5830
0x12c2a24 simplify_relational_operation(rtx_code, machine_mode, machine_mode, rtx_def*, rtx_def*)
        .../riscv32-elf/src/gcc/gcc/rtl.h:3508
0x12c2a24 simplify_rtx(rtx_def const*)
        .../riscv32-elf/src/gcc/gcc/simplify-rtx.cc:7998
0xdffdc7 cselib_expand_value_rtx_1
        .../riscv32-elf/src/gcc/gcc/cselib.cc:2128
0xe0105e cselib_expand_value_rtx_cb(rtx_def*, bitmap_head*, int, rtx_def* (*)(rtx_def*, bitmap_head*, int, void*), void*)
        .../riscv32-elf/src/gcc/gcc/cselib.cc:1836
0x165df17 vt_expand_var_loc_chain
        .../riscv32-elf/src/gcc/gcc/var-tracking.cc:8403
0x165e4e8 vt_expand_loc_callback
        .../riscv32-elf/src/gcc/gcc/var-tracking.cc:8566
0xdfffb1 cselib_expand_value_rtx_1
        .../riscv32-elf/src/gcc/gcc/cselib.cc:1988
0xdffd61 cselib_expand_value_rtx_1
        .../riscv32-elf/src/gcc/gcc/cselib.cc:2026
0xe0105e cselib_expand_value_rtx_cb(rtx_def*, bitmap_head*, int, rtx_def* (*)(rtx_def*, bitmap_head*, int, void*), void*)
        .../riscv32-elf/src/gcc/gcc/cselib.cc:1836
0x165df17 vt_expand_var_loc_chain
        .../riscv32-elf/src/gcc/gcc/var-tracking.cc:8403
0x165e4e8 vt_expand_loc_callback
        .../riscv32-elf/src/gcc/gcc/var-tracking.cc:8566
0xdfffb1 cselib_expand_value_rtx_1
        .../riscv32-elf/src/gcc/gcc/cselib.cc:1988
0xe0105e cselib_expand_value_rtx_cb(rtx_def*, bitmap_head*, int, rtx_def* (*)(rtx_def*, bitmap_head*, int, void*), void*)
        .../riscv32-elf/src/gcc/gcc/cselib.cc:1836
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

For the record the following Crosstool-NG (taken from foss-for-synopsys-dwc-arc-processors/crosstool-ng@963a7fb commit) defconfig was used:

CT_CONFIG_VERSION="4"
CT_EXPERIMENTAL=y
CT_PREFIX_DIR="riscv32-unknown-elf"
# CT_LOG_PROGRESS_BAR is not set
CT_ARCH_RISCV=y
CT_ARCH_TUNE="rocket"
CT_OMIT_TARGET_VENDOR=y
CT_MULTILIB=y
CT_ARCH_ARCH="rv32imafd_zicond_zicsr_zifencei_zihintpause_zfa_zfh_zfhmin_zca_zcb_zcf_zcmp_zcmt_zba_zbb_zbc_zbs"
CT_ARCH_ABI="ilp32d"
CT_TARGET_CFLAGS="-Os -mcmodel=medlow"
# CT_SHOW_CT_VERSION is not set
CT_TOOLCHAIN_PKGVERSION="RISC-V elf toolchain - build 6596"
CT_TARGET_ALIAS="riscv32-elf"
CT_BINUTILS_SRC_DEVEL=y
CT_BINUTILS_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb"
CT_BINUTILS_DEVEL_REVISION="4183914f8d5307d6b0ffe6a47344e546fab3bdf1"
CT_NEWLIB_SRC_DEVEL=y
CT_NEWLIB_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/newlib"
CT_NEWLIB_DEVEL_REVISION="b6a8d03ce1c807ab8f369e819cc46edfe410cbd4"
CT_LIBC_NEWLIB_TARGET_CFLAGS="-O2 -D_POSIX_MODE -ffunction-sections -fdata-sections -Os -mcmodel=medlow"
CT_LIBC_NEWLIB_IO_C99FMT=y
CT_LIBC_NEWLIB_IO_LL=y
CT_LIBC_NEWLIB_IO_FLOAT=y
CT_LIBC_NEWLIB_IO_LDBL=y
CT_LIBC_NEWLIB_REGISTER_FINI=y
CT_GCC_SRC_DEVEL=y
CT_GCC_DEVEL_URL="git@github.com:foss-for-synopsys-dwc-arc-processors/gcc-arcv.git"
CT_GCC_DEVEL_REVISION="97a9f06441fd59c6f87803ded8410536495d145e"
CT_GCC_V_13=y
CT_CC_GCC_CONFIG_TLS=y
# CT_CC_GCC_USE_GRAPHITE is not set
# CT_CC_GCC_ENABLE_TARGET_OPTSPACE is not set
# CT_CC_GCC_TM_CLONE_REGISTRY is not set
CT_CC_LANG_CXX=y
CT_DEBUG_GDB=y
CT_GDB_SRC_DEVEL=y
CT_GDB_DEVEL_URL="https://sourceware.org/git/binutils-gdb.git"
CT_GDB_DEVEL_REVISION="e53a8e8685685c97588f8319d993ea6cd5635e47"
# CT_GDB_CROSS_PYTHON is not set
CT_COMP_LIBS_NEWLIB_NANO=y
CT_NEWLIB_NANO_SRC_DEVEL=y
CT_NEWLIB_NANO_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/newlib"
CT_NEWLIB_NANO_DEVEL_REVISION="b6a8d03ce1c807ab8f369e819cc46edfe410cbd4"
CT_LIBC_NEWLIB_NANO_TARGET_CFLAGS="-Os -ffunction-sections -fdata-sections -Os -mcmodel=medlow"
# CT_LIBC_NEWLIB_NANO_FVWRITE_IN_STREAMIO is not set
# CT_LIBC_NEWLIB_NANO_MULTITHREAD is not set

There's a similar issue in the GCC bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113637 with the corresponding fix https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=457d2b59b58e5998e1e6967316d4e3e8f24edeed. Which we apparently have in the sources I used for that experiment. So that must be something new.

Even easier reproduction with any recent GCC:

$ riscv64-elf-gcc -march=rv32imafd_zicsr_zifencei_zihintpause_zicond_zfa_zfh_zca_zcb_zcmt_zcmp_zcf_zba_zbb_zbc_zbs -mabi=ilp32d -O2 -g truncdfhf2.i

during RTL pass: vartrack
../../../libgcc/soft-fp/truncdfhf2.c: In function '__truncdfhf2':
../../../libgcc/soft-fp/truncdfhf2.c:52:1: internal compiler error: in as_a, at machmode.h:381
   52 | }
      | ^
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <https://gcc.gnu.org/bugs/> for instructions.

I cannot reproduce this on my end. what's the output of riscv64-elf-gcc -### ?

I cannot reproduce this on my end. what's the output of riscv64-elf-gcc -### ?

On my attempt to reproduce that problem bumped into a new thing related to how GCC 14.x-based toolchain got built, see #628.

Anyway, just to double-check, have you tried the following command on https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/files/15253048/truncdfhf2.zip?

$ riscv64-elf-gcc -march=rv32imafd_zicsr_zifencei_zihintpause_zicond_zfa_zfh_zca_zcb_zcmt_zcmp_zcf_zba_zbb_zbc_zbs -mabi=ilp32d -O2 -g truncdfhf2.i

Note that long -march string which really makes a difference.

still no output of that command for me

@abrodkin I tried the latest engineering build 2024.06-eng004 with this command. I changed imafd to imafc and ilp32d to ilp32f because it is not built with that imafd/ilp32d combination. I didn't face any issue. Note that the latest build uses GCC from https://github.com/foss-for-synopsys-dwc-arc-processors/gcc that is much newer than gcc-arcv.

riscv64-elf-gcc -march=rv32imafc_zicsr_zifencei_zihintpause_zicond_zfa_zfh_zca_zcb_zcmt_zcmp_zcf_zba_zbb_zbc_zbs -mabi=ilp32f -O2 -g -c truncdfhf2.i

Indeed, with GCC14 the the following happens with old command line:

$ riscv64-elf-gcc -march=rv32imafd_zicsr_zifencei_zihintpause_zicond_zfa_zfh_zca_zcb_zcmt_zcmp_zcf_zba_zbb_zbc_zbs -mabi=ilp32d -O2 -g truncdfhf2.i
riscv64-elf-gcc: fatal error: Cannot find suitable multilib set for '-march=rv32imafd_zicond_zicsr_zifencei_zihintpause_zfa_zfh_zfhmin_zca_zcb_zcf_zcmp_zcmt_zba_zbb_zbc_zbs'/'-mabi=ilp32d'
compilation terminated.

So the following needs to be used:

riscv64-elf-gcc -march=rv32imafc_zicsr_zifencei_zihintpause_zicond_zfa_zfh_zca_zcb_zcmt_zcmp_zcf_zba_zbb_zbc_zbs -mabi=ilp32f -O2 -g -c truncdfhf2.i

Though I could not reproduce the issue, I faced another one with this configuration:

CT_CONFIG_VERSION="4"
CT_EXPERIMENTAL=y
CT_PREFIX_DIR="riscv64-unknown-elf"
# CT_LOG_PROGRESS_BAR is not set
CT_ARCH_RISCV=y
CT_ARCH_TUNE="rocket"
CT_MULTILIB=y
CT_ARCH_64=y
CT_ARCH_ARCH="rv32imafd_zicsr_zifencei_zihintpause_zicond_zfa_zfh_zca_zcb_zcmt_zcmp_zcf_zba_zbb_zbc_zbs"
CT_ARCH_ABI="ilp32d"
CT_TARGET_CFLAGS="-Os"
# CT_SHOW_CT_VERSION is not set
CT_TOOLCHAIN_PKGVERSION="RISC-V elf toolchain - build 6838"
#CT_TARGET_VENDOR="snps"
CT_TARGET_ALIAS="riscv64-elf"
CT_BINUTILS_SRC_DEVEL=y
CT_BINUTILS_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb.git"
CT_BINUTILS_DEVEL_REVISION="a0ceb30a3a291b7226edd4e209a0f72542722907"
CT_NEWLIB_SRC_DEVEL=y
CT_NEWLIB_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/newlib.git"
CT_NEWLIB_DEVEL_REVISION="caed0fed9a76aab87f93b9e2f0257d3e5d7f8288"
CT_LIBC_NEWLIB_TARGET_CFLAGS="-O2 -D_POSIX_MODE -ffunction-sections -fdata-sections"
CT_LIBC_NEWLIB_IO_C99FMT=y
CT_LIBC_NEWLIB_IO_LL=y
CT_LIBC_NEWLIB_IO_FLOAT=y
CT_LIBC_NEWLIB_IO_LDBL=y
CT_LIBC_NEWLIB_REGISTER_FINI=y
CT_GCC_SRC_DEVEL=y
CT_GCC_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/gcc.git"
CT_GCC_DEVEL_REVISION="01fd9cd939ca8805369aa3a78d5fd6541f286438"
CT_GCC_V_13=y
CT_CC_GCC_MULTILIB_GENERATOR="rv32i-ilp32--;rv32iac-ilp32--;rv32im-ilp32--;rv32imac-ilp32--;rv32imafc-ilp32f--;rv64imac-lp64--;rv64imafdc-lp64d--;"
CT_CC_GCC_CONFIG_TLS=y
# CT_CC_GCC_USE_GRAPHITE is not set
# CT_CC_GCC_ENABLE_TARGET_OPTSPACE is not set
# CT_CC_GCC_TM_CLONE_REGISTRY is not set
CT_CC_LANG_CXX=y
CT_DEBUG_GDB=y
CT_GDB_SRC_DEVEL=y
CT_GDB_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb.git"
CT_GDB_DEVEL_REVISION="445de3297bb5e53c31e031d6bbd29377f81c06dd"
# CT_GDB_CROSS_PYTHON is not set
CT_COMP_LIBS_NEWLIB_NANO=y
CT_NEWLIB_NANO_SRC_DEVEL=y
CT_NEWLIB_NANO_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/newlib.git"
CT_NEWLIB_NANO_DEVEL_REVISION="caed0fed9a76aab87f93b9e2f0257d3e5d7f8288"
CT_LIBC_NEWLIB_NANO_TARGET_CFLAGS="-Os -ffunction-sections -fdata-sections"
# CT_LIBC_NEWLIB_NANO_FVWRITE_IN_STREAMIO is not set
# CT_LIBC_NEWLIB_NANO_MULTITHREAD is not set

To reproduce this file may be used (libm_a-er_lgamma.zip):

$ riscv64-unknown-elf-cc -fno-builtin -march=rv32id_zfa -mabi=ilp32  -mtune=rocket -c libm_a-er_lgamma.i -o libm_a-er_lgamma.o -Os -g
during RTL pass: vartrack
/home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/newlib/newlib/libm/math/er_lgamma.c: In function '__ieee754_lgamma_r':
/home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/newlib/newlib/libm/math/er_lgamma.c:319:1: internal compiler error: in simplify_const_unary_operation, at simplify-rtx.cc:2291
  319 | }
      | ^
0x9fb419 simplify_const_unary_operation(rtx_code, machine_mode, rtx_def*, machine_mode)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/simplify-rtx.cc:2291
0x1045d81 simplify_context::simplify_unary_operation(rtx_code, machine_mode, rtx_def*, machine_mode)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/simplify-rtx.cc:889
0x1045d81 simplify_context::simplify_gen_unary(rtx_code, machine_mode, rtx_def*, machine_mode)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/simplify-rtx.cc:360
0x10461a5 simplify_context::simplify_truncation(machine_mode, rtx_def*, machine_mode)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/simplify-rtx.cc:652
0x1044d70 simplify_context::simplify_unary_operation_1(rtx_code, machine_mode, rtx_def*)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/simplify-rtx.cc:1232
0x1041bb1 simplify_context::simplify_unary_operation(rtx_code, machine_mode, rtx_def*, machine_mode)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/simplify-rtx.cc:893
0x1041bb1 simplify_unary_operation(rtx_code, machine_mode, rtx_def*, machine_mode)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/rtl.h:3486
0x1041bb1 simplify_rtx(rtx_def const*)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/simplify-rtx.cc:7979
0xbe9eaf cselib_expand_value_rtx_1
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/cselib.cc:2128
0xbebad2 cselib_expand_value_rtx_cb(rtx_def*, bitmap_head*, int, rtx_def* (*)(rtx_def*, bitmap_head*, int, void*), void*)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/cselib.cc:1836
0x136b608 vt_expand_var_loc_chain
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/var-tracking.cc:8403
0x136c796 vt_expand_loc_callback
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/var-tracking.cc:8566
0xbea0ec cselib_expand_value_rtx_1
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/cselib.cc:1988
0xbe9e49 cselib_expand_value_rtx_1
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/cselib.cc:2026
0xbebad2 cselib_expand_value_rtx_cb(rtx_def*, bitmap_head*, int, rtx_def* (*)(rtx_def*, bitmap_head*, int, void*), void*)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/cselib.cc:1836
0x136b608 vt_expand_var_loc_chain
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/var-tracking.cc:8403
0x136c796 vt_expand_loc_callback
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/var-tracking.cc:8566
0xbea0ec cselib_expand_value_rtx_1
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/cselib.cc:1988
0xbebad2 cselib_expand_value_rtx_cb(rtx_def*, bitmap_head*, int, rtx_def* (*)(rtx_def*, bitmap_head*, int, void*), void*)
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/cselib.cc:1836
0x136b608 vt_expand_var_loc_chain
        /home/ykolerov/workspace/development/riscv/github-610/build/.build/riscv64-unknown-elf/src/gcc/gcc/var-tracking.cc:8403
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

If -g or _zfa is removed from options, this issue disappears. I will report this bug to GCC, but that means that RISC-V toolchain is not ready yet for building the a toolchain with complex combinations of extensions.

I marked this issue as related to non-Synopsys code. Moreover, this bug requires a further investigation that does not fit in this release. A temporary workaround is building a toolchain without complex configurations or try to find a configuration that leads to a successful building of a toolchain.

@kolerov that needs to go into known issues so that our users are aware of that. Also would be super nice to file an upstream bug for that.

@abrodkin I mentioned this issue as known in 2024.06 RC1 release notes.