public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114180] New: RISC-V: missing vsetvl changes tail policy and causes wrong codegen
@ 2024-02-29 23:44 camel-cdr at protonmail dot com
  0 siblings, 0 replies; only message in thread
From: camel-cdr at protonmail dot com @ 2024-02-29 23:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114180
           Summary: RISC-V: missing vsetvl changes tail policy and causes
                    wrong codegen
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: camel-cdr at protonmail dot com
  Target Milestone: ---

There is a codegen bug for RVV intrinsics in gcc 13.2.0, tested on native
hardware and cross-compilers.
It's fixed in on trunk, but I'm not sure how your policies on back-porting
fixes is.

I wasn't able to find an existing bug report that matches the bug, but I think
this patch might be the one that fixed it in trunk:
https://gcc.gnu.org/pipermail/gcc-patches/2024-January/643934.html

Reproduction:

$ cat test.c
#include <riscv_vector.h>

int validate_ascii(const char *buf, size_t len)  {
  size_t vlmax = __riscv_vsetvlmax_e8m8();
  vint8m8_t mask = __riscv_vmv_v_x_i8m8(0, vlmax);
  for (size_t vl; len > 0; len -= vl, buf += vl) {
    vl = __riscv_vsetvl_e8m8(len);
    vint8m8_t v = __riscv_vle8_v_i8m8((int8_t*)buf, vl);
    mask = __riscv_vor_vv_i8m8_tu(mask, mask, v, vl);
  }
  return __riscv_vfirst_m_b1(__riscv_vmslt_vx_i8m8_b1(mask, 0, vlmax), vlmax) <
0;
}
$ gcc-13 -march=rv64gcv -O2 -S test.c
$ cat test.s
validate_ascii:
        vsetvli a4,zero,e8,m8,ta,ma
        vmv.v.i v24,0
        beq     a1,zero,.L2
.L3:
        vsetvli a5,a1,e8,m8,ta,ma # <--- should be tu,ma
        sub     a1,a1,a5
        vle8.v  v8,0(a0)
        add     a0,a0,a5
        vor.vv  v24,v24,v8
        bne     a1,zero,.L3
        vsetvli a4,zero,e8,m8,ta,ma
.L2:
        vmslt.vi        v8,v24,0
        vfirst.m        a0,v8
        srli    a0,a0,63
        ret

(output slightly cleaned up, and annotated)

See also, for online reproduction: https://godbolt.org/z/jsbT4dErs

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-29 23:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 23:44 [Bug target/114180] New: RISC-V: missing vsetvl changes tail policy and causes wrong codegen camel-cdr at protonmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).