diff options
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/match.pd | 21 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/modmod.c | 13 |
4 files changed, 42 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index caf24c22b12..3dec6b10cda 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-05-15 Marc Glisse <marc.glisse@inria.fr> + + PR tree-optimization/64454 + * match.pd ((X % Y) % Y, (X % Y) < Y): New patterns. + (-1 - A -> ~A): Remove unnecessary condition. + 2015-05-15 Gregor Richards <gregor.richards@uwaterloo.ca> * config/i386/linux.h (MUSL_DYNAMIC_LINKER): Define. diff --git a/gcc/match.pd b/gcc/match.pd index fffe6946325..f277fe33cd5 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -211,7 +211,11 @@ along with GCC; see the file COPYING3. If not see (simplify (mod @0 integer_minus_onep@1) (if (!TYPE_UNSIGNED (type)) - { build_zero_cst (type); }))) + { build_zero_cst (type); })) + /* (X % Y) % Y is just X % Y. */ + (simplify + (mod (mod@2 @0 @1) @1) + @2)) /* X % -C is the same as X % C. */ (simplify @@ -224,6 +228,18 @@ along with GCC; see the file COPYING3. If not see && !sign_bit_p (@1, @1)) (trunc_mod @0 (negate @1)))) +/* X % Y is smaller than Y. */ +(for cmp (lt ge) + (simplify + (cmp (trunc_mod @0 @1) @1) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + { constant_boolean_node (cmp == LT_EXPR, type); }))) +(for cmp (gt le) + (simplify + (cmp @1 (trunc_mod @0 @1)) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + { constant_boolean_node (cmp == GT_EXPR, type); }))) + /* x | ~0 -> ~0 */ (simplify (bit_ior @0 integer_all_onesp@1) @@ -533,8 +549,7 @@ along with GCC; see the file COPYING3. If not see /* -1 - A -> ~A */ (simplify (minus integer_all_onesp @0) - (if (TREE_CODE (type) != COMPLEX_TYPE) - (bit_not @0))) + (bit_not @0)) /* (T)(P + A) - (T)P -> (T) A */ (for add (plus pointer_plus) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a9361067c5a..5875476821b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-05-15 Marc Glisse <marc.glisse@inria.fr> + + PR tree-optimization/64454 + * gcc.dg/modmod.c: New testcase. + 2015-05-15 Ilya Enkovich <ilya.enkovich@intel.com> * gcc.dg/lto/chkp-wrap-asm-name_0.c: New. diff --git a/gcc/testsuite/gcc.dg/modmod.c b/gcc/testsuite/gcc.dg/modmod.c new file mode 100644 index 00000000000..577d0aa5462 --- /dev/null +++ b/gcc/testsuite/gcc.dg/modmod.c @@ -0,0 +1,13 @@ +/* { dg-options "-O -fdump-tree-optimized-raw" } */ + +int f(int a, int b){ + a %= b; + return a % b; +} +int g(unsigned a, unsigned b){ + a %= b; + return a < b; +} + +/* { dg-final { scan-tree-dump-times "trunc_mod_expr" 1 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ |