From 182f37c9ac733391323494e5f0ee394a0a065b27 Mon Sep 17 00:00:00 2001 From: "Naveen H.S" Date: Wed, 21 Dec 2016 08:37:47 +0000 Subject: [PATCH] match.pd (max:c @0 (plus@2 @0 INTEGER_CST@1)): New Pattern. 2016-12-22 Andrew Pinski Naveen H.S 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 --- gcc/ChangeLog | 5 +++++ gcc/match.pd | 18 ++++++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/max.c | 22 ++++++++++++++++++++++ gcc/testsuite/gcc.dg/min.c | 22 ++++++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/max.c create mode 100644 gcc/testsuite/gcc.dg/min.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 156408f2f10..bd41f389d22 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-12-22 Andrew Pinski + + * 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 * common.opt (excess_precision): Tag as SetByCombined. diff --git a/gcc/match.pd b/gcc/match.pd index f4cc2d810c3..1570ac82784 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 f06c53c9430..be5673d69ea 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-12-22 Naveen H.S + + * gcc.dg/max.c: New Testcase. + * gcc.dg/min.c: New Testcase. + 2016-12-21 Jakub Jelinek PR c/77767 diff --git a/gcc/testsuite/gcc.dg/max.c b/gcc/testsuite/gcc.dg/max.c new file mode 100644 index 00000000000..e9798104228 --- /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 00000000000..d8472702e9c --- /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" } } */ -- 2.30.2