]> gcc.gnu.org Git - gcc.git/commitdiff
MATCH: extend min_value/max_value match to vectors
authorAndrew Pinski <apinski@marvell.com>
Wed, 30 Aug 2023 19:27:06 +0000 (12:27 -0700)
committerAndrew Pinski <apinski@marvell.com>
Thu, 31 Aug 2023 17:25:28 +0000 (10:25 -0700)
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.

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.

13 files changed:
gcc/match.pd
gcc/testsuite/gcc.dg/pr110915-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-10.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-11.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-12.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-8.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr110915-9.c [new file with mode: 0644]

index 6a7edde5736affe415e501089229e123dd34d429..c01362ee359218aa9dff6cfb84eec3d351a34dcc 100644 (file)
@@ -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 (file)
index 0000000..2e1e871
--- /dev/null
@@ -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 (file)
index 0000000..b0644bf
--- /dev/null
@@ -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 (file)
index 0000000..0288e53
--- /dev/null
@@ -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 (file)
index 0000000..054a077
--- /dev/null
@@ -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 (file)
index 0000000..3962b15
--- /dev/null
@@ -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 (file)
index 0000000..c6462b5
--- /dev/null
@@ -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 (file)
index 0000000..5b28ccd
--- /dev/null
@@ -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 (file)
index 0000000..a8b871d
--- /dev/null
@@ -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 (file)
index 0000000..a3b9cc0
--- /dev/null
@@ -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 (file)
index 0000000..fd331e9
--- /dev/null
@@ -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 (file)
index 0000000..fae533c
--- /dev/null
@@ -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 (file)
index 0000000..07aa08e
--- /dev/null
@@ -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" } } */
This page took 0.096592 seconds and 5 git commands to generate.