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

            Bug ID: 116593
           Summary: internal compiler error: in get_attr_type, at
                    config/riscv/riscv.md:28048 with -O2 -O3 when
                    compiling for risc-v xtheadvector
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shuizhuyuanluo at gmail dot com
  Target Milestone: ---

-O1 compiles fine
-O2 -O3 gives compiler internal error as follows


$ ./riscv64-unknown-linux-gnu-g++ -c test3.cpp -o test3.o
-march=rv64gc_zfh_xtheadvector -O2
test3.cpp: In function 'void atan2(const float*, const float*, float*, int,
int)':
test3.cpp:41:1: error: unrecognizable insn:
   41 | }
      | ^
(insn 415 284 70 17 (parallel [
            (set (reg:SI 66 vl)
                (unspec:SI [
                        (const_int 1 [0x1])
                        (const_int 32 [0x20])
                        (const_int 3 [0x3])
                    ] UNSPEC_VSETVL))
            (set (reg:SI 67 vtype)
                (unspec:SI [
                        (const_int 32 [0x20])
                        (const_int 3 [0x3])
                        (const_int 1 [0x1]) repeated x2
                    ] UNSPEC_VSETVL))
        ]) "test3.cpp":10:26 discrim 1 -1
     (nil))
during RTL pass: sched2
test3.cpp:41:1: internal compiler error: in get_attr_type, at
config/riscv/riscv.md:28048
0x3248645 internal_error(char const*, ...)
        ../.././gcc/gcc/diagnostic-global-context.cc:492
0xe28c92 fancy_abort(char const*, int, char const*)
        ../.././gcc/gcc/diagnostic.cc:1658
0xc01cdf _fatal_insn(char const*, rtx_def const*, char const*, int, char
const*)
        ../.././gcc/gcc/rtl-error.cc:108
0xc01d01 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
        ../.././gcc/gcc/rtl-error.cc:116
0xda5128 get_attr_type(rtx_insn*)
        ../.././gcc/gcc/config/riscv/riscv.md:28048
0x1bcbd5e riscv_sched_variable_issue
        ../.././gcc/gcc/config/riscv/riscv.cc:9356
0x2c33ff3 schedule_block(basic_block_def**, void*)
        ../.././gcc/gcc/haifa-sched.cc:6912
0x172fbc4 schedule_region
        ../.././gcc/gcc/sched-rgn.cc:3203
0x172fbc4 schedule_insns()
        ../.././gcc/gcc/sched-rgn.cc:3525
0x172ffe1 schedule_insns()
        ../.././gcc/gcc/sched-rgn.cc:3511
0x172ffe1 rest_of_handle_sched2
        ../.././gcc/gcc/sched-rgn.cc:3749
0x172ffe1 execute
        ../.././gcc/gcc/sched-rgn.cc:3888
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.
*/






$ ./riscv64-unknown-linux-gnu-g++ -v
Using built-in specs.
COLLECT_GCC=./riscv64-unknown-linux-gnu-g++
COLLECT_LTO_WRAPPER=/data/action/osd/riscv/libexec/gcc/riscv64-unknown-linux-gnu/15.0.0/lto-wrapper
Target: riscv64-unknown-linux-gnu
Configured with: /data/action/osd/riscv-gnu-toolchain/gcc/configure
--target=riscv64-unknown-linux-gnu --prefix=/data/action/osd/riscv
--with-sysroot=/data/action/osd/riscv/sysroot --with-pkgversion=g155da081706
--with-system-zlib --enable-shared --enable-tls
--enable-languages=c,c++,fortran --disable-libmudflap --disable-libssp
--disable-libquadmath --disable-libsanitizer --disable-nls --disable-bootstrap
--src=.././gcc --disable-default-pie --disable-multilib --with-abi=lp64d
--with-arch=rv64imafdc --with-tune=rocket --with-isa-spec=20191213
'CFLAGS_FOR_TARGET=-O2    -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-O2   
-mcmodel=medlow'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240829 (experimental) (g155da081706) 



binutils master branch

commit 5cca20f614694ba6af3c10ca5bb93c32cdb9522b (HEAD -> master, origin/master,
origin/HEAD)
Author: GDB Administrator <gdbad...@sourceware.org>
Date:   Thu Aug 29 00:00:14 2024 +0000

    Automatic date update in version.in



------------- soucecode -------------


#include <math.h>
#include <riscv_vector.h>

#include <vector>

static vfloat32m8_t atan2_ps(vfloat32m8_t a, vfloat32m8_t b, size_t vl)
{
    std::vector<float> tmpx(vl);
    std::vector<float> tmpy(vl);
    __riscv_vse32_v_f32m8(tmpx.data(), a, vl);
    __riscv_vse32_v_f32m8(tmpy.data(), b, vl);
    for (size_t i = 0; i < vl; i++)
    {
        tmpx[i] = atan2(tmpx[i], tmpy[i]);
    }
    return __riscv_vle32_v_f32m8(tmpx.data(), vl);
}

void atan2(const float* x, const float* y, float* out, int size, int ch)
{
    for (int i = 0; i < ch; i++)
    {
        const float* xx = x + size * i;
        const float* yy = y + size * i;
        float* zz = out + size * i;

        int n = size;
        while (n > 0)
        {
            size_t vl = __riscv_vsetvl_e32m8(n);
            vfloat32m8_t _xx = __riscv_vle32_v_f32m8(xx, vl);
            vfloat32m8_t _yy = __riscv_vle32_v_f32m8(yy, vl);
            vfloat32m8_t _zz = atan2_ps(_xx, _yy, vl);
            __riscv_vse32_v_f32m8(zz, _zz, vl);
            n -= vl;
            xx += vl;
            yy += vl;
            zz += vl;
        }
    }
}

Reply via email to