public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113696] New: RISC-V: ineffective vsetvl behavior
@ 2024-02-01  1:48 pan2.li at intel dot com
  2024-02-19  8:20 ` [Bug c/113696] " cvs-commit at gcc dot gnu.org
  2024-02-19  8:23 ` pan2.li at intel dot com
  0 siblings, 2 replies; 3+ messages in thread
From: pan2.li at intel dot com @ 2024-02-01  1:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113696
           Summary: RISC-V: ineffective vsetvl behavior
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pan2.li at intel dot com
  Target Milestone: ---

Given we have a sample code, build with '-march=rv64gcv -O3 -g0'.


#include "riscv_vector.h"

void f (int32_t * restrict in, int32_t * restrict out, size_t n, size_t cond,
size_t cond2)
{
  for (size_t i = 0; i < n; i++)
    {
      if (i == cond) {
        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
        *(vint8mf8_t*)(out + i + 100) = v;
      } else if (i == cond2) {
        vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 200);
        *(vfloat32mf2_t*)(out + i + 200) = v;
      } else if (i == (cond2 - 1)) {
        vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 300);
        *(vuint16mf2_t*)(out + i + 300) = v;
      } else {
        vint8mf4_t v = *(vint8mf4_t*)(in + i + 400);
        *(vint8mf4_t*)(out + i + 400) = v;
      }
    }
}

when we have asm code as below, the vsetvl insn is somehow ineffective and can
be refined up to a point.

f:
.LFB0:
        .cfi_startproc
        beq     a2,zero,.L12
        addi    a7,a0,400
        addi    a6,a1,400
        addi    a0,a0,1600
        addi    a1,a1,1600
        li      a5,0
        addi    t6,a4,-1
        vsetvli t3,zero,e8,mf8,ta,ma
.L7:
        beq     a3,a5,.L15
        beq     a4,a5,.L16
        beq     t6,a5,.L17
        vsetvli t1,zero,e8,mf4,ta,ma
        vle8.v  v1,0(a0)
        vse8.v  v1,0(a1)
        vsetvli t3,zero,e8,mf8,ta,ma
.L4:
        addi    a5,a5,1
        addi    a7,a7,4
        addi    a6,a6,4
        addi    a0,a0,4
        addi    a1,a1,4
        bne     a2,a5,.L7
.L12:
        ret
.L15:
        vle8.v  v1,0(a7)
        vse8.v  v1,0(a6)
        j       .L4
.L17:
        vsetvli t1,zero,e8,mf4,ta,ma
        addi    t5,a0,-400
        addi    t4,a1,-400
        vle16.v v1,0(t5)
        vse16.v v1,0(t4)
        vsetvli t3,zero,e8,mf8,ta,ma
        j       .L4
.L16:
        addi    t5,a0,-800
        addi    t4,a1,-800
        vle32.v v1,0(t5)
        vse32.v v1,0(t4)
        j       .L4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/113696] RISC-V: ineffective vsetvl behavior
  2024-02-01  1:48 [Bug c/113696] New: RISC-V: ineffective vsetvl behavior pan2.li at intel dot com
@ 2024-02-19  8:20 ` cvs-commit at gcc dot gnu.org
  2024-02-19  8:23 ` pan2.li at intel dot com
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-19  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Pan Li <panli@gcc.gnu.org>:

https://gcc.gnu.org/g:6082024891e421bfd81d8f708a7411f4019d0d97

