This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Handle a + ~a in reassoc


On Tue, Apr 13, 2010 at 5:19 PM, Alexander Monakov <amonakov@ispras.ru> wrote:
> Hi,
>
> This implements folding of (a + ~a) in tree-ssa-reassoc.c. ?As the testcase
> suggests, this should slightly clean up Fortran code after iv-opts
> (unfortunately, it only helps in relatively simple cases since reassoc does
> not touch operands with multiple uses).
>
> Bootstrapped and regtested on x86_64-linux. ?OK for trunk?

A better place for this kind of tree-combining is tree-ssa-forwprop.c
where we already do similar kinds of tricks (and are not limited to
single uses).

Richard.

> 2010-04-13 ?Alexander Monakov ?<amonakov@ispras.ru>
>
> ? ? ? ?* tree-ssa-reassoc.c (eliminate_plus_minus_pair): Handle BIT_NOT_EXPR
> ? ? ? ?to simplify a + ~a.
>
> ? ? ? ?* gfortran.dg/reassoc_6.f: New testcase.
>
> diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
> index cf05de5..54a0413 100644
> --- a/gcc/tree-ssa-reassoc.c
> +++ b/gcc/tree-ssa-reassoc.c
> @@ -482,6 +482,7 @@ eliminate_plus_minus_pair (enum tree_code opcode,
> ? ? ? ? ? ? ? ? ? ? ? ? ? operand_entry_t curr)
> ?{
> ? tree negateop;
> + ?tree notop;
> ? unsigned int i;
> ? operand_entry_t oe;
>
> @@ -489,7 +490,8 @@ eliminate_plus_minus_pair (enum tree_code opcode,
> ? ? return false;
>
> ? negateop = get_unary_op (curr->op, NEGATE_EXPR);
> - ?if (negateop == NULL_TREE)
> + ?notop = get_unary_op (curr->op, BIT_NOT_EXPR);
> + ?if (negateop == NULL_TREE && notop == NULL_TREE)
> ? ? return false;
>
> ? /* Any non-negated version will have a rank that is one less than
> @@ -521,6 +523,28 @@ eliminate_plus_minus_pair (enum tree_code opcode,
>
> ? ? ? ? ?return true;
> ? ? ? ?}
> + ? ? ?else if (oe->op == notop)
> + ? ? ? {
> + ? ? ? ? tree op_type = TREE_TYPE (oe->op);
> +
> + ? ? ? ? if (dump_file && (dump_flags & TDF_DETAILS))
> + ? ? ? ? ? {
> + ? ? ? ? ? ? fprintf (dump_file, "Equivalence: ");
> + ? ? ? ? ? ? print_generic_expr (dump_file, notop, 0);
> + ? ? ? ? ? ? fprintf (dump_file, " + ~");
> + ? ? ? ? ? ? print_generic_expr (dump_file, oe->op, 0);
> + ? ? ? ? ? ? fprintf (dump_file, " -> -1\n");
> + ? ? ? ? ? }
> +
> + ? ? ? ? VEC_ordered_remove (operand_entry_t, *ops, i);
> + ? ? ? ? add_to_ops_vec (ops,
> + ? ? ? ? ? ? ? ? ? ? ? ? build_low_bits_mask (op_type,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE_PRECISION (op_type)));
> + ? ? ? ? VEC_ordered_remove (operand_entry_t, *ops, currindex);
> + ? ? ? ? reassociate_stats.ops_eliminated ++;
> +
> + ? ? ? ? return true;
> + ? ? ? }
> ? ? }
>
> ? /* CURR->OP is a negate expr in a plus expr: save it for later
>
> diff --git a/gcc/testsuite/gfortran.dg/reassoc_6.f b/gcc/testsuite/gfortran.dg/reassoc_6.f
> new file mode 100644
> index 0000000..cbc36f5
> --- /dev/null
> +++ b/gcc/testsuite/gfortran.dg/reassoc_6.f
> @@ -0,0 +1,20 @@
> +! { dg-do compile }
> +! { dg-options "-O2 -fdump-tree-optimized" }
> +
> + ? ? ? ?subroutine test(nb,nx,r2)
> + ? ? ? ?implicit none
> + ? ? ? ?integer nb,nx,i,l
> + ? ? ? ?real*8 r2(nb,nx)
> +
> +
> + ? ? ? ? ? ? do i=1,nx
> + ? ? ? ? ? ? ? ?do l=1,nb
> + ? ? ? ? ? ? ? ? ? r2(l,i)=0.0d0
> + ? ? ? ? ? ? ? ?enddo
> + ? ? ? ? ? ? enddo
> +
> + ? ? ? ?return
> + ? ? ? ?end
> +! Verify that offset of the first element is simplified
> +! { dg-final { scan-tree-dump-not "~" "optimized" } }
> +! { dg-final { cleanup-tree-dump "optimized" } }
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]