Message ID | 20220920233835.45071-1-hongtao.liu@intel.com |
---|---|
State | New |
Headers | show |
Series | Don't check can_vec_perm_const_p for nonlinear iv_init when it's constant. | expand |
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 >
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 > >
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,