On Thu, Aug 31, 2023 at 12:27 AM Andrew Pinski via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > This simple patch extends the min_value/max_value match to vector integer > types. > Using uniform_integer_cst_p makes this easy. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > The testcases pr110915-*.c are the same as pr88784-*.c except using vector > types instead.
OK. > PR tree-optimization/110915 > > gcc/ChangeLog: > > * match.pd (min_value, max_value): Extend to vector constants. > > gcc/testsuite/ChangeLog: > > * gcc.dg/pr110915-1.c: New test. > * gcc.dg/pr110915-10.c: New test. > * gcc.dg/pr110915-11.c: New test. > * gcc.dg/pr110915-12.c: New test. > * gcc.dg/pr110915-2.c: New test. > * gcc.dg/pr110915-3.c: New test. > * gcc.dg/pr110915-4.c: New test. > * gcc.dg/pr110915-5.c: New test. > * gcc.dg/pr110915-6.c: New test. > * gcc.dg/pr110915-7.c: New test. > * gcc.dg/pr110915-8.c: New test. > * gcc.dg/pr110915-9.c: New test. > --- > gcc/match.pd | 24 ++++++++++++++-------- > gcc/testsuite/gcc.dg/pr110915-1.c | 31 ++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-10.c | 33 ++++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-11.c | 31 ++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-12.c | 31 ++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-2.c | 31 ++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-3.c | 33 ++++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-4.c | 33 ++++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-5.c | 32 +++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-6.c | 32 +++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-7.c | 32 +++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-8.c | 32 +++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110915-9.c | 33 ++++++++++++++++++++++++++++++ > 13 files changed, 400 insertions(+), 8 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr110915-1.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-10.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-11.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-12.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-2.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-3.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-4.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-5.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-6.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-7.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-8.c > create mode 100644 gcc/testsuite/gcc.dg/pr110915-9.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index 6a7edde5736..c01362ee359 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -2750,16 +2750,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > & (bitpos / BITS_PER_UNIT))); })))) > > (match min_value > - INTEGER_CST > - (if ((INTEGRAL_TYPE_P (type) > - || POINTER_TYPE_P(type)) > - && wi::eq_p (wi::to_wide (t), wi::min_value (type))))) > + uniform_integer_cst_p > + (with { > + tree int_cst = uniform_integer_cst_p (t); > + tree inner_type = TREE_TYPE (int_cst); > + } > + (if ((INTEGRAL_TYPE_P (inner_type) > + || POINTER_TYPE_P (inner_type)) > + && wi::eq_p (wi::to_wide (int_cst), wi::min_value (inner_type)))))) > > (match max_value > - INTEGER_CST > - (if ((INTEGRAL_TYPE_P (type) > - || POINTER_TYPE_P(type)) > - && wi::eq_p (wi::to_wide (t), wi::max_value (type))))) > + uniform_integer_cst_p > + (with { > + tree int_cst = uniform_integer_cst_p (t); > + tree itype = TREE_TYPE (int_cst); > + } > + (if ((INTEGRAL_TYPE_P (itype) > + || POINTER_TYPE_P (itype)) > + && wi::eq_p (wi::to_wide (int_cst), wi::max_value (itype)))))) > > /* x > y && x != XXX_MIN --> x > y > x > y && x == XXX_MIN --> false . */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-1.c > b/gcc/testsuite/gcc.dg/pr110915-1.c > new file mode 100644 > index 00000000000..2e1e871b9a0 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-1.c > @@ -0,0 +1,31 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed and1(vector unsigned x, vector unsigned y) > +{ > + /* (x > y) & (x != 0) --> x > y */ > + return (x > y) & (x != 0); > +} > + > +vector signed and2(vector unsigned x, vector unsigned y) > +{ > + /* (x < y) & (x != UINT_MAX) --> x < y */ > + return (x < y) & (x != UINT_MAX); > +} > + > +vector signed and3(vector signed x, vector signed y) > +{ > + /* (x > y) & (x != INT_MIN) --> x > y */ > + return (x > y) & (x != INT_MIN); > +} > + > +vector signed and4(vector signed x, vector signed y) > +{ > + /* (x < y) & (x != INT_MAX) --> x < y */ > + return (x < y) & (x != INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-10.c > b/gcc/testsuite/gcc.dg/pr110915-10.c > new file mode 100644 > index 00000000000..b0644bf3123 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-10.c > @@ -0,0 +1,33 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector unsigned or1(vector unsigned x, vector unsigned y) > +{ > + /* (x <= y) | (x != 0)) --> true */ > + return (x <= y) | (x != 0); > +} > + > +vector unsigned or2(vector unsigned x, vector unsigned y) > +{ > + /* (x >= y) | (x != UINT_MAX) --> true */ > + return (x >= y) | (x != UINT_MAX); > +} > + > +vector signed or3(vector signed x, vector signed y) > +{ > + /* (x <= y) | (x != INT_MIN) --> true */ > + return (x <= y) | (x != INT_MIN); > +} > + > +vector signed or4(vector signed x, vector signed y) > +{ > + /* (x >= y) | (x != INT_MAX) --> true */ > + return (x >= y) | (x != INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " != " "optimized" } } */ > +/* { dg-final { scan-tree-dump-not " <= " "optimized" } } */ > +/* { dg-final { scan-tree-dump-not " >= " "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-11.c > b/gcc/testsuite/gcc.dg/pr110915-11.c > new file mode 100644 > index 00000000000..0288e53b16b > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-11.c > @@ -0,0 +1,31 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector unsigned or1(vector unsigned x, vector unsigned y) > +{ > + /* (x <= y) | (x == 0) --> x <= y */ > + return (x <= y) | (x == 0); > +} > + > +vector unsigned or2(vector unsigned x, vector unsigned y) > +{ > + /* (x >= y) | (x == UINT_MAX) --> x >= y */ > + return (x >= y) | (x == UINT_MAX); > +} > + > +vector signed or3(vector signed x, vector signed y) > +{ > + /* (x <= y) | (x == INT_MIN) --> x <= y */ > + return (x <= y) | (x == INT_MIN); > +} > + > +vector signed or4(vector signed x, vector signed y) > +{ > + /* (x >= y) | (x == INT_MAX) --> x >= y */ > + return (x >= y) | (x == INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " == " "ifcombine" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-12.c > b/gcc/testsuite/gcc.dg/pr110915-12.c > new file mode 100644 > index 00000000000..054a077ce3e > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-12.c > @@ -0,0 +1,31 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-dce3" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector unsigned or1(vector unsigned x, vector unsigned y) > +{ > + /* (x <= y) | (x == 0) --> x <= y */ > + return (x <= y) | (x == 0); > +} > + > +vector unsigned or2(vector unsigned x, vector unsigned y) > +{ > + /* (x >= y) | (x == UINT_MAX) --> x >= y */ > + return (x >= y) | (x == UINT_MAX); > +} > + > +vector signed or3(vector signed x, vector signed y) > +{ > + /* (x <= y) | (x == INT_MIN) --> x <= y */ > + return (x <= y) | (x == INT_MIN); > +} > + > +vector signed or4(vector signed x, vector signed y) > +{ > + /* (x >= y) | (x == INT_MAX) --> x >= y */ > + return (x >= y) | (x == INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " == " "dce3" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-2.c > b/gcc/testsuite/gcc.dg/pr110915-2.c > new file mode 100644 > index 00000000000..3962b152078 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-2.c > @@ -0,0 +1,31 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed and1(vector unsigned x, vector unsigned y) > +{ > + /* (x > y) & (x != 0) --> x > y */ > + return (x > y) & (x != 0); > +} > + > +vector signed and2(vector unsigned x, vector unsigned y) > +{ > + /* (x < y) & (x != UINT_MAX) --> x < y */ > + return (x < y) & (x != UINT_MAX); > +} > + > +vector signed and3(vector signed x, vector signed y) > +{ > + /* (x > y) & (x != INT_MIN) --> x > y */ > + return (x > y) & (x != INT_MIN); > +} > + > +vector signed and4(vector signed x, vector signed y) > +{ > + /* (x < y) & (x != INT_MAX) --> x < y */ > + return (x < y) & (x != INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " != " "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-3.c > b/gcc/testsuite/gcc.dg/pr110915-3.c > new file mode 100644 > index 00000000000..c6462b59526 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-3.c > @@ -0,0 +1,33 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed and1(vector unsigned x, vector unsigned y) > +{ > + /* (x > y) & (x == 0) --> false */ > + return (x > y) & (x == 0); > +} > + > +vector signed and2(vector unsigned x, vector unsigned y) > +{ > + /* (x < y) & (x == UINT_MAX) --> false */ > + return (x < y) & (x == UINT_MAX); > +} > + > +vector signed and3(vector signed x, vector signed y) > +{ > + /* (x > y) & (x == INT_MIN) --> false */ > + return (x > y) & (x == INT_MIN); > +} > + > +vector signed and4(vector signed x, vector signed y) > +{ > + /* (x < y) & (x == INT_MAX) --> false */ > + return (x < y) & (x == INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " == " "ifcombine" } } */ > +/* { dg-final { scan-tree-dump-not " > " "ifcombine" } } */ > +/* { dg-final { scan-tree-dump-not " < " "ifcombine" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-4.c > b/gcc/testsuite/gcc.dg/pr110915-4.c > new file mode 100644 > index 00000000000..5b28ccdd321 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-4.c > @@ -0,0 +1,33 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed and1(vector unsigned x, vector unsigned y) > +{ > + /* (x > y) & (x == 0) --> false */ > + return (x > y) & (x == 0); > +} > + > +vector signed and2(vector unsigned x, vector unsigned y) > +{ > + /* (x < y) & (x == UINT_MAX) --> false */ > + return (x < y) & (x == UINT_MAX); > +} > + > +vector signed and3(vector signed x, vector signed y) > +{ > + /* (x > y) & (x == INT_MIN) --> false */ > + return (x > y) & (x == INT_MIN); > +} > + > +vector signed and4(vector signed x, vector signed y) > +{ > + /* (x < y) & (x == INT_MAX) --> false */ > + return (x < y) & (x == INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " == " "optimized" } } */ > +/* { dg-final { scan-tree-dump-not " > " "optimized" } } */ > +/* { dg-final { scan-tree-dump-not " < " "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-5.c > b/gcc/testsuite/gcc.dg/pr110915-5.c > new file mode 100644 > index 00000000000..a8b871d5bca > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-5.c > @@ -0,0 +1,32 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed and1(vector unsigned x, vector unsigned y) > +{ > + /* (x <= y) & (x == 0) --> x == 0 */ > + return (x <= y) & (x == 0); > +} > + > +vector signed and2(vector unsigned x, vector unsigned y) > +{ > + /* (x >= y) & (x == UINT_MAX) --> x == UINT_MAX */ > + return (x >= y) & (x == UINT_MAX); > +} > + > +vector signed and3(vector signed x, vector signed y) > +{ > + /* (x <= y) & (x == INT_MIN) --> x == INT_MIN */ > + return (x <= y) & (x == INT_MIN); > +} > + > +vector signed and4(vector signed x, vector signed y) > +{ > + /* (x >= y) & (x == INT_MAX) --> x == INT_MAX */ > + return (x >= y) & (x == INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */ > +/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-6.c > b/gcc/testsuite/gcc.dg/pr110915-6.c > new file mode 100644 > index 00000000000..a3b9cc02a4b > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-6.c > @@ -0,0 +1,32 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed and1(vector unsigned x, vector unsigned y) > +{ > + /* (x <= y) & (x == 0) --> x == 0 */ > + return (x <= y) & (x == 0); > +} > + > +vector signed and2(vector unsigned x, vector unsigned y) > +{ > + /* (x >= y) & (x == UINT_MAX) --> x == UINT_MAX */ > + return (x >= y) & (x == UINT_MAX); > +} > + > +vector signed and3(vector signed x, vector signed y) > +{ > + /* (x <= y) & (x == INT_MIN) --> x == INT_MIN */ > + return (x <= y) & (x == INT_MIN); > +} > + > +vector signed and4(vector signed x, vector signed y) > +{ > + /* (x >= y) & (x == INT_MAX) --> x == INT_MAX */ > + return (x >= y) & (x == INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " <= " "optimized" } } */ > +/* { dg-final { scan-tree-dump-not " >= " "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-7.c > b/gcc/testsuite/gcc.dg/pr110915-7.c > new file mode 100644 > index 00000000000..fd331e90e4a > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-7.c > @@ -0,0 +1,32 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed or1(vector unsigned x, vector unsigned y) > +{ > + /* (x > y) | (x != 0) --> x != 0 */ > + return (x > y) | (x != 0); > +} > + > +vector signed or2(vector unsigned x, vector unsigned y) > +{ > + /* (x < y) | (x != UINT_MAX) --> x != UINT_MAX */ > + return (x < y) | (x != UINT_MAX); > +} > + > +vector signed or3(vector signed x, vector signed y) > +{ > + /* (x > y) | (x != INT_MIN) --> x != INT_MIN */ > + return (x > y) | (x != INT_MIN); > +} > + > +vector signed or4(vector signed x, vector signed y) > +{ > + /* (x < y) | (x != INT_MAX) --> x != INT_MAX */ > + return (x < y) | (x != INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " > " "ifcombine" } } */ > +/* { dg-final { scan-tree-dump-not " < " "ifcombine" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-8.c > b/gcc/testsuite/gcc.dg/pr110915-8.c > new file mode 100644 > index 00000000000..fae533cbf22 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-8.c > @@ -0,0 +1,32 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed or1(vector unsigned x, vector unsigned y) > +{ > + /* (x > y) | (x != 0) --> x != 0 */ > + return (x > y) | (x != 0); > +} > + > +vector signed or2(vector unsigned x, vector unsigned y) > +{ > + /* (x < y) | (x != UINT_MAX) --> x != UINT_MAX */ > + return (x < y) | (x != UINT_MAX); > +} > + > +vector signed or3(vector signed x, vector signed y) > +{ > + /* (x > y) | (x != INT_MIN) --> x != INT_MIN */ > + return (x > y) | (x != INT_MIN); > +} > + > +vector signed or4(vector signed x, vector signed y) > +{ > + /* (x < y) | (x != INT_MAX) --> x != INT_MAX */ > + return (x < y) | (x != INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " > " "optimized" } } */ > +/* { dg-final { scan-tree-dump-not " < " "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr110915-9.c > b/gcc/testsuite/gcc.dg/pr110915-9.c > new file mode 100644 > index 00000000000..07aa08ee00b > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110915-9.c > @@ -0,0 +1,33 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ > +#define vector __attribute__((vector_size(sizeof(unsigned)*2))) > + > +#include <limits.h> > + > +vector signed or1(vector unsigned x, vector unsigned y) > +{ > + /* (x <= y) | (x != 0) --> true */ > + return (x <= y) | (x != 0); > +} > + > +vector signed or2(vector unsigned x, vector unsigned y) > +{ > + /* (x >= y) | (x != UINT_MAX) --> true */ > + return (x >= y) | (x != UINT_MAX); > +} > + > +vector signed or3(vector signed x, vector signed y) > +{ > + /* (x <= y) | (x != INT_MIN) --> true */ > + return (x <= y) | (x != INT_MIN); > +} > + > +vector signed or4(vector signed x, vector signed y) > +{ > + /* (x >= y) | (x != INT_MAX) --> true */ > + return (x >= y) | (x != INT_MAX); > +} > + > +/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */ > +/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */ > +/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */ > -- > 2.31.1 >