Message ID | f8cf4e2c-c172-401f-ab02-a3daa7e2ba74@gmail.com |
---|---|
State | New |
Headers | show |
Series | vect: Look through pattern stmt in fold_left_reduction. | expand |
On Fri, Nov 10, 2023 at 10:06 AM Robin Dapp <rdapp.gcc@gmail.com> wrote: > > Hi, > > more fallout from the COND_OP change was shown in PR112464. > > It appears as if we "look through" a statement pattern in > vect_finish_replace_stmt but not before when we replace the newly > created vector statement's lhs. Then the lhs is the statement pattern's > lhs while in vect_finish_replace_stmt we assert that it's from the > statement the pattern replaced. > > This patch uses vect_orig_stmt on the scalar destination's definition > so the replaced statement is used everywhere. > > Bootstrapped and regtested on x86 and aarch64, riscv testsuite > unchanged. OK > Regards > Robin > > gcc/ChangeLog: > > PR tree-optimization/112464 > > * tree-vect-loop.cc (vectorize_fold_left_reduction): Use > vect_orig_stmt on scalar_dest_def_info. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/pr112464.c: New test. > --- > gcc/testsuite/gcc.target/i386/pr112464.c | 10 ++++++++++ > gcc/tree-vect-loop.cc | 2 +- > 2 files changed, 11 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/i386/pr112464.c > > diff --git a/gcc/testsuite/gcc.target/i386/pr112464.c b/gcc/testsuite/gcc.target/i386/pr112464.c > new file mode 100644 > index 00000000000..2290c714986 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr112464.c > @@ -0,0 +1,10 @@ > +/* { dg-do compile } */ > +/* { dg-options "-Ofast -mavx512dq -ftrapv" } */ > + > +long *e; > +int n, i, err; > +void fn() { > + for (; i < n; i++) > + if (e[i]) > + err++; > +} > diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc > index 8abc1937d74..f61adad1ca3 100644 > --- a/gcc/tree-vect-loop.cc > +++ b/gcc/tree-vect-loop.cc > @@ -7087,7 +7087,7 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo, > opmask, &vec_opmask); > } > > - gimple *sdef = scalar_dest_def_info->stmt; > + gimple *sdef = vect_orig_stmt (scalar_dest_def_info)->stmt; > tree scalar_dest = gimple_get_lhs (sdef); > tree scalar_type = TREE_TYPE (scalar_dest); > tree reduc_var = gimple_phi_result (reduc_def_stmt); > -- > 2.41.0
diff --git a/gcc/testsuite/gcc.target/i386/pr112464.c b/gcc/testsuite/gcc.target/i386/pr112464.c new file mode 100644 index 00000000000..2290c714986 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr112464.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast -mavx512dq -ftrapv" } */ + +long *e; +int n, i, err; +void fn() { + for (; i < n; i++) + if (e[i]) + err++; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 8abc1937d74..f61adad1ca3 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -7087,7 +7087,7 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo, opmask, &vec_opmask); } - gimple *sdef = scalar_dest_def_info->stmt; + gimple *sdef = vect_orig_stmt (scalar_dest_def_info)->stmt; tree scalar_dest = gimple_get_lhs (sdef); tree scalar_type = TREE_TYPE (scalar_dest); tree reduc_var = gimple_phi_result (reduc_def_stmt);