diff options
author | glisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-05-15 17:34:15 +0000 |
---|---|---|
committer | glisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-05-15 17:34:15 +0000 |
commit | d792dcdf81daf1c9707fff3723084fa66835dabc (patch) | |
tree | c27c4d0fff690de1f31c090ece7b64e6f9c3ce13 /gcc/match.pd | |
parent | ce86a36a01b0debf9288a59bd15f70fc2871f9c0 (diff) | |
download | gcc-d792dcdf81daf1c9707fff3723084fa66835dabc.tar.gz |
2015-05-15 Marc Glisse <marc.glisse@inria.fr>
PR tree-optimization/64454
gcc/
* match.pd ((X % Y) % Y, (X % Y) < Y): New patterns.
(-1 - A -> ~A): Remove unnecessary condition.
gcc/testsuite/
* gcc.dg/modmod.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223221 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 21 |
1 files changed, 18 insertions, 3 deletions
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) |