diff mbox series

vect: Treat VMAT_ELEMENTWISE as scalar load in costing [PR110776]

Message ID 7dacafa4-d2e8-c471-f251-406a60f291ed@linux.ibm.com
State New
Headers show
Series vect: Treat VMAT_ELEMENTWISE as scalar load in costing [PR110776] | expand

Commit Message

Kewen.Lin July 26, 2023, 2:52 a.m. UTC
Hi,

PR110776 exposes one issue that we could query unaligned
load for vector type but actually no unaligned vector load
is supported there.  The reason is that the costed load is
with single-lane vector type and its memory access type is
VMAT_ELEMENTWISE, we actually take it as scalar load and
set its alignment_support_scheme as dr_unaligned_supported.

To avoid the ICE as exposed, following Rich's suggestion,
this patch is to make VMAT_ELEMENTWISE be costed as scalar
load.

Bootstrapped and regress-tested on x86_64-redhat-linux,
powerpc64-linux-gnu P8/P9 and powerpc64le-linux-gnu P9/P10.

Is it ok for trunk?

BR,
Kewen
-----

Co-authored-by: Richard Biener <rguenther@suse.de>

	PR tree-optimization/110776

gcc/ChangeLog:

	* tree-vect-stmts.cc (vectorizable_load): Always cost VMAT_ELEMENTWISE
	as scalar load.

gcc/testsuite/ChangeLog:

	* gcc.target/powerpc/pr110776.c: New test.
---
 gcc/testsuite/gcc.target/powerpc/pr110776.c | 22 +++++++++++++++++++++
 gcc/tree-vect-stmts.cc                      |  5 ++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr110776.c

--
2.39.1

Comments

Richard Biener July 26, 2023, 10:02 a.m. UTC | #1
On Wed, Jul 26, 2023 at 4:52 AM Kewen.Lin <linkw@linux.ibm.com> wrote:
>
> Hi,
>
> PR110776 exposes one issue that we could query unaligned
> load for vector type but actually no unaligned vector load
> is supported there.  The reason is that the costed load is
> with single-lane vector type and its memory access type is
> VMAT_ELEMENTWISE, we actually take it as scalar load and
> set its alignment_support_scheme as dr_unaligned_supported.
>
> To avoid the ICE as exposed, following Rich's suggestion,
> this patch is to make VMAT_ELEMENTWISE be costed as scalar
> load.
>
> Bootstrapped and regress-tested on x86_64-redhat-linux,
> powerpc64-linux-gnu P8/P9 and powerpc64le-linux-gnu P9/P10.
>
> Is it ok for trunk?

OK.

> BR,
> Kewen
> -----
>
> Co-authored-by: Richard Biener <rguenther@suse.de>
>
>         PR tree-optimization/110776
>
> gcc/ChangeLog:
>
>         * tree-vect-stmts.cc (vectorizable_load): Always cost VMAT_ELEMENTWISE
>         as scalar load.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/powerpc/pr110776.c: New test.
> ---
>  gcc/testsuite/gcc.target/powerpc/pr110776.c | 22 +++++++++++++++++++++
>  gcc/tree-vect-stmts.cc                      |  5 ++++-
>  2 files changed, 26 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/powerpc/pr110776.c
>
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr110776.c b/gcc/testsuite/gcc.target/powerpc/pr110776.c
> new file mode 100644
> index 00000000000..749159fd675
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr110776.c
> @@ -0,0 +1,22 @@
> +/* { dg-require-effective-target powerpc_altivec_ok } */
> +/* { dg-options "-O2 -mdejagnu-cpu=power6 -maltivec" } */
> +
> +/* Verify there is no ICE.  */
> +
> +int a;
> +long *b;
> +int
> +c ()
> +{
> +  long e;
> +  int d = 0;
> +  for (long f; f; f++)
> +    {
> +      e = b[f * a];
> +      if (e)
> +       d = 1;
> +    }
> +  if (d)
> +    for (;;)
> +      ;
> +}
> diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
> index ed28fbdced3..09705200594 100644
> --- a/gcc/tree-vect-stmts.cc
> +++ b/gcc/tree-vect-stmts.cc
> @@ -9840,7 +9840,10 @@ vectorizable_load (vec_info *vinfo,
>             {
>               if (costing_p)
>                 {
> -                 if (VECTOR_TYPE_P (ltype))
> +                 /* For VMAT_ELEMENTWISE, just cost it as scalar_load to
> +                    avoid ICE, see PR110776.  */
> +                 if (VECTOR_TYPE_P (ltype)
> +                     && memory_access_type != VMAT_ELEMENTWISE)
>                     vect_get_load_cost (vinfo, stmt_info, 1,
>                                         alignment_support_scheme, misalignment,
>                                         false, &inside_cost, nullptr, cost_vec,
> --
> 2.39.1
Kewen.Lin July 27, 2023, 2:53 a.m. UTC | #2
on 2023/7/26 18:02, Richard Biener wrote:
> On Wed, Jul 26, 2023 at 4:52 AM Kewen.Lin <linkw@linux.ibm.com> wrote:
>>
>> Hi,
>>
>> PR110776 exposes one issue that we could query unaligned
>> load for vector type but actually no unaligned vector load
>> is supported there.  The reason is that the costed load is
>> with single-lane vector type and its memory access type is
>> VMAT_ELEMENTWISE, we actually take it as scalar load and
>> set its alignment_support_scheme as dr_unaligned_supported.
>>
>> To avoid the ICE as exposed, following Rich's suggestion,
>> this patch is to make VMAT_ELEMENTWISE be costed as scalar
>> load.
>>
>> Bootstrapped and regress-tested on x86_64-redhat-linux,
>> powerpc64-linux-gnu P8/P9 and powerpc64le-linux-gnu P9/P10.
>>
>> Is it ok for trunk?
> 
> OK.

Thanks Richi, pushed as r14-2813.

BR,
Kewen
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.target/powerpc/pr110776.c b/gcc/testsuite/gcc.target/powerpc/pr110776.c
new file mode 100644
index 00000000000..749159fd675
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr110776.c
@@ -0,0 +1,22 @@ 
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power6 -maltivec" } */
+
+/* Verify there is no ICE.  */
+
+int a;
+long *b;
+int
+c ()
+{
+  long e;
+  int d = 0;
+  for (long f; f; f++)
+    {
+      e = b[f * a];
+      if (e)
+	d = 1;
+    }
+  if (d)
+    for (;;)
+      ;
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index ed28fbdced3..09705200594 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -9840,7 +9840,10 @@  vectorizable_load (vec_info *vinfo,
 	    {
 	      if (costing_p)
 		{
-		  if (VECTOR_TYPE_P (ltype))
+		  /* For VMAT_ELEMENTWISE, just cost it as scalar_load to
+		     avoid ICE, see PR110776.  */
+		  if (VECTOR_TYPE_P (ltype)
+		      && memory_access_type != VMAT_ELEMENTWISE)
 		    vect_get_load_cost (vinfo, stmt_info, 1,
 					alignment_support_scheme, misalignment,
 					false, &inside_cost, nullptr, cost_vec,