https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67170

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ok, the argument may go like "foo (&D.3438) may not modify *arg_29(D)
because then the fnspec on foo would be incorrect - *arg_29(D) would be
modified".

Untested patch (works for the testcase):

Index: gcc/tree-ssa-alias.c
===================================================================
--- gcc/tree-ssa-alias.c        (revision 226807)
+++ gcc/tree-ssa-alias.c        (working copy)
@@ -2153,6 +2153,33 @@ call_may_clobber_ref_p_1 (gcall *call, a
        return false;
     }

+  /* If the base of an indirect access is a parameter which by means
+     of the fnspec of ourselves not clobbered by us then it is surely
+     not modified by calls we do.  */
+  tree base_ptr;
+  tree fnspec;
+  if (TREE_CODE (base) == MEM_REF
+      && (base_ptr = TREE_OPERAND (base, 0))
+      && TREE_CODE (base_ptr) == SSA_NAME
+      && SSA_NAME_IS_DEFAULT_DEF (base_ptr)
+      && SSA_NAME_VAR (base_ptr)
+      && TREE_CODE (SSA_NAME_VAR (base_ptr)) == PARM_DECL
+      && (fnspec = lookup_attribute ("fn spec",
+                                    TYPE_ATTRIBUTES (TREE_TYPE
(cfun->decl)))))
+    {
+      unsigned i = 0;
+      tree arg;
+      for (arg = DECL_ARGUMENTS (cfun->decl);
+          arg && arg != SSA_NAME_VAR (base_ptr); arg = DECL_CHAIN (arg), ++i)
+       ;
+      gcc_assert (arg == SSA_NAME_VAR (base_ptr));
+      fnspec = TREE_VALUE (TREE_VALUE (fnspec));
+      if ((unsigned) TREE_STRING_LENGTH (fnspec) > i + 1
+         && (TREE_STRING_POINTER (fnspec)[i + 1] == 'R'
+             || TREE_STRING_POINTER (fnspec)[i + 1] == 'r'))
+       return false;
+    }
+
   /* Check if the base variable is call-clobbered.  */
   if (DECL_P (base))
     return pt_solution_includes (gimple_call_clobber_set (call), base);


of course this asks for the argument being marked somehow to avoid the
linear search for its index.  It also requires some thinking on if and
when derived pointers (from the argument) allow similar handling.

A way "simpler" approach would be to change code generation by the Frontend
for scalar pass-by-reference intent-in arguments to load such parameters
at the beginning of the function and further use that load result for
all references to that parameter.

Martin, can you check if the above solves the RA issue it was blocking?

Reply via email to