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)

> True, but that really doesn't make any difference.

Of course, the dereference is optimized out by the gimplifier.

You need to set the ref-all flag on p, since the problematic access is p->t:

foo (s)
  struct T * D.1535;
  struct T * p;

  p = (struct T *) s;
  D.1535 = t.t;
  p->t = D.1535;

Aliasing rules are clearly violated after the memcpy optimization so p must be 
ref-all for this to work.  The Ada compiler would automatically set it upon 
parsing the wild (unchecked) conversion:

  p = (struct T *) s;

Minimal patch attached.  In .gimple:

foo (s)
  struct T * {ref-all} p.0;
  struct T * D.1536;
  struct T * p;

  p = (struct T *) s;
  p.0 = (struct T * {ref-all}) p;
  D.1536 = t.t;
  p.0->t = D.1536;
  p.0 = (struct T * {ref-all}) p;

Eric Botcazou
Index: builtins.c
--- builtins.c	(revision 117403)
+++ builtins.c	(working copy)
@@ -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, inner;
   unsigned HOST_WIDE_INT length;
   if (! validate_arglist (arglist,
@@ -8036,6 +8036,20 @@ fold_builtin_memory_op (tree arglist, tr
 	  && !SCALAR_FLOAT_TYPE_P (TREE_TYPE (destvar)))
 	return 0;
+      /* If destvar is a VAR_DECL or a component thereof,
+	 we can use its alias set, otherwise we'd need to make
+	 sure we go through alias set 0. ?*/
+      inner = destvar;
+      while (handled_component_p (inner))
+	inner = TREE_OPERAND (inner, 0);
+      if (TREE_CODE (inner) == INDIRECT_REF)
+	{
+	  tree ref_all
+	    = build_pointer_type_for_mode (TREE_TYPE (inner), ptr_mode, true);
+	  TREE_OPERAND (inner, 0)
+	    = fold_convert (ref_all, TREE_OPERAND (inner, 0));
+	}
       srcvar = src;
       STRIP_NOPS (srcvar);
       if (TREE_CODE (srcvar) != ADDR_EXPR)

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