llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.96k forks source link

Crash compiling RISC-V Vector code #87897

Closed bscarlet closed 6 months ago

bscarlet commented 7 months ago
$ clang --version
clang version 19.0.0git (https://github.com/llvm/llvm-project.git fa8a7266724f26d27820f8876b504d7a4f166948)
...

Full stack dump. Top of stack dump:

 #0 0x000055c11459608b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3
 #1 0x000055c114593eb4 llvm::sys::RunSignalHandlers() /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #2 0x000055c114500638 HandleCrash /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #3 0x000055c114500638 CrashRecoverySignalHandler(int) /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:62
 #4 0x00007fab6bc5a510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
 #5 0x000055c113c1ab0f llvm::MCRegisterInfo::DiffListIterator::operator++() /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:216:24
 #6 0x000055c113c1ab0f llvm::MCSuperRegIterator::operator++() /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:588:24
 #7 0x000055c113c1ab0f llvm::MCSuperRegIterator::MCSuperRegIterator(llvm::MCRegister, llvm::MCRegisterInfo const*, bool) /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:581:10
 #8 0x000055c113c1ab0f llvm::MCRegisterInfo::superregs(llvm::MCRegister) const /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:793:20
 #9 0x000055c113c1ab0f llvm::MCRegisterInfo::isSuperRegister(llvm::MCRegister, llvm::MCRegister) const /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:599:32
#10 0x000055c113c1ab0f llvm::MCRegisterInfo::isSubRegister(llvm::MCRegister, llvm::MCRegister) const /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:457:27

Source, (manually simplified from code in google highway, also in attached tarball, along with bugpoint output):

#pragma clang riscv intrinsic vector

unsigned long out_of_line_vsetvl() { return __builtin_rvv_vsetvlimax(2, 7); }

template <class Unused>
__rvv_float32mf2_t function1(__rvv_float32mf2_t f0_vf0) {
  const unsigned f1_vl0 = __builtin_rvv_vsetvlimax(2, 7);

  const __rvv_float32mf2_t f1_vf1 = __riscv_vfsgnjx_vv_f32mf2(f0_vf0, f0_vf0, f1_vl0);
  const __rvv_uint32mf2_t f1_vu0 = __riscv_vreinterpret_v_f32mf2_u32mf2(f1_vf1);
  const __rvv_uint32mf2_t f1_vu1 = __riscv_vmv_v_x_u32mf2(0, f1_vl0);
  const __rvv_float32mf2_t f1_vf2 = __riscv_vreinterpret_v_u32mf2_f32mf2(f1_vu1);
  const __rvv_bool64_t f1_vb0 = __riscv_vmflt_vv_f32mf2_b64(f1_vf2, f0_vf0, f1_vl0);
  const __rvv_uint32mf2_t f1_vu2 = __riscv_vmv_v_x_u32mf2(1, f1_vl0);
  const __rvv_uint32mf2_t f1_vu3 = __riscv_vmv_v_x_u32mf2(2, f1_vl0);
  const __rvv_uint32mf2_t f1_vu4 = __riscv_vmerge_vvm_u32mf2(f1_vu2, f1_vu3, f1_vb0, f1_vl0);
  const __rvv_uint32mf2_t f1_vu5 = __riscv_vadd_vv_u32mf2(f1_vu0, f1_vu4, f1_vl0);
  const __rvv_float32mf2_t f1_vf3 = __riscv_vreinterpret_v_u32mf2_f32mf2(f1_vu5);
  const __rvv_float32mf2_t f1_vf4 = __riscv_vfmv_v_f_f32mf2(3, f1_vl0);
  const __rvv_uint32mf2_t f1_vu6 = __riscv_vmv_v_x_u32mf2(0x7f800000, f1_vl0);
  const __rvv_float32mf2_t f1_vf5 = __riscv_vreinterpret_v_u32mf2_f32mf2(f1_vu6);
  const __rvv_uint32mf2_t f1_vu7 = __riscv_vreinterpret_v_f32mf2_u32mf2(f1_vf3);
  const __rvv_uint32mf2_t f1_vu8 = __riscv_vadd_vv_u32mf2(f1_vu7, f1_vu7, f1_vl0);
  const __rvv_uint32mf2_t f1_vu9 = __riscv_vsrl_vx_u32mf2(f1_vu8, 24, f1_vl0);
  const __rvv_int32mf2_t f1_vi0 = __riscv_vreinterpret_v_u32mf2_i32mf2(f1_vu9);
  const unsigned vl1 = out_of_line_vsetvl();
  const __rvv_bool64_t f1_vb1 = __riscv_vmslt_vx_i32mf2_b64(f1_vi0, 0xff, vl1);
  const __rvv_float32mf2_t f1_vf6 = __riscv_vmerge_vvm_f32mf2(f1_vf5, f1_vf4, f1_vb0, f1_vl0);
  const __rvv_float32mf2_t f1_vf7 = __riscv_vmerge_vvm_f32mf2(f1_vf6, f1_vf3, f1_vb1, f1_vl0);
  return f1_vf7;
}

void function0(const unsigned num, float* buf) {
  const unsigned f0_vl0 = __builtin_rvv_vsetvlimax(2, 7);
  const __rvv_float32mf2_t f0_vf0 = __riscv_vfmv_v_f_f32mf2(*buf, f0_vl0);
  const __rvv_float32mf2_t f0_vf1 = __riscv_vle32_v_f32mf2(buf, f0_vl0);
  const __rvv_float32mf2_t f0_vf2 = __riscv_vfmv_v_f_f32mf2(*buf, f0_vl0);
  const __rvv_bool64_t f0_vb0 = __riscv_vmfeq_vv_f32mf2_b64(f0_vf1, f0_vf0, f0_vl0);
  const __rvv_bool64_t f0_vb1 = __riscv_vmnot_m_b64(f0_vb0, f0_vl0);
  const int f0_i0 = __riscv_vfirst_m_b64(f0_vb1, f0_vl0);
  const bool f0_b0 = f0_i0 < 0;
  if (__builtin_expect(f0_b0, 0)) function1<void>(f0_vf2);
  out_of_line_vsetvl();
}

llvm-rvv-crash-2024-04-06.tar.gz

bscarlet commented 7 months ago

bisection seems to indicate this problem was introduced in https://github.com/llvm/llvm-project/commit/29e8bfc13c6078ed07e6474e8c9634c42aa2f6f4

llvmbot commented 7 months ago

@llvm/issue-subscribers-backend-risc-v

Author: Benjamin S. Scarlet (bscarlet)

``` $ clang --version clang version 19.0.0git (https://github.com/llvm/llvm-project.git fa8a7266724f26d27820f8876b504d7a4f166948) ... ``` [Full stack dump](https://github.com/llvm/llvm-project/files/14895116/stack-dump.txt). Top of stack dump: ``` #0 0x000055c11459608b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3 #1 0x000055c114593eb4 llvm::sys::RunSignalHandlers() /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/Signals.cpp:105:20 #2 0x000055c114500638 HandleCrash /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5 #3 0x000055c114500638 CrashRecoverySignalHandler(int) /usr/local/google/home/bscarlet/src/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:62 #4 0x00007fab6bc5a510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510) #5 0x000055c113c1ab0f llvm::MCRegisterInfo::DiffListIterator::operator++() /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:216:24 #6 0x000055c113c1ab0f llvm::MCSuperRegIterator::operator++() /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:588:24 #7 0x000055c113c1ab0f llvm::MCSuperRegIterator::MCSuperRegIterator(llvm::MCRegister, llvm::MCRegisterInfo const*, bool) /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:581:10 #8 0x000055c113c1ab0f llvm::MCRegisterInfo::superregs(llvm::MCRegister) const /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:793:20 #9 0x000055c113c1ab0f llvm::MCRegisterInfo::isSuperRegister(llvm::MCRegister, llvm::MCRegister) const /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:599:32 #10 0x000055c113c1ab0f llvm::MCRegisterInfo::isSubRegister(llvm::MCRegister, llvm::MCRegister) const /usr/local/google/home/bscarlet/src/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:457:27 ``` Source, (manually simplified from code in google highway, also in attached tarball, along with bugpoint output): ```c++ #pragma clang riscv intrinsic vector unsigned long out_of_line_vsetvl() { return __builtin_rvv_vsetvlimax(2, 7); } template <class Unused> __rvv_float32mf2_t function1(__rvv_float32mf2_t f0_vf0) { const unsigned f1_vl0 = __builtin_rvv_vsetvlimax(2, 7); const __rvv_float32mf2_t f1_vf1 = __riscv_vfsgnjx_vv_f32mf2(f0_vf0, f0_vf0, f1_vl0); const __rvv_uint32mf2_t f1_vu0 = __riscv_vreinterpret_v_f32mf2_u32mf2(f1_vf1); const __rvv_uint32mf2_t f1_vu1 = __riscv_vmv_v_x_u32mf2(0, f1_vl0); const __rvv_float32mf2_t f1_vf2 = __riscv_vreinterpret_v_u32mf2_f32mf2(f1_vu1); const __rvv_bool64_t f1_vb0 = __riscv_vmflt_vv_f32mf2_b64(f1_vf2, f0_vf0, f1_vl0); const __rvv_uint32mf2_t f1_vu2 = __riscv_vmv_v_x_u32mf2(1, f1_vl0); const __rvv_uint32mf2_t f1_vu3 = __riscv_vmv_v_x_u32mf2(2, f1_vl0); const __rvv_uint32mf2_t f1_vu4 = __riscv_vmerge_vvm_u32mf2(f1_vu2, f1_vu3, f1_vb0, f1_vl0); const __rvv_uint32mf2_t f1_vu5 = __riscv_vadd_vv_u32mf2(f1_vu0, f1_vu4, f1_vl0); const __rvv_float32mf2_t f1_vf3 = __riscv_vreinterpret_v_u32mf2_f32mf2(f1_vu5); const __rvv_float32mf2_t f1_vf4 = __riscv_vfmv_v_f_f32mf2(3, f1_vl0); const __rvv_uint32mf2_t f1_vu6 = __riscv_vmv_v_x_u32mf2(0x7f800000, f1_vl0); const __rvv_float32mf2_t f1_vf5 = __riscv_vreinterpret_v_u32mf2_f32mf2(f1_vu6); const __rvv_uint32mf2_t f1_vu7 = __riscv_vreinterpret_v_f32mf2_u32mf2(f1_vf3); const __rvv_uint32mf2_t f1_vu8 = __riscv_vadd_vv_u32mf2(f1_vu7, f1_vu7, f1_vl0); const __rvv_uint32mf2_t f1_vu9 = __riscv_vsrl_vx_u32mf2(f1_vu8, 24, f1_vl0); const __rvv_int32mf2_t f1_vi0 = __riscv_vreinterpret_v_u32mf2_i32mf2(f1_vu9); const unsigned vl1 = out_of_line_vsetvl(); const __rvv_bool64_t f1_vb1 = __riscv_vmslt_vx_i32mf2_b64(f1_vi0, 0xff, vl1); const __rvv_float32mf2_t f1_vf6 = __riscv_vmerge_vvm_f32mf2(f1_vf5, f1_vf4, f1_vb0, f1_vl0); const __rvv_float32mf2_t f1_vf7 = __riscv_vmerge_vvm_f32mf2(f1_vf6, f1_vf3, f1_vb1, f1_vl0); return f1_vf7; } void function0(const unsigned num, float* buf) { const unsigned f0_vl0 = __builtin_rvv_vsetvlimax(2, 7); const __rvv_float32mf2_t f0_vf0 = __riscv_vfmv_v_f_f32mf2(*buf, f0_vl0); const __rvv_float32mf2_t f0_vf1 = __riscv_vle32_v_f32mf2(buf, f0_vl0); const __rvv_float32mf2_t f0_vf2 = __riscv_vfmv_v_f_f32mf2(*buf, f0_vl0); const __rvv_bool64_t f0_vb0 = __riscv_vmfeq_vv_f32mf2_b64(f0_vf1, f0_vf0, f0_vl0); const __rvv_bool64_t f0_vb1 = __riscv_vmnot_m_b64(f0_vb0, f0_vl0); const int f0_i0 = __riscv_vfirst_m_b64(f0_vb1, f0_vl0); const bool f0_b0 = f0_i0 < 0; if (__builtin_expect(f0_b0, 0)) function1<void>(f0_vf2); out_of_line_vsetvl(); } ``` [llvm-rvv-crash-2024-04-06.tar.gz](https://github.com/llvm/llvm-project/files/14894673/llvm-rvv-crash-2024-04-06.tar.gz)
dtcxzyw commented 7 months ago

cc @4vtomat @topperc

4vtomat commented 7 months ago

The issue is handled in this PR: 87736, thanks!