diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2015-05-15 19:34:15 +0200 |
---|---|---|
committer | Marc Glisse <glisse@gcc.gnu.org> | 2015-05-15 17:34:15 +0000 |
commit | bc4315fbb0075e29d9a246bf73ff4c56ccf8fa6b (patch) | |
tree | c27c4d0fff690de1f31c090ece7b64e6f9c3ce13 | |
parent | ff935d0c3d1ace1b6d7acbd24d414e0d8977103e (diff) | |
download | gcc-bc4315fbb0075e29d9a246bf73ff4c56ccf8fa6b.zip gcc-bc4315fbb0075e29d9a246bf73ff4c56ccf8fa6b.tar.gz gcc-bc4315fbb0075e29d9a246bf73ff4c56ccf8fa6b.tar.bz2 |
re PR tree-optimization/64454 (optimize (x%5)%5)
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.
From-SVN: r223221
-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 caf24c2..3dec6b1 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 fffe694..f277fe3 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 a936106..5875476 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 0000000..577d0aa --- /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" } } */ |