Message ID | 20210926110936.344019-4-iii@linux.ibm.com |
---|---|
State | New |
Headers | show |
Series | reassoc: Propagate PHI_LOOP_BIAS along single uses | expand |
On Sun, 26 Sep 2021, Ilya Leoshkevich wrote: > Add both positive and negative tests. The tests will likely be quite fragile with respect to what is actually vectorized on which target. If you move the tests to gcc.dg/vect/ you could at least do /* { dg-require-effective-target vect_int } */ do you need to look for the exact GIMPLE IL or is it enough to verify we are vectorizing the reduction? Thanks, Richard. > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/reassoc-46.c: New test. > * gcc.dg/tree-ssa/reassoc-46.h: Common code for new tests. > * gcc.dg/tree-ssa/reassoc-47.c: New test. > * gcc.dg/tree-ssa/reassoc-48.c: New test. > * gcc.dg/tree-ssa/reassoc-49.c: New test. > * gcc.dg/tree-ssa/reassoc-50.c: New test. > * gcc.dg/tree-ssa/reassoc-51.c: New test. > --- > gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c | 7 +++++ > gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h | 33 ++++++++++++++++++++++ > gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c | 9 ++++++ > gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c | 9 ++++++ > gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c | 11 ++++++++ > gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c | 10 +++++++ > gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c | 11 ++++++++ > 7 files changed, 90 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c > > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c > new file mode 100644 > index 00000000000..97563dd929f > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c > @@ -0,0 +1,7 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ > + > +#include "reassoc-46.h" > + > +/* Check that the loop accumulator is added last. */ > +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h > new file mode 100644 > index 00000000000..e60b490ea0d > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h > @@ -0,0 +1,33 @@ > +#define M 1024 > +unsigned int arr1[M]; > +unsigned int arr2[M]; > +volatile unsigned int sink; > + > +unsigned int > +test (void) > +{ > + unsigned int sum = 0; > + for (int i = 0; i < M; i++) > + { > +#ifdef MODIFY > + /* Modify the loop accumulator using a chain of operations - this should > + not affect its rank biasing. */ > + sum |= 1; > + sum ^= 2; > +#endif > +#ifdef STORE > + /* Save the loop accumulator into a global variable - this should not > + affect its rank biasing. */ > + sink = sum; > +#endif > +#ifdef USE > + /* Add a tricky use of the loop accumulator - this should prevent its > + rank biasing. */ > + i = (i + sum) % M; > +#endif > + /* Use addends with different ranks. */ > + sum += arr1[i]; > + sum += arr2[((i ^ 1) + 1) % M]; > + } > + return sum; > +} > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c > new file mode 100644 > index 00000000000..1b0f0fdabe1 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c > @@ -0,0 +1,9 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ > + > +#define MODIFY > +#include "reassoc-46.h" > + > +/* Check that if the loop accumulator is saved into a global variable, it's > + still added last. */ > +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c > new file mode 100644 > index 00000000000..13836ebe8e6 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c > @@ -0,0 +1,9 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ > + > +#define STORE > +#include "reassoc-46.h" > + > +/* Check that if the loop accumulator is modified using a chain of operations > + other than addition, its new value is still added last. */ > +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c > new file mode 100644 > index 00000000000..c1136a447a2 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c > @@ -0,0 +1,11 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ > + > +#define MODIFY > +#define STORE > +#include "reassoc-46.h" > + > +/* Check that if the loop accumulator is both modified using a chain of > + operations other than addition and stored into a global variable, its new > + value is still added last. */ > +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c > new file mode 100644 > index 00000000000..e35a4ff1278 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c > @@ -0,0 +1,10 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ > + > +#define MODIFY > +#define USE > +#include "reassoc-46.h" > + > +/* Check that if the loop accumulator has multiple uses inside the loop, it's > + not forced to the end of the reassociation chain. */ > +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 2 "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c > new file mode 100644 > index 00000000000..07175675e24 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c > @@ -0,0 +1,11 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ > + > +#define MODIFY > +#define STORE > +#define USE > +#include "reassoc-46.h" > + > +/* Check that if the loop accumulator has multiple uses inside the loop, it's > + not forced to the end of the reassociation chain. */ > +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 2 "optimized" } } */
On Tue, 2021-09-28 at 13:28 +0200, Richard Biener wrote: > On Sun, 26 Sep 2021, Ilya Leoshkevich wrote: > > > Add both positive and negative tests. > > The tests will likely be quite fragile with respect to what is > actually vectorized on which target. If you move the tests > to gcc.dg/vect/ you could at least do > > /* { dg-require-effective-target vect_int } */ > > do you need to look for the exact GIMPLE IL or is it enough to > verify we are vectorizing the reduction? Actually I don't think vectorization is that important here, and I only check how many times sum_x = sum_y + _z appears. So I use (?:vect_)?, which may or may not be there. An alternative I considered was to use -fno-tree-vectorize to get smaller regexes, but I thought it would be nice to know that vectorization does not mess up reassociation results. Best regards, Ilya
On Tue, 28 Sep 2021, Ilya Leoshkevich wrote: > On Tue, 2021-09-28 at 13:28 +0200, Richard Biener wrote: > > On Sun, 26 Sep 2021, Ilya Leoshkevich wrote: > > > > > Add both positive and negative tests. > > > > The tests will likely be quite fragile with respect to what is > > actually vectorized on which target. If you move the tests > > to gcc.dg/vect/ you could at least do > > > > /* { dg-require-effective-target vect_int } */ > > > > do you need to look for the exact GIMPLE IL or is it enough to > > verify we are vectorizing the reduction? > > Actually I don't think vectorization is that important here, and I > only check how many times sum_x = sum_y + _z appears. So I use > (?:vect_)?, which may or may not be there. > > An alternative I considered was to use -fno-tree-vectorize to get > smaller regexes, but I thought it would be nice to know that > vectorization does not mess up reassociation results. Ah, OK. So lets go ahead with the patch unchanged, but be prepared to deal with eventual fallout here on weird targets. Thanks, Richard.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c new file mode 100644 index 00000000000..97563dd929f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ + +#include "reassoc-46.h" + +/* Check that the loop accumulator is added last. */ +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h new file mode 100644 index 00000000000..e60b490ea0d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h @@ -0,0 +1,33 @@ +#define M 1024 +unsigned int arr1[M]; +unsigned int arr2[M]; +volatile unsigned int sink; + +unsigned int +test (void) +{ + unsigned int sum = 0; + for (int i = 0; i < M; i++) + { +#ifdef MODIFY + /* Modify the loop accumulator using a chain of operations - this should + not affect its rank biasing. */ + sum |= 1; + sum ^= 2; +#endif +#ifdef STORE + /* Save the loop accumulator into a global variable - this should not + affect its rank biasing. */ + sink = sum; +#endif +#ifdef USE + /* Add a tricky use of the loop accumulator - this should prevent its + rank biasing. */ + i = (i + sum) % M; +#endif + /* Use addends with different ranks. */ + sum += arr1[i]; + sum += arr2[((i ^ 1) + 1) % M]; + } + return sum; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c new file mode 100644 index 00000000000..1b0f0fdabe1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ + +#define MODIFY +#include "reassoc-46.h" + +/* Check that if the loop accumulator is saved into a global variable, it's + still added last. */ +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c new file mode 100644 index 00000000000..13836ebe8e6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ + +#define STORE +#include "reassoc-46.h" + +/* Check that if the loop accumulator is modified using a chain of operations + other than addition, its new value is still added last. */ +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c new file mode 100644 index 00000000000..c1136a447a2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ + +#define MODIFY +#define STORE +#include "reassoc-46.h" + +/* Check that if the loop accumulator is both modified using a chain of + operations other than addition and stored into a global variable, its new + value is still added last. */ +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c new file mode 100644 index 00000000000..e35a4ff1278 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ + +#define MODIFY +#define USE +#include "reassoc-46.h" + +/* Check that if the loop accumulator has multiple uses inside the loop, it's + not forced to the end of the reassociation chain. */ +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 2 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c new file mode 100644 index 00000000000..07175675e24 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -ftree-vectorize" } */ + +#define MODIFY +#define STORE +#define USE +#include "reassoc-46.h" + +/* Check that if the loop accumulator has multiple uses inside the loop, it's + not forced to the end of the reassociation chain. */ +/* { dg-final { scan-tree-dump-times {(?:vect_)?sum_[\d._]+ = (?:(?:vect_)?_[\d._]+ \+ (?:vect_)?sum_[\d._]+|(?:vect_)?sum_[\d._]+ \+ (?:vect_)?_[\d._]+)} 2 "optimized" } } */