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: Aliasing: look through pointer's def stmt


On Wed, Oct 30, 2013 at 1:09 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Tue, 29 Oct 2013, Richard Biener wrote:
>
>> For the POINTER_PLUS_EXPR offset argument you should use
>> int_cst_value () to access it (it will unconditionally sign-extend)
>> and use host_integerp (..., 0).  That leaves the overflow possibility
>> in place (and you should multiply by BITS_PER_UNIT) which we
>> ignore in enough other places similar to this to ignore ...
>
>
> Like this? (passes bootstrap+testsuite on x86_64-linux-gnu)
>
> 2013-10-30  Marc Glisse  <marc.glisse@inria.fr>
>
>
> gcc/
>         * tree-ssa-alias.c (ao_ref_init_from_ptr_and_size): Look for a
>         POINTER_PLUS_EXPR in the defining statement.
>
> gcc/testsuite/
>         * gcc.dg/tree-ssa/alias-24.c: New file.
>
>
> --
> Marc Glisse
>
> Index: gcc/testsuite/gcc.dg/tree-ssa/alias-24.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/tree-ssa/alias-24.c    (revision 0)
> +++ gcc/testsuite/gcc.dg/tree-ssa/alias-24.c    (working copy)
> @@ -0,0 +1,22 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +void f (const char *c, int *i)
> +{
> +  *i = 42;
> +  __builtin_memcpy (i + 1, c, sizeof (int));
> +  if (*i != 42) __builtin_abort();
> +}
> +
> +extern void keepit ();
> +void g (const char *c, int *i)
> +{
> +  *i = 33;
> +  __builtin_memcpy (i - 1, c, 3 * sizeof (int));
> +  if (*i != 33) keepit();
> +}
> +
> +/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */
> +/* { dg-final { scan-tree-dump "keepit" "optimized" } } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> +
>
> Property changes on: gcc/testsuite/gcc.dg/tree-ssa/alias-24.c
> ___________________________________________________________________
> Added: svn:keywords
> ## -0,0 +1 ##
> +Author Date Id Revision URL
> \ No newline at end of property
> Added: svn:eol-style
> ## -0,0 +1 ##
> +native
> \ No newline at end of property
> Index: gcc/tree-ssa-alias.c
> ===================================================================
> --- gcc/tree-ssa-alias.c        (revision 204188)
> +++ gcc/tree-ssa-alias.c        (working copy)
> @@ -567,20 +567,29 @@ void
>  ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size)
>  {
>    HOST_WIDE_INT t1, t2;
>    ref->ref = NULL_TREE;
>    if (TREE_CODE (ptr) == SSA_NAME)
>      {
>        gimple stmt = SSA_NAME_DEF_STMT (ptr);
>        if (gimple_assign_single_p (stmt)
>           && gimple_assign_rhs_code (stmt) == ADDR_EXPR)
>         ptr = gimple_assign_rhs1 (stmt);
> +      else if (is_gimple_assign (stmt)
> +              && gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR
> +              && host_integerp (gimple_assign_rhs2 (stmt), 0)
> +              && (t1 = int_cst_value (gimple_assign_rhs2 (stmt))) >= 0)

No need to restrict this to positive offsets I think.

> +       {
> +         ao_ref_init_from_ptr_and_size (ref, gimple_assign_rhs1 (stmt),
> size);

Please don't recurse - forwprop combines series of POINTER_PLUS_EXPRs
and &MEM[ptr, offset] so it shouldn't be necessary.

> +         ref->offset += 8 * t1;

BITS_PER_UNIT instead of 8.  I'd say just have a 0-initialized
additional_offset var that you unconditionally add ...

> +         return;
> +       }
>      }
>
>    if (TREE_CODE (ptr) == ADDR_EXPR)
>      ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0),
>                                          &ref->offset, &t1, &t2);
>    else
>      {
>        ref->base = build2 (MEM_REF, char_type_node,
>                           ptr, null_pointer_node);
>        ref->offset = 0;

... here at the end.

Thanks,
Richard.


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