From: Michael Collison Date: Thu, 15 Oct 2015 22:21:22 +0000 (+0000) Subject: 2015-09-30 Michael Collison X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4f7a56926513835ec1f05e8e59e49db938ebfd2a;p=gcc.git 2015-09-30 Michael Collison Andrew Pinski * match.pd ((x < y) && (x < z) -> x < min (y,z), (x > y) and (x > z) -> x > max (y,z)) * testsuite/gcc.dg/tree-ssa/minmax-loopend.c: New test. Co-Authored-By: Andrew Pinski From-SVN: r228854 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fbe7fabcb15..17e690e3324 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-10-16 Michael Collison + Andrew Pinski + + * match.pd ((x < y) && (x < z) -> x < min (y,z), + (x > y) and (x > z) -> x > max (y,z)) + 2015-10-15 Gregor Richards Szabolcs Nagy diff --git a/gcc/match.pd b/gcc/match.pd index e0ecbe2e776..f3813d87b5d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2431,3 +2431,13 @@ along with GCC; see the file COPYING3. If not see (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); } (convert (bit_and (op (convert:utype @0) (convert:utype @1)) (convert:utype @4)))))))) + +/* Transform (@0 < @1 and @0 < @2) to use min, + (@0 > @1 and @0 > @2) to use max */ +(for op (lt le gt ge) + ext (min min max max) + (simplify + (bit_and (op:s @0 @1) (op:s @0 @2)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) + (op @0 (ext @1 @2))))) + diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 181e5e482e0..fa4fb7da29a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-10-16 Michael Collison + Andrew Pinski + + * testsuite/gcc.dg/tree-ssa/minmax-loopend.c: New test. + 2015-10-15 Marek Polacek * gcc.dg/tree-ssa/reassoc-42.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c new file mode 100644 index 00000000000..2e4300c41aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int min_test(long a, long b, long c) { + int cmp1 = a < b; + int cmp2 = a < c; + return cmp1 & cmp2; +} + +int max_test (long a, long b, long c) { + int cmp1 = a > b; + int cmp2 = a > c; + return cmp1 & cmp2; +} + +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */