>> Your previous patch correctly restricted this to unsigned types. Thanks for your review and comments.
Please find attached the modified patch as per your comments. Please let me know if this version is okay? Thanks, Naveen 2015-07-22 Naveen H.S <naveen.hurugalaw...@caviumnetworks.com> gcc/testsuite/ChangeLog: PR middle-end/25530 * gcc.dg/pr25530.c: New test. gcc/ChangeLog: PR middle-end/25530 * match.pd (mult (trunc_div @0 integer_pow2p@1) @1) : New simplifier.
diff --git a/gcc/match.pd b/gcc/match.pd index 9a66f52..6c37a20 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -29,7 +29,8 @@ along with GCC; see the file COPYING3. If not see integer_each_onep integer_truep real_zerop real_onep real_minus_onep CONSTANT_CLASS_P - tree_expr_nonnegative_p) + tree_expr_nonnegative_p + integer_pow2p) /* Operator lists. */ (define_operator_list tcc_comparison @@ -280,6 +281,12 @@ along with GCC; see the file COPYING3. If not see && integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0) (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))))) +/* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1. */ +(simplify + (mult (trunc_div @0 integer_pow2p@1) @1) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + (bit_and @0 (negate @1)))) + /* X % Y is smaller than Y. */ (for cmp (lt ge) (simplify diff --git a/gcc/testsuite/gcc.dg/pr25530.c b/gcc/testsuite/gcc.dg/pr25530.c new file mode 100644 index 0000000..f180768 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr25530.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int +f (unsigned t) +{ + return (t / 2) * 2; +} + +/* { dg-final { scan-tree-dump "\& -2" "optimized" } } */