public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH V2] GIMPLE_FOLD: Fix gimple fold for LEN_{MASK}_{LOAD,STORE}
@ 2023-06-26  8:11 juzhe.zhong
  2023-06-26  8:17 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: juzhe.zhong @ 2023-06-26  8:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.sandiford, rguenther, Ju-Zhe Zhong

From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>

Hi, previous I made a mistake on GIMPLE_FOLD of LEN_MASK_{LOAD,STORE}.

We should fold LEN_MASK_{LOAD,STORE} (bias+len) == vf (nunits instead of bytesize) && mask = all trues mask

into:
   MEM_REF [...].

This patch added testcase to test gimple fold of LEN_MASK_{LOAD,STORE}.

Also, I fix LEN_LOAD/LEN_STORE, to make them have the same behavior.

Ok for trunk ?

gcc/ChangeLog:

        * gimple-fold.cc (gimple_fold_partial_load_store_mem_ref): Fix gimple fold of LOAD/STORE with length.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c: New test.

---
 gcc/gimple-fold.cc                            |  6 ++-
 .../riscv/rvv/autovec/partial/gimple_fold-1.c | 43 +++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3d46b76edeb..6d167b116b9 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -5397,8 +5397,10 @@ gimple_fold_partial_load_store_mem_ref (gcall *call, tree vectype, bool mask_p)
       unsigned int nargs = gimple_call_num_args (call);
       tree bias = gimple_call_arg (call, nargs - 1);
       gcc_assert (TREE_CODE (bias) == INTEGER_CST);
-      if (maybe_ne (wi::to_poly_widest (basic_len) - wi::to_widest (bias),
-		    GET_MODE_SIZE (TYPE_MODE (vectype))))
+      /* For LEN_LOAD/LEN_STORE/LEN_MASK_LOAD/LEN_MASK_STORE,
+	 we don't fold when (bias + len) != VF.  */
+      if (maybe_ne (wi::to_poly_widest (basic_len) + wi::to_widest (bias),
+		    GET_MODE_NUNITS (TYPE_MODE (vectype))))
 	return NULL_TREE;
 
       /* For LEN_MASK_{LOAD,STORE}, we should also check whether
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
new file mode 100644
index 00000000000..23407a2d3f4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32d --param riscv-autovec-preference=fixed-vlmax --param riscv-autovec-lmul=m8 -O3 -fdump-tree-optimized-details" } */
+
+#include <stdint-gcc.h>
+
+#define SZ 255
+
+#define DEF(TYPE) void fn_##TYPE (TYPE *__restrict a);
+
+#define RUN(TYPE)                                                              \
+  TYPE a##TYPE[SZ];                                                            \
+  for (int i = 0; i < SZ; i++)                                                 \
+    {                                                                          \
+      a##TYPE[i] = 127;                                                        \
+    }                                                                          \
+  fn_##TYPE (a##TYPE);
+
+#define RUN_ALL()                                                              \
+  RUN (int8_t)                                                                 \
+  RUN (int16_t)                                                                \
+  RUN (int32_t)                                                                \
+  RUN (int64_t)                                                                \
+  RUN (uint8_t)                                                                \
+  RUN (uint16_t)                                                               \
+  RUN (uint32_t)                                                               \
+  RUN (uint64_t)
+
+DEF (int8_t)
+DEF (int16_t)
+DEF (int32_t)
+DEF (int64_t)
+DEF (uint8_t)
+DEF (uint16_t)
+DEF (uint32_t)
+DEF (uint64_t)
+
+int
+main ()
+{
+  RUN_ALL ()
+}
+
+/* { dg-final { scan-tree-dump-times "\.LEN_MASK_STORE" 6 "optimized" } } */
-- 
2.36.3


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

* Re: [PATCH V2] GIMPLE_FOLD: Fix gimple fold for LEN_{MASK}_{LOAD,STORE}
  2023-06-26  8:11 [PATCH V2] GIMPLE_FOLD: Fix gimple fold for LEN_{MASK}_{LOAD,STORE} juzhe.zhong
@ 2023-06-26  8:17 ` Richard Biener
  2023-06-26 14:07   ` Li, Pan2
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-06-26  8:17 UTC (permalink / raw)
  To: Ju-Zhe Zhong; +Cc: gcc-patches, richard.sandiford

On Mon, 26 Jun 2023, juzhe.zhong@rivai.ai wrote:

> From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
> 
> Hi, previous I made a mistake on GIMPLE_FOLD of LEN_MASK_{LOAD,STORE}.
> 
> We should fold LEN_MASK_{LOAD,STORE} (bias+len) == vf (nunits instead of bytesize) && mask = all trues mask
> 
> into:
>    MEM_REF [...].
> 
> This patch added testcase to test gimple fold of LEN_MASK_{LOAD,STORE}.
> 
> Also, I fix LEN_LOAD/LEN_STORE, to make them have the same behavior.
> 
> Ok for trunk ?

OK

> gcc/ChangeLog:
> 
>         * gimple-fold.cc (gimple_fold_partial_load_store_mem_ref): Fix gimple fold of LOAD/STORE with length.
> 
> gcc/testsuite/ChangeLog:
> 
>         * gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c: New test.
> 
> ---
>  gcc/gimple-fold.cc                            |  6 ++-
>  .../riscv/rvv/autovec/partial/gimple_fold-1.c | 43 +++++++++++++++++++
>  2 files changed, 47 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
> 
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index 3d46b76edeb..6d167b116b9 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -5397,8 +5397,10 @@ gimple_fold_partial_load_store_mem_ref (gcall *call, tree vectype, bool mask_p)
>        unsigned int nargs = gimple_call_num_args (call);
>        tree bias = gimple_call_arg (call, nargs - 1);
>        gcc_assert (TREE_CODE (bias) == INTEGER_CST);
> -      if (maybe_ne (wi::to_poly_widest (basic_len) - wi::to_widest (bias),
> -		    GET_MODE_SIZE (TYPE_MODE (vectype))))
> +      /* For LEN_LOAD/LEN_STORE/LEN_MASK_LOAD/LEN_MASK_STORE,
> +	 we don't fold when (bias + len) != VF.  */
> +      if (maybe_ne (wi::to_poly_widest (basic_len) + wi::to_widest (bias),
> +		    GET_MODE_NUNITS (TYPE_MODE (vectype))))
>  	return NULL_TREE;
>  
>        /* For LEN_MASK_{LOAD,STORE}, we should also check whether
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
> new file mode 100644
> index 00000000000..23407a2d3f4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
> @@ -0,0 +1,43 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32d --param riscv-autovec-preference=fixed-vlmax --param riscv-autovec-lmul=m8 -O3 -fdump-tree-optimized-details" } */
> +
> +#include <stdint-gcc.h>
> +
> +#define SZ 255
> +
> +#define DEF(TYPE) void fn_##TYPE (TYPE *__restrict a);
> +
> +#define RUN(TYPE)                                                              \
> +  TYPE a##TYPE[SZ];                                                            \
> +  for (int i = 0; i < SZ; i++)                                                 \
> +    {                                                                          \
> +      a##TYPE[i] = 127;                                                        \
> +    }                                                                          \
> +  fn_##TYPE (a##TYPE);
> +
> +#define RUN_ALL()                                                              \
> +  RUN (int8_t)                                                                 \
> +  RUN (int16_t)                                                                \
> +  RUN (int32_t)                                                                \
> +  RUN (int64_t)                                                                \
> +  RUN (uint8_t)                                                                \
> +  RUN (uint16_t)                                                               \
> +  RUN (uint32_t)                                                               \
> +  RUN (uint64_t)
> +
> +DEF (int8_t)
> +DEF (int16_t)
> +DEF (int32_t)
> +DEF (int64_t)
> +DEF (uint8_t)
> +DEF (uint16_t)
> +DEF (uint32_t)
> +DEF (uint64_t)
> +
> +int
> +main ()
> +{
> +  RUN_ALL ()
> +}
> +
> +/* { dg-final { scan-tree-dump-times "\.LEN_MASK_STORE" 6 "optimized" } } */
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

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

* RE: [PATCH V2] GIMPLE_FOLD: Fix gimple fold for LEN_{MASK}_{LOAD,STORE}
  2023-06-26  8:17 ` Richard Biener
@ 2023-06-26 14:07   ` Li, Pan2
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Pan2 @ 2023-06-26 14:07 UTC (permalink / raw)
  To: Richard Biener, Ju-Zhe Zhong; +Cc: gcc-patches, richard.sandiford

Committed as passed both the bootstrap and regression test, thanks Richard.

Pan