commit r14-9060-g6082024891e421bfd81d8f708a7411f4019d0d97
Author: Juzhe-Zhong <juzhe.zhong@rivai.ai>
Date:   Thu Feb 1 17:02:52 2024 +0800

    RISC-V: Suppress the vsetvl fusion for conflict successors

    Update in v2: Add dump information.

    This patch fixes the following ineffective vsetvl insertion:

    void f (int32_t * restrict in, int32_t * restrict out, size_t n, size_t
cond, size_t cond2)
    {
      for (size_t i = 0; i < n; i++)
        {
          if (i == cond) {
            vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
            *(vint8mf8_t*)(out + i + 100) = v;
          } else if (i == cond2) {
            vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 200);
            *(vfloat32mf2_t*)(out + i + 200) = v;
          } else if (i == (cond2 - 1)) {
            vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 300);
            *(vuint16mf2_t*)(out + i + 300) = v;
          } else {
            vint8mf4_t v = *(vint8mf4_t*)(in + i + 400);
            *(vint8mf4_t*)(out + i + 400) = v;
          }
        }
    }

    Before this patch:

    f:
    .LFB0:
            .cfi_startproc
            beq     a2,zero,.L12
            addi    a7,a0,400
            addi    a6,a1,400
            addi    a0,a0,1600
            addi    a1,a1,1600
            li      a5,0
            addi    t6,a4,-1
            vsetvli t3,zero,e8,mf8,ta,ma     ---> ineffective uplift
    .L7:
            beq     a3,a5,.L15
            beq     a4,a5,.L16
            beq     t6,a5,.L17
            vsetvli t1,zero,e8,mf4,ta,ma
            vle8.v  v1,0(a0)
            vse8.v  v1,0(a1)
            vsetvli t3,zero,e8,mf8,ta,ma
    .L4:
            addi    a5,a5,1
            addi    a7,a7,4
            addi    a6,a6,4
            addi    a0,a0,4
            addi    a1,a1,4
            bne     a2,a5,.L7
    .L12:
            ret
    .L15:
            vle8.v  v1,0(a7)
            vse8.v  v1,0(a6)
            j       .L4
    .L17:
            vsetvli t1,zero,e8,mf4,ta,ma
            addi    t5,a0,-400
            addi    t4,a1,-400
            vle16.v v1,0(t5)
            vse16.v v1,0(t4)
            vsetvli t3,zero,e8,mf8,ta,ma
            j       .L4
    .L16:
            addi    t5,a0,-800
            addi    t4,a1,-800
            vle32.v v1,0(t5)
            vse32.v v1,0(t4)
            j       .L4

    It's obvious that we are hoisting the e8mf8 vsetvl to the top. It's
ineffective since e8mf8 comes from
    low probability block which is if (i == cond).

    For this case, we disable such fusion.

    After this patch:

    f:
            beq     a2,zero,.L12
            addi    a7,a0,400
            addi    a6,a1,400
            addi    a0,a0,1600
            addi    a1,a1,1600
            li      a5,0
            addi    t6,a4,-1
    .L7:
            beq     a3,a5,.L15
            beq     a4,a5,.L16
            beq     t6,a5,.L17
            vsetvli t1,zero,e8,mf4,ta,ma
            vle8.v  v1,0(a0)
            vse8.v  v1,0(a1)
    .L4:
            addi    a5,a5,1
            addi    a7,a7,4
            addi    a6,a6,4
            addi    a0,a0,4
            addi    a1,a1,4
            bne     a2,a5,.L7
    .L12:
            ret
    .L15:
            vsetvli t3,zero,e8,mf8,ta,ma
            vle8.v  v1,0(a7)
            vse8.v  v1,0(a6)
            j       .L4
    .L17:
            addi    t5,a0,-400
            addi    t4,a1,-400
            vsetvli t1,zero,e8,mf4,ta,ma
            vle16.v v1,0(t5)
            vse16.v v1,0(t4)
            j       .L4
    .L16:
            addi    t5,a0,-800
            addi    t4,a1,-800
            vsetvli t3,zero,e32,mf2,ta,ma
            vle32.v v1,0(t5)
            vse32.v v1,0(t4)
            j       .L4

    Tested on both RV32/RV64 no regression. Ok for trunk ?

            PR target/113696

    gcc/ChangeLog:

            * config/riscv/riscv-vsetvl.cc
(pre_vsetvl::earliest_fuse_vsetvl_info):
            Suppress vsetvl fusion.

    gcc/testsuite/ChangeLog:

            * gcc.target/riscv/rvv/vsetvl/pr113696.c: New test.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/113696] RISC-V: ineffective vsetvl behavior
  2024-02-01  1:48 [Bug c/113696] New: RISC-V: ineffective vsetvl behavior pan2.li at intel dot com
  2024-02-19  8:20 ` [Bug c/113696] " cvs-commit at gcc dot gnu.org
@ 2024-02-19  8:23 ` pan2.li at intel dot com
  1 sibling, 0 replies; 3+ messages in thread
From: pan2.li at intel dot com @ 2024-02-19  8:23 UTC (permalink / raw)
  To: gcc-bugs

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

Li Pan <pan2.li at intel dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Li Pan <pan2.li at intel dot com> ---
Fixed.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-19  8:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01  1:48 [Bug c/113696] New: RISC-V: ineffective vsetvl behavior pan2.li at intel dot com
2024-02-19  8:20 ` [Bug c/113696] " cvs-commit at gcc dot gnu.org
2024-02-19  8:23 ` pan2.li at intel 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).