This is the mail archive of the 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: [PATCH] Fix the one entry mem{{,p}cpy,move,set} optimization aliasing issues (PR middle-end/29272)

On Tue, Oct 03, 2006 at 02:06:37PM -0400, Diego Novillo wrote:
> Eric Botcazou wrote on 10/03/06 14:02:
> >> That should suffice for the TBAA alias checks done at the RTL level.
> >> The tree level doesn't check the alias set, but presumably we can do
> >> something similar if necessary.
> > 
> > TYPE_REF_CAN_ALIAS_ALL works both at the Tree and the RTL level.
> > 
> But you don't want to punish all the pointers of that type.  Unless, a
> new type was created for that pointer.  DECL_POINTER_ALIAS_SET may be
> good enough.

I tried:

--- builtins.c.jj       2006-10-04 10:59:46.000000000 +0200
+++ builtins.c  2006-10-04 11:52:29.000000000 +0200
@@ -7995,7 +7995,7 @@ fold_builtin_bzero (tree arglist, bool i
 static tree
 fold_builtin_memory_op (tree arglist, tree type, bool ignore, int endp)
-  tree dest, src, len, destvar, srcvar, expr;
+  tree dest, src, len, destvar, srcvar, expr, desttype, srctype;
   unsigned HOST_WIDE_INT length;

   if (! validate_arglist (arglist,
@@ -8059,6 +8059,18 @@ fold_builtin_memory_op (tree arglist, tr
             < (int) length)
        return 0;

+      desttype = build_pointer_type_for_mode (TREE_TYPE (destvar),
+                                             ptr_mode, true);
+      destvar = build_fold_addr_expr (destvar);
+      destvar = fold_convert (desttype, destvar);
+      destvar = build1 (INDIRECT_REF, TREE_TYPE (desttype), destvar);
+      srctype = build_pointer_type_for_mode (TREE_TYPE (srcvar),
+                                            ptr_mode, true);
+      srcvar = build_fold_addr_expr (srcvar);
+      srcvar = fold_convert (srctype, srcvar);
+      srcvar = build1 (INDIRECT_REF, TREE_TYPE (srctype), srcvar);
       if ((INTEGRAL_TYPE_P (TREE_TYPE (srcvar))
           || POINTER_TYPE_P (TREE_TYPE (srcvar)))
          && (INTEGRAL_TYPE_P (TREE_TYPE (destvar))

but in all testcases I tried the ref_all pointer was very quickly
optimized away (I tried both testcases from
and the
testcase too).  While tree_ssa_useless_type_conversion honors ref_all differences,
STRIP_NOPS etc. don't.
IMHO we certainly don't want to do this kind of thing if destvar and srcvar's
base is a VAR_DECL - in that case it is safe (at least in C and Mike would
need to prove otherwise for C++) to use the VAR_DECL's alias set and if
we force a pointer, we suddenly loose the biggest advantage of the optimization
- that some objects can avoid being addressable and aren't unnecessarily forced
into stack.
And for the rest - pointers - I'm not sure how to preserve the alias set 0
access throughout the optimizers.  ref_all I have tried, for DECL_POINTER_ALIAS_SET () = 0
I'd need to create a temporary in the non-gimple trees fold_builtin returns
and I doubt it would be any better than ref_all, DECL_POINTER_ALIAS_SET isn't
considered anywhere beyond alias.c, so there isn't even something like
the ref_all check in tree_ssa_useless_type_conversion.


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