aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-08-05 09:23:26 -0700
committerAndrew Pinski <apinski@marvell.com>2023-08-07 00:29:43 -0700
commit58f1e185ff6d108171b9c8ea043796c85a65fcec (patch)
tree29c7e8ce110a2fdcb111adf9181e8a18c863f9ec
parent2a0b19f52596d75b349d0eecfce036b2c8f9270f (diff)
downloadgcc-58f1e185ff6d108171b9c8ea043796c85a65fcec.zip
gcc-58f1e185ff6d108171b9c8ea043796c85a65fcec.tar.gz
gcc-58f1e185ff6d108171b9c8ea043796c85a65fcec.tar.bz2
MATCH: Extend min_value/max_value to pointer types
Since we already had the infrastructure to optimize `(x == 0) && (x > y)` to false for integer types, this extends the same to pointer types as indirectly requested by PR 96695. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/96695 * match.pd (min_value, max_value): Extend to pointer types too. gcc/testsuite/ChangeLog: PR tree-optimization/96695 * gcc.dg/pr96695-1.c: New test. * gcc.dg/pr96695-10.c: New test. * gcc.dg/pr96695-11.c: New test. * gcc.dg/pr96695-12.c: New test. * gcc.dg/pr96695-2.c: New test. * gcc.dg/pr96695-3.c: New test. * gcc.dg/pr96695-4.c: New test. * gcc.dg/pr96695-5.c: New test. * gcc.dg/pr96695-6.c: New test. * gcc.dg/pr96695-7.c: New test. * gcc.dg/pr96695-8.c: New test. * gcc.dg/pr96695-9.c: New test.
-rw-r--r--gcc/match.pd6
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-1.c18
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-10.c20
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-11.c18
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-12.c18
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-2.c18
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-3.c20
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-4.c21
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-5.c19
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-6.c20
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-7.c19
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-8.c19
-rw-r--r--gcc/testsuite/gcc.dg/pr96695-9.c20
13 files changed, 234 insertions, 2 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 2278029..de54b17 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2733,12 +2733,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(match min_value
INTEGER_CST
- (if (INTEGRAL_TYPE_P (type)
+ (if ((INTEGRAL_TYPE_P (type)
+ || POINTER_TYPE_P(type))
&& wi::eq_p (wi::to_wide (t), wi::min_value (type)))))
(match max_value
INTEGER_CST
- (if (INTEGRAL_TYPE_P (type)
+ (if ((INTEGRAL_TYPE_P (type)
+ || POINTER_TYPE_P(type))
&& wi::eq_p (wi::to_wide (t), wi::max_value (type)))))
/* x > y && x != XXX_MIN --> x > y
diff --git a/gcc/testsuite/gcc.dg/pr96695-1.c b/gcc/testsuite/gcc.dg/pr96695-1.c
new file mode 100644
index 0000000..d4287ab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-1.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+
+#include <limits.h>
+
+_Bool and1(unsigned *x, unsigned *y)
+{
+ /* x > y && x != 0 --> x > y */
+ return x > y && x != 0;
+}
+
+_Bool and2(unsigned *x, unsigned *y)
+{
+ /* x < y && x != -1 --> x < y */
+ return x < y && x != (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-10.c b/gcc/testsuite/gcc.dg/pr96695-10.c
new file mode 100644
index 0000000..dfe7525
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-10.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include <limits.h>
+
+_Bool or1(unsigned *x, unsigned *y)
+{
+ /* x <= y || x != 0 --> true */
+ return x <= y || x != 0;
+}
+
+_Bool or2(unsigned *x, unsigned *y)
+{
+ /* x >= y || x != -1 --> true */
+ return x >= y || x != (unsigned*)-1;
+}
+
+/* { 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/pr96695-11.c b/gcc/testsuite/gcc.dg/pr96695-11.c
new file mode 100644
index 0000000..d3c3616
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-11.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+
+#include <limits.h>
+
+_Bool or1(unsigned *x, unsigned *y)
+{
+ /* x <= y || x == 0 --> x <= y */
+ return x <= y || x == 0;
+}
+
+_Bool or2(unsigned *x, unsigned *y)
+{
+ /* x >= y || x == -1 --> x >= y */
+ return x >= y || x == (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " == " "ifcombine" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-12.c b/gcc/testsuite/gcc.dg/pr96695-12.c
new file mode 100644
index 0000000..9ce2ddf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-12.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dce3" } */
+
+#include <limits.h>
+
+_Bool or1(unsigned *x, unsigned *y)
+{
+ /* x <= y || x == 0 --> x <= y */
+ return x <= y || x == 0;
+}
+
+_Bool or2(unsigned *x, unsigned *y)
+{
+ /* x >= y || x == -1 --> x >= y */
+ return x >= y || x == (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " == " "dce3" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-2.c b/gcc/testsuite/gcc.dg/pr96695-2.c
new file mode 100644
index 0000000..6d347c3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-2.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include <limits.h>
+
+_Bool and1(unsigned *x, unsigned *y)
+{
+ /* x > y && x != 0 --> x > y */
+ return x > y && x != 0;
+}
+
+_Bool and2(unsigned *x, unsigned *y)
+{
+ /* x < y && x != -1 --> x < y */
+ return x < y && x != (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " != " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-3.c b/gcc/testsuite/gcc.dg/pr96695-3.c
new file mode 100644
index 0000000..b205b27
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-3.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+
+#include <limits.h>
+
+_Bool and1(unsigned *x, unsigned *y)
+{
+ /* x > y && x == 0 --> false */
+ return x > y && x == 0;
+}
+
+_Bool and2(unsigned *x, unsigned *y)
+{
+ /* x < y && x == -1 --> false */
+ return x < y && x == (unsigned*)-1;
+}
+
+/* { 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/pr96695-4.c b/gcc/testsuite/gcc.dg/pr96695-4.c
new file mode 100644
index 0000000..a5aa8de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-4.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include <limits.h>
+
+_Bool and1(unsigned *x, unsigned *y)
+{
+ /* x > y && x == 0 --> false */
+ return x > y && x == 0;
+}
+
+_Bool and2(unsigned *x, unsigned *y)
+{
+ /* x < y && x == -1 --> false */
+ return x < y && x == (unsigned*)-1;
+}
+
+
+/* { 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/pr96695-5.c b/gcc/testsuite/gcc.dg/pr96695-5.c
new file mode 100644
index 0000000..54d8f1a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-5.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+
+#include <limits.h>
+
+_Bool and1(unsigned *x, unsigned *y)
+{
+ /* x <= y && x == 0 --> x == 0 */
+ return x <= y && x == 0;
+}
+
+_Bool and2(unsigned *x, unsigned *y)
+{
+ /* x >= y && x == -1 --> x == -1 */
+ return x >= y && x == (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-6.c b/gcc/testsuite/gcc.dg/pr96695-6.c
new file mode 100644
index 0000000..1574524
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-6.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include <limits.h>
+
+_Bool and1(unsigned *x, unsigned *y)
+{
+ /* x <= y && x == 0 --> x == 0 */
+ return x <= y && x == 0;
+}
+
+_Bool and2(unsigned *x, unsigned *y)
+{
+ /* x >= y && x == -1 --> x == -1 */
+ return x >= y && x == (unsigned*)-1;
+}
+
+
+/* { dg-final { scan-tree-dump-not " <= " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " >= " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-7.c b/gcc/testsuite/gcc.dg/pr96695-7.c
new file mode 100644
index 0000000..7977ae1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-7.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+
+#include <limits.h>
+
+_Bool or1(unsigned *x, unsigned *y)
+{
+ /* x > y || x != 0 --> x != 0 */
+ return x > y || x != 0;
+}
+
+_Bool or2(unsigned *x, unsigned *y)
+{
+ /* x < y || x != -1 --> x != -1 */
+ return x < y || x != (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " > " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " < " "ifcombine" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-8.c b/gcc/testsuite/gcc.dg/pr96695-8.c
new file mode 100644
index 0000000..ecda865
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-8.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include <limits.h>
+
+_Bool or1(unsigned *x, unsigned *y)
+{
+ /* x > y || x != 0 --> x != 0 */
+ return x > y || x != 0;
+}
+
+_Bool or2(unsigned *x, unsigned *y)
+{
+ /* x < y || x != -1 --> x != -1 */
+ return x < y || x != (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " > " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " < " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/pr96695-9.c b/gcc/testsuite/gcc.dg/pr96695-9.c
new file mode 100644
index 0000000..b87522c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96695-9.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+
+#include <limits.h>
+
+_Bool or1(unsigned *x, unsigned *y)
+{
+ /* x <= y || x != 0 --> true */
+ return x <= y || x != 0;
+}
+
+_Bool or2(unsigned *x, unsigned *y)
+{
+ /* x >= y || x != -1 --> true */
+ return x >= y || x != (unsigned*)-1;
+}
+
+/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */