aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaveen H.S <naveenh@gcc.gnu.org>2016-12-21 08:37:47 +0000
committerNaveen H.S <naveenh@gcc.gnu.org>2016-12-21 08:37:47 +0000
commit182f37c9ac733391323494e5f0ee394a0a065b27 (patch)
treece38343c14f2c6bf2a64434cb40493a12d00cd0d
parent899614c10b3e214e0a5f9699565e83ba1627213b (diff)
downloadgcc-182f37c9ac733391323494e5f0ee394a0a065b27.zip
gcc-182f37c9ac733391323494e5f0ee394a0a065b27.tar.gz
gcc-182f37c9ac733391323494e5f0ee394a0a065b27.tar.bz2
match.pd (max:c @0 (plus@2 @0 INTEGER_CST@1)): New Pattern.
2016-12-22 Andrew Pinski <apinski@cavium.com> Naveen H.S <Naveen.Hurugalawadi@cavium.com> gcc * match.pd (max:c @0 (plus@2 @0 INTEGER_CST@1)): New Pattern. (min:c @0 (plus@2 @0 INTEGER_CST@1)) : New Pattern. gcc/testsuite * gcc.dg/max.c: New Testcase. * gcc.dg/min.c: New Testcase. From-SVN: r243838
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/match.pd18
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/max.c22
-rw-r--r--gcc/testsuite/gcc.dg/min.c22
5 files changed, 72 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 156408f..bd41f38 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2016-12-22 Andrew Pinski <apinski@cavium.com>
+
+ * match.pd (max:c @0 (plus@2 @0 INTEGER_CST@1)): New Pattern.
+ (min:c @0 (plus@2 @0 INTEGER_CST@1)) : New Pattern.
+
2016-12-20 James Greenhalgh <james.greenhalghj@arm.com>
* common.opt (excess_precision): Tag as SetByCombined.
diff --git a/gcc/match.pd b/gcc/match.pd
index f4cc2d8..1570ac8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1373,6 +1373,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& operand_equal_p (@1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST))
@0)))
+/* max (a, a + CST) -> a + CST where CST is positive. */
+/* max (a, a + CST) -> a where CST is negative. */
+(simplify
+ (max:c @0 (plus@2 @0 INTEGER_CST@1))
+ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+ (if (tree_int_cst_sgn (@1) > 0)
+ @2
+ @0)))
+
+/* min (a, a + CST) -> a where CST is positive. */
+/* min (a, a + CST) -> a + CST where CST is negative. */
+(simplify
+ (min:c @0 (plus@2 @0 INTEGER_CST@1))
+ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+ (if (tree_int_cst_sgn (@1) > 0)
+ @0
+ @2)))
+
/* (convert (minmax ((convert (x) c)))) -> minmax (x c) if x is promoted
and the outer convert demotes the expression back to x's type. */
(for minmax (min max)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f06c53c..be5673d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-12-22 Naveen H.S <Naveen.Hurugalawadi@cavium.com>
+
+ * gcc.dg/max.c: New Testcase.
+ * gcc.dg/min.c: New Testcase.
+
2016-12-21 Jakub Jelinek <jakub@redhat.com>
PR c/77767
diff --git a/gcc/testsuite/gcc.dg/max.c b/gcc/testsuite/gcc.dg/max.c
new file mode 100644
index 0000000..e979810
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/max.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+static inline int
+max (int a, int b)
+{
+ return a < b ? b : a;
+}
+
+int
+test_00 (int a)
+{
+ return max (a, a + 8);
+}
+
+int
+test_01 (int a)
+{
+ return max (a, a - 8);
+}
+
+/* { dg-final { scan-tree-dump-not "MAX_EXPR" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/min.c b/gcc/testsuite/gcc.dg/min.c
new file mode 100644
index 0000000..d847270
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/min.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+static inline int
+min (int a, int b)
+{
+ return a < b ? a : b;
+}
+
+int
+test_00 (int a)
+{
+ return min (a, a + 8);
+}
+
+int
+test_01 (int a)
+{
+ return min (a, a - 8);
+}
+
+/* { dg-final { scan-tree-dump-not "MIN_EXPR" "optimized" } } */