public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/113112] RISC-V: Dynamic LMUL feature stabilization for GCC-14 release
Date: Tue, 02 Jan 2024 00:23:39 +0000	[thread overview]
Message-ID: <bug-113112-4-JmdtkzneHf@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113112-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 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:9a29b00365a07745c4ba2ed2af374e7c732aaeb3

commit r14-6877-g9a29b00365a07745c4ba2ed2af374e7c732aaeb3
Author: Juzhe-Zhong <juzhe.zhong@rivai.ai>
Date:   Fri Dec 29 09:21:02 2023 +0800

    RISC-V: Count pointer type SSA into RVV regs liveness for dynamic LMUL cost
model

    This patch fixes the following choosing unexpected big LMUL which cause
register spillings.

    Before this patch, choosing LMUL = 4:

            addi    sp,sp,-160
            addiw   t1,a2,-1
            li      a5,7
            bleu    t1,a5,.L16
            vsetivli        zero,8,e64,m4,ta,ma
            vmv.v.x v4,a0
            vs4r.v  v4,0(sp)                        ---> spill to the stack.
            vmv.v.x v4,a1
            addi    a5,sp,64
            vs4r.v  v4,0(a5)                        ---> spill to the stack.

    The root cause is the following codes:

                      if (poly_int_tree_p (var)
                          || (is_gimple_val (var)
                             && !POINTER_TYPE_P (TREE_TYPE (var))))

    We count the variable as consuming a RVV reg group when it is not
POINTER_TYPE.

    It is right for load/store STMT for example:

    _1 = (MEM)*addr -->  addr won't be allocated an RVV vector group.

    However, we find it is not right for non-load/store STMT:

    _3 = _1 == x_8(D);

    _1 is pointer type too but we does allocate a RVV register group for it.

    So after this patch, we are choosing the perfect LMUL for the testcase in
this patch:

            ble     a2,zero,.L17
            addiw   a7,a2,-1
            li      a5,3
            bleu    a7,a5,.L15
            srliw   a5,a7,2
            slli    a6,a5,1
            add     a6,a6,a5
            lui     a5,%hi(replacements)
            addi    t1,a5,%lo(replacements)
            slli    a6,a6,5
            lui     t4,%hi(.LANCHOR0)
            lui     t3,%hi(.LANCHOR0+8)
            lui     a3,%hi(.LANCHOR0+16)
            lui     a4,%hi(.LC1)
            vsetivli        zero,4,e16,mf2,ta,ma
            addi    t4,t4,%lo(.LANCHOR0)
            addi    t3,t3,%lo(.LANCHOR0+8)
            addi    a3,a3,%lo(.LANCHOR0+16)
            addi    a4,a4,%lo(.LC1)
            add     a6,t1,a6
            addi    a5,a5,%lo(replacements)
            vle16.v v18,0(t4)
            vle16.v v17,0(t3)
            vle16.v v16,0(a3)
            vmsgeu.vi       v25,v18,4
            vadd.vi v24,v18,-4
            vmsgeu.vi       v23,v17,4
            vadd.vi v22,v17,-4
            vlm.v   v21,0(a4)
            vmsgeu.vi       v20,v16,4
            vadd.vi v19,v16,-4
            vsetvli zero,zero,e64,m2,ta,mu
            vmv.v.x v12,a0
            vmv.v.x v14,a1
    .L4:
            vlseg3e64.v     v6,(a5)
            vmseq.vv        v2,v6,v12
            vmseq.vv        v0,v8,v12
            vmsne.vv        v1,v8,v12
            vmand.mm        v1,v1,v2
            vmerge.vvm      v2,v8,v14,v0
            vmv1r.v v0,v1
            addi    a4,a5,24
            vmerge.vvm      v6,v6,v14,v0
            vmerge.vim      v2,v2,0,v0
            vrgatherei16.vv v4,v6,v18
            vmv1r.v v0,v25
            vrgatherei16.vv v4,v2,v24,v0.t
            vs1r.v  v4,0(a5)
            addi    a3,a5,48
            vmv1r.v v0,v21
            vmv2r.v v4,v2
            vcompress.vm    v4,v6,v0
            vs1r.v  v4,0(a4)
            vmv1r.v v0,v23
            addi    a4,a5,72
            vrgatherei16.vv v4,v6,v17
            vrgatherei16.vv v4,v2,v22,v0.t
            vs1r.v  v4,0(a3)
            vmv1r.v v0,v20
            vrgatherei16.vv v4,v6,v16
            addi    a5,a5,96
            vrgatherei16.vv v4,v2,v19,v0.t
            vs1r.v  v4,0(a4)
            bne     a6,a5,.L4

    No spillings, no "sp" register used.

    Tested on both RV32 and RV64, no regression.

    Ok for trunk ?

            PR target/113112

    gcc/ChangeLog:

            * config/riscv/riscv-vector-costs.cc (compute_nregs_for_mode): Fix
            pointer type liveness count.

    gcc/testsuite/ChangeLog:

            * gcc.dg/vect/costmodel/riscv/rvv/pr113112-4.c: New test.

  parent reply	other threads:[~2024-01-02  0:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22  9:04 [Bug c/113112] New: " juzhe.zhong at rivai dot ai
2023-12-23  0:59 ` [Bug target/113112] " cvs-commit at gcc dot gnu.org
2023-12-26  9:29 ` cvs-commit at gcc dot gnu.org
2023-12-27  9:19 ` cvs-commit at gcc dot gnu.org
2024-01-02  0:23 ` cvs-commit at gcc dot gnu.org [this message]
2024-01-03  9:21 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113112-4-JmdtkzneHf@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).