Message ID | SN2PR0701MB1024E2FD81BA317E4CFFE98F8E820@SN2PR0701MB1024.namprd07.prod.outlook.com |
---|---|
State | New |
Headers | show |
On Thu, Jul 23, 2015 at 5:47 AM, Hurugalawadi, Naveen <Naveen.Hurugalawadi@caviumnetworks.com> wrote: >>> so using wi::mask is prefered here. > > 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? Ok with adding /* { dg-require-effective-target int32 } */ to the testcase. Please omit the +/* Simplify (t * 2)/2 -> t. */ +(simplify + (exact_div (mult @0 INTEGER_CST@1) @1) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + @0)) pattern. As a followup extend it - it shoudl also work for non-INTEGER_CST divisors and it should work for any kind of division, not just exact_div. The key here is TYPE_OVERFLOW_UNDEFINED. I believe you should find the equivalent operation in extract_trunc_div_1. Richard. > Thanks, > Naveen > > 2015-07-22 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com> > > gcc/testsuite/ChangeLog: > PR middle-end/25529 > * gcc.dg/pr25529.c: New test. > > gcc/ChangeLog: > PR middle-end/25529 > * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) : New simplifier. > (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.
diff --git a/gcc/match.pd b/gcc/match.pd index 9a66f52..9c8080f 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,20 @@ 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 (t * 2)/2 -> t. */ +(simplify + (exact_div (mult @0 INTEGER_CST@1) @1) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + @0)) + +/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF. */ +(simplify + (trunc_div (mult @0 integer_pow2p@1) @1) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + (bit_and @0 { wide_int_to_tree + (type, wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (@1), + false, TYPE_PRECISION (type))); }))) + /* X % Y is smaller than Y. */ (for cmp (lt ge) (simplify diff --git a/gcc/testsuite/gcc.dg/pr25529.c b/gcc/testsuite/gcc.dg/pr25529.c new file mode 100644 index 0000000..4d9fe9e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr25529.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 "\& 2147483647" "optimized" } } */
>> so using wi::mask is prefered here. 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.Hurugalawadi@caviumnetworks.com> gcc/testsuite/ChangeLog: PR middle-end/25529 * gcc.dg/pr25529.c: New test. gcc/ChangeLog: PR middle-end/25529 * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) : New simplifier. (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.