[llvm] [RISCV] RISCV vector calling convention (2/2) (PR #79096)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 11 04:16:25 PDT 2024


newgre wrote:

Hi,

this commit has been identified as the root cause for a compiler crash with the following reproducer:

```
#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();
}
```
`clang --target=riscv64-unknown-linux -march=rv64gcv -O1 -o repro.o -x c++ repro.c`

#87897 refers to the same root cause.

Could we revert this back to green as a remediation?

https://github.com/llvm/llvm-project/pull/79096


More information about the llvm-commits mailing list