]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
MATCH: Extend min_value/max_value to pointer types
authorAndrew Pinski <apinski@marvell.com>
Sat, 5 Aug 2023 16:23:26 +0000 (09:23 -0700)
committerAndrew Pinski <apinski@marvell.com>
Mon, 7 Aug 2023 07:29:43 +0000 (00:29 -0700)
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.

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

index 2278029d608bf8082490724005de75336359ae83..de54b17abbabf4f8ef69fc301de9546e70857bfd 100644 (file)
@@ -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 (file)
index 0000000..d4287ab
--- /dev/null
@@ -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 (file)
index 0000000..dfe7525
--- /dev/null
@@ -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 (file)
index 0000000..d3c3616
--- /dev/null
@@ -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 (file)
index 0000000..9ce2ddf
--- /dev/null
@@ -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 (file)
index 0000000..6d347c3
--- /dev/null
@@ -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 (file)
index 0000000..b205b27
--- /dev/null
@@ -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 (file)
index 0000000..a5aa8de
--- /dev/null
@@ -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 (file)
index 0000000..54d8f1a
--- /dev/null
@@ -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 (file)
index 0000000..1574524
--- /dev/null
@@ -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 (file)
index 0000000..7977ae1
--- /dev/null
@@ -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 (file)
index 0000000..ecda865
--- /dev/null
@@ -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 (file)
index 0000000..b87522c
--- /dev/null
@@ -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" } } */