public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kito Cheng <kito.cheng@sifive.com>
To: Juzhe-Zhong <juzhe.zhong@rivai.ai>
Cc: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com,
	jeffreyalaw@gmail.com,  rdapp.gcc@gmail.com
Subject: Re: [PATCH] RISC-V: Fix dynamic LMUL cost model ICE
Date: Thu, 9 Nov 2023 10:43:21 +0800	[thread overview]
Message-ID: <CALLt3TikQOtAS0hVASfvN98KdmzRYK_OzGUvGh0K8eZgYkYNCA@mail.gmail.com> (raw)
In-Reply-To: <20231109023917.3985192-1-juzhe.zhong@rivai.ai>

LGTM, thanks :)

On Thu, Nov 9, 2023 at 10:39 AM Juzhe-Zhong <juzhe.zhong@rivai.ai> wrote:
>
> When trying to use dynamic LMUL to compile benchmark.
> Notice there is a bunch ICEs.
>
> This patch fixes those ICEs and append tests.
>
> gcc/ChangeLog:
>
>         * config/riscv/riscv-vector-costs.cc (costs::preferred_new_lmul_p): Fix ICE.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c: New test.
>         * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c: New test.
>         * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c: New test.
>
> ---
>  gcc/config/riscv/riscv-vector-costs.cc        | 11 +++++---
>  .../costmodel/riscv/rvv/dynamic-lmul-ice-1.c  | 25 +++++++++++++++++++
>  .../costmodel/riscv/rvv/dynamic-lmul-ice-2.c  | 22 ++++++++++++++++
>  .../costmodel/riscv/rvv/dynamic-lmul-ice-3.c  | 14 +++++++++++
>  4 files changed, 69 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c
>  create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c
>  create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c
>
> diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc
> index af87388a1e4..8036c9c40d7 100644
> --- a/gcc/config/riscv/riscv-vector-costs.cc
> +++ b/gcc/config/riscv/riscv-vector-costs.cc
> @@ -231,7 +231,9 @@ compute_local_live_ranges (
>
>                      TODO: We may elide the cases that the unnecessary IMM in
>                      the future.  */
> -                 if (is_gimple_val (var) && !POINTER_TYPE_P (TREE_TYPE (var)))
> +                 if (poly_int_tree_p (var)
> +                     || (is_gimple_val (var)
> +                         && !POINTER_TYPE_P (TREE_TYPE (var))))
>                     {
>                       biggest_mode
>                         = get_biggest_mode (biggest_mode,
> @@ -416,7 +418,8 @@ static void
>  update_local_live_ranges (
>    vec_info *vinfo,
>    hash_map<basic_block, vec<stmt_point>> &program_points_per_bb,
> -  hash_map<basic_block, hash_map<tree, pair>> &live_ranges_per_bb)
> +  hash_map<basic_block, hash_map<tree, pair>> &live_ranges_per_bb,
> +  machine_mode *biggest_mode)
>  {
>    loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
>    if (!loop_vinfo)
> @@ -501,6 +504,8 @@ update_local_live_ranges (
>                            : get_store_value (gsi_stmt (si));
>               tree sel_type = build_nonstandard_integer_type (
>                 TYPE_PRECISION (TREE_TYPE (var)), 1);
> +             *biggest_mode
> +               = get_biggest_mode (*biggest_mode, TYPE_MODE (sel_type));
>               tree sel = build_decl (UNKNOWN_LOCATION, VAR_DECL,
>                                      get_identifier ("vect_perm"), sel_type);
>               pair &live_range = live_ranges->get_or_insert (sel, &existed_p);
> @@ -572,7 +577,7 @@ costs::preferred_new_lmul_p (const vector_costs *uncast_other) const
>
>    /* Update live ranges according to PHI.  */
>    update_local_live_ranges (other->m_vinfo, program_points_per_bb,
> -                           live_ranges_per_bb);
> +                           live_ranges_per_bb, &biggest_mode);
>
>    /* TODO: We calculate the maximum live vars base on current STMTS
>       sequence.  We can support live range shrink if it can give us
> diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c
> new file mode 100644
> index 00000000000..4f019ccae6b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c
> @@ -0,0 +1,25 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -O3 -ftree-vectorize --param riscv-autovec-lmul=dynamic" } */
> +
> +int a, *b[9], c, d, e;
> +
> +static int
> +fn1 ()
> +{
> +  for (c = 6; c >= 0; c--)
> +    for (d = 0; d < 2; d++)
> +      {
> +        b[d * 2 + c] = 0;
> +        e = a > 1 ? : 0;
> +        if (e == 2)
> +          return 0;
> +      }
> +  return 0;
> +}
> +
> +int
> +main ()
> +{
> +  fn1 ();
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c
> new file mode 100644
> index 00000000000..6fc8062f23b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c
> @@ -0,0 +1,22 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -Ofast -ftree-vectorize --param riscv-autovec-lmul=dynamic" } */
> +
> +typedef struct rtx_def *rtx;
> +struct replacement {
> +    rtx *where;
> +    rtx *subreg_loc;
> +    int mode;
> +};
> +static struct replacement replacements[150];
> +void move_replacements (rtx *x, rtx *y, int n_replacements)
> +{
> +  int i;
> +  for (i = 0; i < n_replacements; i++)
> +    if (replacements[i].subreg_loc == x)
> +      replacements[i].subreg_loc = y;
> +    else if (replacements[i].where == x)
> +      {
> +       replacements[i].where = y;
> +       replacements[i].subreg_loc = 0;
> +      }
> +}
> diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c
> new file mode 100644
> index 00000000000..c1f698b9a68
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -O2 -ftree-vectorize -flto -fno-use-linker-plugin -flto-partition=none --param riscv-autovec-lmul=dynamic" } */
> +
> +void (*foo[6][6]) (int);
> +void bar (hdR)
> +    int hdR;
> +{ }
> +void xxx ()
> +{
> +    unsigned int i, j;
> +    for (i = 0; i < 6; ++i)
> +       for (j = 0; j < 6; ++j)
> +            foo [i][j] = bar;
> +}
> --
> 2.36.3
>

  reply	other threads:[~2023-11-09  2:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09  2:39 Juzhe-Zhong
2023-11-09  2:43 ` Kito Cheng [this message]
2023-11-09  2:49   ` Li, Pan2

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=CALLt3TikQOtAS0hVASfvN98KdmzRYK_OzGUvGh0K8eZgYkYNCA@mail.gmail.com \
    --to=kito.cheng@sifive.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=juzhe.zhong@rivai.ai \
    --cc=kito.cheng@gmail.com \
    --cc=rdapp.gcc@gmail.com \
    /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).