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

            Bug ID: 123808
           Summary: gcc 16 miscompiles at -O2/3
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rvismith1115 at gmail dot com
  Target Milestone: ---

gcc 16 miscompiles at -O2/3

> riscv64-unknown-linux-gnu-g++ test.cpp -O2 -march=rv64gcv_zvfh -mabi=lp64d && 
> $QEMU a.out
86 86 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

> riscv64-unknown-linux-gnu-g++ test.cpp -O1 -march=rv64gcv_zvfh -mabi=lp64d && 
> $QEMU a.out
86 86 0 0 86 86 86 86 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

> (gcc-15) riscv64-unknown-linux-gnu-g++ test.cpp -O1 -march=rv64gcv_zvfh 
> -mabi=lp64d && $QEMU a.out
test.cpp: In function 'int main()':
test.cpp:26:31: error: invalid argument to built-in function
   26 |     __riscv_vle32ff_v_f32m4_mu(
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~^
   27 |         q, __riscv_vfmv_v_f_f32m4(0, __riscv_vsetvlmax_e8m1()), &j[n],
&o, o);
      |        
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Code: https://godbolt.org/z/cG97EzYcc

#include <riscv_vector.h>
#include <vector>
#define a 36
uint8_t e[a], x[a];
int64_t f[a], g[a], l[a];
float j[a], k[a], m[a];
int main() {
  for (int i = 0; i < a; ++i) { e[i]=1; g[i] = 86; x[i] = 86; }
  for (size_t n = 0, avl = a; avl;) {
    size_t o = __riscv_vsetvl_e64m8(avl);
    vuint8m1_t p = __riscv_vle8_v_u8m1(&e[n], o);
    vbool8_t q = __riscv_vmseq_vx_u8m1_b8(p, 1, o);
    vuint64m8_t r = __riscv_vsll_vx_u64m8(__riscv_vid_v_u64m8(o), 3, o);
    vint64m8_t s = __riscv_vluxei64_v_i64m8_tum(
        __riscv_vlm_v_b8(std::vector<uint8_t>(o + 7).data(), o),
        __riscv_vmv_v_x_i64m8(0, __riscv_vsetvlmax_e16m2()), &f[n], r, o);
    vuint32m4_t t = __riscv_vsll_vx_u32m4(__riscv_vid_v_u32m4(o), 3, o);
    vint64m8_t u = __riscv_vluxei32(&g[n], t, o);
    vbool8_t v = __riscv_vlm_v_b8(&x[n], o);
    __riscv_vle32ff_v_f32m4_mu(q, __riscv_vfmv_v_f_f32m4(0,
__riscv_vsetvlmax_e8m1()), &j[n], &o, o);
    vfloat32m1_t w = __riscv_vfmv_v_f_f32m1(0, __riscv_vsetvlmax_e32m1());
    vfloat32m1_t aa = __riscv_vle32_v_f32m1_tu(w, &k[n], o);
    s = __riscv_vcompress_vm_i64m8_tu(s, u, v, o);
    vfloat32mf2_t ab = __riscv_vlmul_trunc_v_f32m1_f32mf2(aa);
    vuint64m8_t ac = __riscv_vsll_vx_u64m8(__riscv_vid_v_u64m8(o), 3, o);
    __riscv_vsuxei64_v_i64m8(&l[n], ac, s, o);
    __riscv_vse32_v_f32mf2(&m[n], ab, o);
    avl -= o;
  }
  for (int i = 0; i < a; ++i) __builtin_printf("%ld ", l[i]);
  __builtin_printf("\n");
}

Reply via email to