From: Marc Glisse Date: Mon, 24 Apr 2017 19:04:25 +0000 (+0200) Subject: X /[ex] 4 < Y /[ex] 4 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a8492d5ec1d8b90930a7dca04a104bcaec62d035;p=gcc.git X /[ex] 4 < Y /[ex] 4 2017-04-24 Marc Glisse gcc/ * match.pd (X/[ex]C CMP Y/[ex]C): New transformation. gcc/testsuite/ * gcc.dg/tree-ssa/cmpexactdiv-2.c: New file. From-SVN: r247107 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0dd86c12e6c..c1186326334 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2017-04-24 Marc Glisse + + * match.pd (X/[ex]C CMP Y/[ex]C): New transformation. + 2017-04-24 Martin Jambor PR tree-optimization/80293 diff --git a/gcc/match.pd b/gcc/match.pd index 357797877c8..44745df9afa 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1035,6 +1035,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && wi::neg_p (@1, TYPE_SIGN (TREE_TYPE (@1)))) (cmp @2 @0)))))) +/* X / 4 < Y / 4 iff X < Y when the division is known to be exact. */ +(for cmp (simple_comparison) + (simplify + (cmp (exact_div @0 INTEGER_CST@2) (exact_div @1 @2)) + (if (wi::gt_p(@2, 0, TYPE_SIGN (TREE_TYPE (@2)))) + (cmp @0 @1)))) + /* ((X inner_op C0) outer_op C1) With X being a tree where value_range has reasoned certain bits to always be zero throughout its computed value range, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3be6903c7e9..c8d79e3663a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-04-24 Marc Glisse + + * gcc.dg/tree-ssa/cmpexactdiv-2.c: New file. + 2017-04-24 Volker Reichelt * g++.dg/diagnostic/duplicate1.C: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-2.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-2.c new file mode 100644 index 00000000000..e7f11b988c0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized-raw" } */ + +int f (long *a, long *b, long *c) { + __PTRDIFF_TYPE__ l1 = b - a; + __PTRDIFF_TYPE__ l2 = c - a; + return l1 < l2; +} + +/* Eventually we also want to remove all minus_expr. */ +/* { dg-final { scan-tree-dump-not "exact_div_expr" "optimized" } } */