public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/110897 - Fix missed vectorization of shift on both RISC-V and aarch64
@ 2023-08-07  9:38 Juzhe-Zhong
  2023-08-07  9:45 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Juzhe-Zhong @ 2023-08-07  9:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.sandiford, rguenther, Juzhe-Zhong

Consider this following case:

#include <stdint.h>

#define TEST2_TYPE(TYPE)					\
  __attribute__((noipa))					\
  void vshiftr_##TYPE (TYPE *__restrict dst, TYPE *__restrict a, TYPE *__restrict b, int n)	\
  {								\
    for (int i = 0; i < n; i++)					\
      dst[i] = (a[i]) >> b[i];					\
  }

#define TEST_ALL()	\
 TEST2_TYPE(uint8_t)	\
 TEST2_TYPE(uint16_t)	\
 TEST2_TYPE(uint32_t)	\
 TEST2_TYPE(uint64_t)	\

TEST_ALL()

Both RISC-V and aarch64 of trunk GCC failed vectorize uint8_t/uint16_t with following missed report:

<source>:17:1: missed: couldn't vectorize loop
<source>:17:1: missed: not vectorized: relevant stmt not supported: patt_46 = MIN_EXPR <_6, 7>;
<source>:17:1: missed: couldn't vectorize loop
<source>:17:1: missed: not vectorized: relevant stmt not supported: patt_47 = MIN_EXPR <_7, 15>;
Compiler returned: 0

Both GCC 13.1 can vectorize, see:

https://godbolt.org/z/6vaMK5M1o

Bootstrap and regression on X86 passed.

Ok for trunk ?

gcc/ChangeLog:

	* tree-vect-patterns.cc (vect_recog_over_widening_pattern): Add op vectype.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/binop/narrow-1.c: Adapt testcase.

---
 gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c | 4 ++--
 gcc/tree-vect-patterns.cc                                   | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c
index 3de8d85b52d..b12cb6355c8 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c
@@ -27,5 +27,5 @@
 
 TEST_ALL ()
 
-/* { dg-final { scan-assembler-times {\tvnsra\.wv} 6 } } */
-/* { dg-final { scan-assembler-times {\tvnsrl\.wv} 5 } } */
+/* { dg-final { scan-assembler-times {\tvnsra\.wv} 4 } } */
+/* { dg-final { scan-assembler-times {\tvnsrl\.wv} 4 } } */
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 2cedf238450..cda27fed95b 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -3133,7 +3133,8 @@ vect_recog_over_widening_pattern (vec_info *vinfo,
 		return NULL;
 	    }
 	  else
-	    append_pattern_def_seq (vinfo, last_stmt_info, pattern_stmt);
+	    append_pattern_def_seq (vinfo, last_stmt_info, pattern_stmt,
+				    op_vectype);
 	  ops[1] = new_var;
 	}
     }
-- 
2.36.1


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

* Re: [PATCH] tree-optimization/110897 - Fix missed vectorization of shift on both RISC-V and aarch64
  2023-08-07  9:38 [PATCH] tree-optimization/110897 - Fix missed vectorization of shift on both RISC-V and aarch64 Juzhe-Zhong
@ 2023-08-07  9:45 ` Richard Biener
  2023-08-07 10:18   ` Lehua Ding
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-08-07  9:45 UTC (permalink / raw)
  To: Juzhe-Zhong; +Cc: gcc-patches, richard.sandiford

On Mon, 7 Aug 2023, Juzhe-Zhong wrote:

> Consider this following case:
> 
> #include <stdint.h>
> 
> #define TEST2_TYPE(TYPE)					\
>   __attribute__((noipa))					\
>   void vshiftr_##TYPE (TYPE *__restrict dst, TYPE *__restrict a, TYPE *__restrict b, int n)	\
>   {								\
>     for (int i = 0; i < n; i++)					\
>       dst[i] = (a[i]) >> b[i];					\
>   }
> 
> #define TEST_ALL()	\
>  TEST2_TYPE(uint8_t)	\
>  TEST2_TYPE(uint16_t)	\
>  TEST2_TYPE(uint32_t)	\
>  TEST2_TYPE(uint64_t)	\
> 
> TEST_ALL()
> 
> Both RISC-V and aarch64 of trunk GCC failed vectorize uint8_t/uint16_t with following missed report:
> 
> <source>:17:1: missed: couldn't vectorize loop
> <source>:17:1: missed: not vectorized: relevant stmt not supported: patt_46 = MIN_EXPR <_6, 7>;
> <source>:17:1: missed: couldn't vectorize loop
> <source>:17:1: missed: not vectorized: relevant stmt not supported: patt_47 = MIN_EXPR <_7, 15>;
> Compiler returned: 0
> 
> Both GCC 13.1 can vectorize, see:
> 
> https://godbolt.org/z/6vaMK5M1o
> 
> Bootstrap and regression on X86 passed.
> 
> Ok for trunk ?

OK.

> gcc/ChangeLog:
> 
> 	* tree-vect-patterns.cc (vect_recog_over_widening_pattern): Add op vectype.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/riscv/rvv/autovec/binop/narrow-1.c: Adapt testcase.
> 
> ---
>  gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c | 4 ++--
>  gcc/tree-vect-patterns.cc                                   | 3 ++-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c
> index 3de8d85b52d..b12cb6355c8 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c
> @@ -27,5 +27,5 @@
>  
>  TEST_ALL ()
>  
> -/* { dg-final { scan-assembler-times {\tvnsra\.wv} 6 } } */
> -/* { dg-final { scan-assembler-times {\tvnsrl\.wv} 5 } } */
> +/* { dg-final { scan-assembler-times {\tvnsra\.wv} 4 } } */
> +/* { dg-final { scan-assembler-times {\tvnsrl\.wv} 4 } } */
> diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
> index 2cedf238450..cda27fed95b 100644
> --- a/gcc/tree-vect-patterns.cc
> +++ b/gcc/tree-vect-patterns.cc
> @@ -3133,7 +3133,8 @@ vect_recog_over_widening_pattern (vec_info *vinfo,
>  		return NULL;
>  	    }
>  	  else
> -	    append_pattern_def_seq (vinfo, last_stmt_info, pattern_stmt);
> +	    append_pattern_def_seq (vinfo, last_stmt_info, pattern_stmt,
> +				    op_vectype);
>  	  ops[1] = new_var;
>  	}
>      }
> 

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

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

* Re: [PATCH] tree-optimization/110897 - Fix missed vectorization of shift on both RISC-V and aarch64
  2023-08-07  9:45 ` Richard Biener
@ 2023-08-07 10:18   ` Lehua Ding
  0 siblings, 0 replies; 3+ messages in thread
From: Lehua Ding @ 2023-08-07 10:18 UTC (permalink / raw)
  To: Richard Biener, Juzhe-Zhong; +Cc: gcc-patches, richard.sandiford

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

Committed to trunk, thanks Richard and Juzhe.

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

end of thread, other threads:[~2023-08-07 10:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07  9:38 [PATCH] tree-optimization/110897 - Fix missed vectorization of shift on both RISC-V and aarch64 Juzhe-Zhong
2023-08-07  9:45 ` Richard Biener
2023-08-07 10:18   ` Lehua Ding

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