-----Original Message-----
From: Gcc-patches <gcc-patches-bounces+pan2.li=intel.com@gcc.gnu.org> On Behalf Of Richard Biener via Gcc-patches
Sent: Monday, June 26, 2023 4:17 PM
To: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
Cc: gcc-patches@gcc.gnu.org; richard.sandiford@arm.com
Subject: Re: [PATCH V2] GIMPLE_FOLD: Fix gimple fold for LEN_{MASK}_{LOAD,STORE}

On Mon, 26 Jun 2023, juzhe.zhong@rivai.ai wrote:

> From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
> 
> Hi, previous I made a mistake on GIMPLE_FOLD of LEN_MASK_{LOAD,STORE}.
> 
> We should fold LEN_MASK_{LOAD,STORE} (bias+len) == vf (nunits instead of bytesize) && mask = all trues mask
> 
> into:
>    MEM_REF [...].
> 
> This patch added testcase to test gimple fold of LEN_MASK_{LOAD,STORE}.
> 
> Also, I fix LEN_LOAD/LEN_STORE, to make them have the same behavior.
> 
> Ok for trunk ?

OK

> gcc/ChangeLog:
> 
>         * gimple-fold.cc (gimple_fold_partial_load_store_mem_ref): Fix gimple fold of LOAD/STORE with length.
> 
> gcc/testsuite/ChangeLog:
> 
>         * gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c: New test.
> 
> ---
>  gcc/gimple-fold.cc                            |  6 ++-
>  .../riscv/rvv/autovec/partial/gimple_fold-1.c | 43 +++++++++++++++++++
>  2 files changed, 47 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
> 
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index 3d46b76edeb..6d167b116b9 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -5397,8 +5397,10 @@ gimple_fold_partial_load_store_mem_ref (gcall *call, tree vectype, bool mask_p)
>        unsigned int nargs = gimple_call_num_args (call);
>        tree bias = gimple_call_arg (call, nargs - 1);
>        gcc_assert (TREE_CODE (bias) == INTEGER_CST);
> -      if (maybe_ne (wi::to_poly_widest (basic_len) - wi::to_widest (bias),
> -		    GET_MODE_SIZE (TYPE_MODE (vectype))))
> +      /* For LEN_LOAD/LEN_STORE/LEN_MASK_LOAD/LEN_MASK_STORE,
> +	 we don't fold when (bias + len) != VF.  */
> +      if (maybe_ne (wi::to_poly_widest (basic_len) + wi::to_widest (bias),
> +		    GET_MODE_NUNITS (TYPE_MODE (vectype))))
>  	return NULL_TREE;
>  
>        /* For LEN_MASK_{LOAD,STORE}, we should also check whether
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
> new file mode 100644
> index 00000000000..23407a2d3f4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c
> @@ -0,0 +1,43 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32d --param riscv-autovec-preference=fixed-vlmax --param riscv-autovec-lmul=m8 -O3 -fdump-tree-optimized-details" } */
> +
> +#include <stdint-gcc.h>
> +
> +#define SZ 255
> +
> +#define DEF(TYPE) void fn_##TYPE (TYPE *__restrict a);
> +
> +#define RUN(TYPE)                                                              \
> +  TYPE a##TYPE[SZ];                                                            \
> +  for (int i = 0; i < SZ; i++)                                                 \
> +    {                                                                          \
> +      a##TYPE[i] = 127;                                                        \
> +    }                                                                          \
> +  fn_##TYPE (a##TYPE);
> +
> +#define RUN_ALL()                                                              \
> +  RUN (int8_t)                                                                 \
> +  RUN (int16_t)                                                                \
> +  RUN (int32_t)                                                                \
> +  RUN (int64_t)                                                                \
> +  RUN (uint8_t)                                                                \
> +  RUN (uint16_t)                                                               \
> +  RUN (uint32_t)                                                               \
> +  RUN (uint64_t)
> +
> +DEF (int8_t)
> +DEF (int16_t)
> +DEF (int32_t)
> +DEF (int64_t)
> +DEF (uint8_t)
> +DEF (uint16_t)
> +DEF (uint32_t)
> +DEF (uint64_t)
> +
> +int
> +main ()
> +{
> +  RUN_ALL ()
> +}
> +
> +/* { dg-final { scan-tree-dump-times "\.LEN_MASK_STORE" 6 "optimized" } } */
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

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

end of thread, other threads:[~2023-06-26 14:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26  8:11 [PATCH V2] GIMPLE_FOLD: Fix gimple fold for LEN_{MASK}_{LOAD,STORE} juzhe.zhong
2023-06-26  8:17 ` Richard Biener
2023-06-26 14:07   ` Li, Pan2

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).