public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Don't check can_vec_perm_const_p for nonlinear iv_init when it's constant.
@ 2022-09-20 23:38 liuhongt
  2022-09-21  7:41 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: liuhongt @ 2022-09-20 23:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: crazylht, hjl.tools

When init_expr is INTEGER_CST or REAL_CST, can_vec_perm_const_p is not
necessary since there's no real vec_perm needed, but
vec_gen_perm_mask_checked will gcc_assert (can_vec_perm_const_p). So
it's better to use vec_gen_perm_mask_any in
vect_create_nonlinear_iv_init.

Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ok for trunk?

gcc/ChangeLog:

	PR tree-optimization/106963
	* tree-vect-loop.cc (vect_create_nonlinear_iv_init): Use
	vec_gen_perm_mask_any instead of vec_gen_perm_mask_check.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr106963.c: New test.
---
 gcc/testsuite/gcc.target/i386/pr106963.c | 14 ++++++++++++++
 gcc/tree-vect-loop.cc                    |  5 ++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr106963.c

diff --git a/gcc/testsuite/gcc.target/i386/pr106963.c b/gcc/testsuite/gcc.target/i386/pr106963.c
new file mode 100644
index 00000000000..9f2d20e2523
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr106963.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx -mno-avx2" } */
+
+void
+foo_neg_const (int *a)
+{
+  int i, b = 1;
+
+  for (i = 0; i < 1000; i++)
+    {
+      a[i] = b;
+      b = -b;
+    }
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 9c434b66c5b..aabdc6f2d81 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -8356,8 +8356,11 @@ vect_create_nonlinear_iv_init (gimple_seq* stmts, tree init_expr,
 	    sel[2 * i + 1] = i + nunits;
 	  }
 	vec_perm_indices indices (sel, 2, nunits);
+	/* Don't use vect_gen_perm_mask_checked since can_vec_perm_const_p may
+	   fail when vec_init is const vector. In that situation vec_perm is not
+	   really needed.  */
 	tree perm_mask_even
-	  = vect_gen_perm_mask_checked (vectype, indices);
+	  = vect_gen_perm_mask_any (vectype, indices);
 	vec_init = gimple_build (stmts, VEC_PERM_EXPR,
 				 vectype,
 				 vec_init, vec_neg,
-- 
2.18.1


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

* Re: [PATCH] Don't check can_vec_perm_const_p for nonlinear iv_init when it's constant.
  2022-09-20 23:38 [PATCH] Don't check can_vec_perm_const_p for nonlinear iv_init when it's constant liuhongt
@ 2022-09-21  7:41 ` Richard Biener
  2022-09-21  7:45   ` Hongtao Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2022-09-21  7:41 UTC (permalink / raw)
  To: liuhongt; +Cc: GCC Patches

On Wed, Sep 21, 2022 at 1:41 AM liuhongt via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> When init_expr is INTEGER_CST or REAL_CST, can_vec_perm_const_p is not
> necessary since there's no real vec_perm needed, but
> vec_gen_perm_mask_checked will gcc_assert (can_vec_perm_const_p). So
> it's better to use vec_gen_perm_mask_any in
> vect_create_nonlinear_iv_init.

and the VEC_PERM build will fold the permute away?

> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk?

OK.

Thanks,
Richard.

> gcc/ChangeLog:
>
>         PR tree-optimization/106963
>         * tree-vect-loop.cc (vect_create_nonlinear_iv_init): Use
>         vec_gen_perm_mask_any instead of vec_gen_perm_mask_check.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/pr106963.c: New test.
> ---
>  gcc/testsuite/gcc.target/i386/pr106963.c | 14 ++++++++++++++
>  gcc/tree-vect-loop.cc                    |  5 ++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr106963.c
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr106963.c b/gcc/testsuite/gcc.target/i386/pr106963.c
> new file mode 100644
> index 00000000000..9f2d20e2523
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr106963.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mavx -mno-avx2" } */
> +
> +void
> +foo_neg_const (int *a)
> +{
> +  int i, b = 1;
> +
> +  for (i = 0; i < 1000; i++)
> +    {
> +      a[i] = b;
> +      b = -b;
> +    }
> +}
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index 9c434b66c5b..aabdc6f2d81 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -8356,8 +8356,11 @@ vect_create_nonlinear_iv_init (gimple_seq* stmts, tree init_expr,
>             sel[2 * i + 1] = i + nunits;
>           }
>         vec_perm_indices indices (sel, 2, nunits);
> +       /* Don't use vect_gen_perm_mask_checked since can_vec_perm_const_p may
> +          fail when vec_init is const vector. In that situation vec_perm is not
> +          really needed.  */
>         tree perm_mask_even
> -         = vect_gen_perm_mask_checked (vectype, indices);
> +         = vect_gen_perm_mask_any (vectype, indices);
>         vec_init = gimple_build (stmts, VEC_PERM_EXPR,
>                                  vectype,
>                                  vec_init, vec_neg,
> --
> 2.18.1
>

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

* Re: [PATCH] Don't check can_vec_perm_const_p for nonlinear iv_init when it's constant.
  2022-09-21  7:41 ` Richard Biener
@ 2022-09-21  7:45   ` Hongtao Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Hongtao Liu @ 2022-09-21  7:45 UTC (permalink / raw)
  To: Richard Biener; +Cc: liuhongt, GCC Patches

On Wed, Sep 21, 2022 at 3:41 PM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Wed, Sep 21, 2022 at 1:41 AM liuhongt via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > When init_expr is INTEGER_CST or REAL_CST, can_vec_perm_const_p is not
> > necessary since there's no real vec_perm needed, but
> > vec_gen_perm_mask_checked will gcc_assert (can_vec_perm_const_p). So
> > it's better to use vec_gen_perm_mask_any in
> > vect_create_nonlinear_iv_init.
>
> and the VEC_PERM build will fold the permute away?
Yes, it's just a const vector. [ c, -c, c, c, .. ].
>
> > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> > Ok for trunk?
>
> OK.
>
> Thanks,
> Richard.
>
> > gcc/ChangeLog:
> >
> >         PR tree-optimization/106963
> >         * tree-vect-loop.cc (vect_create_nonlinear_iv_init): Use
> >         vec_gen_perm_mask_any instead of vec_gen_perm_mask_check.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         * gcc.target/i386/pr106963.c: New test.
> > ---
> >  gcc/testsuite/gcc.target/i386/pr106963.c | 14 ++++++++++++++
> >  gcc/tree-vect-loop.cc                    |  5 ++++-
> >  2 files changed, 18 insertions(+), 1 deletion(-)
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr106963.c
> >
> > diff --git a/gcc/testsuite/gcc.target/i386/pr106963.c b/gcc/testsuite/gcc.target/i386/pr106963.c
> > new file mode 100644
> > index 00000000000..9f2d20e2523
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr106963.c
> > @@ -0,0 +1,14 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -mavx -mno-avx2" } */
> > +
> > +void
> > +foo_neg_const (int *a)
> > +{
> > +  int i, b = 1;
> > +
> > +  for (i = 0; i < 1000; i++)
> > +    {
> > +      a[i] = b;
> > +      b = -b;
> > +    }
> > +}
> > diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> > index 9c434b66c5b..aabdc6f2d81 100644
> > --- a/gcc/tree-vect-loop.cc
> > +++ b/gcc/tree-vect-loop.cc
> > @@ -8356,8 +8356,11 @@ vect_create_nonlinear_iv_init (gimple_seq* stmts, tree init_expr,
> >             sel[2 * i + 1] = i + nunits;
> >           }
> >         vec_perm_indices indices (sel, 2, nunits);
> > +       /* Don't use vect_gen_perm_mask_checked since can_vec_perm_const_p may
> > +          fail when vec_init is const vector. In that situation vec_perm is not
> > +          really needed.  */
> >         tree perm_mask_even
> > -         = vect_gen_perm_mask_checked (vectype, indices);
> > +         = vect_gen_perm_mask_any (vectype, indices);
> >         vec_init = gimple_build (stmts, VEC_PERM_EXPR,
> >                                  vectype,
> >                                  vec_init, vec_neg,
> > --
> > 2.18.1
> >



-- 
BR,
Hongtao

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

end of thread, other threads:[~2022-09-21  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 23:38 [PATCH] Don't check can_vec_perm_const_p for nonlinear iv_init when it's constant liuhongt
2022-09-21  7:41 ` Richard Biener
2022-09-21  7:45   ` Hongtao Liu

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