explow.c (maybe_set_unchanging): New function, broken out from...
authorJason Merrill <jason@casey.soma.redhat.com>
Tue, 6 Jun 2000 03:37:50 +0000 (03:37 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 6 Jun 2000 03:37:50 +0000 (23:37 -0400)
        * explow.c (maybe_set_unchanging): New function, broken out from...
        (set_mem_attributes): Here.
        * expr.h: Declare it.
        * stmt.c (expand_decl): Call it.

From-SVN: r34421

gcc/ChangeLog
gcc/explow.c
gcc/expr.h
gcc/stmt.c

index c0040dd62050230eb8630ec32cc98711c93dd76b..bb74239d12abab5815a148f8f0991d571d224c58 100644 (file)
@@ -1,3 +1,10 @@
+2000-06-05  Jason Merrill  <jason@casey.soma.redhat.com>
+
+       * explow.c (maybe_set_unchanging): New function, broken out from...
+       (set_mem_attributes): Here.
+       * expr.h: Declare it.
+       * stmt.c (expand_decl): Call it.
+
 2000-06-05  Richard Henderson  <rth@cygnus.com>
 
        * reload1.c (choose_reload_regs): Mind CLASS_CANNOT_CHANGE_SIZE
index 6ca93bcbffb1b25febb59dd5b45b90c25cc0b103..9f7eada363e09f85a4c9fc59aa2bc886ff4f27d2 100644 (file)
@@ -628,6 +628,27 @@ validize_mem (ref)
   return change_address (ref, GET_MODE (ref), XEXP (ref, 0));
 }
 \f
+/* Given REF, either a MEM or a REG, and T, either the type of X or
+   the expression corresponding to REF, set RTX_UNCHANGING_P if
+   appropriate.  */
+
+void
+maybe_set_unchanging (ref, t)
+     rtx ref;
+     tree t;
+{
+  /* We can set RTX_UNCHANGING_P from TREE_READONLY for decls whose
+     initialization is only executed once, or whose initializer always
+     has the same value.  Currently we simplify this to PARM_DECLs in the
+     first case, and decls with TREE_CONSTANT initializers in the second.  */
+  if ((TREE_READONLY (t) && DECL_P (t)
+       && (TREE_CODE (t) == PARM_DECL
+          || DECL_INITIAL (t) == NULL_TREE
+          || TREE_CONSTANT (DECL_INITIAL (t))))
+      || TREE_CODE_CLASS (TREE_CODE (t)) == 'c')
+    RTX_UNCHANGING_P (ref) = 1;
+}
+
 /* Given REF, a MEM, and T, either the type of X or the expression
    corresponding to REF, set the memory attributes.  OBJECTP is nonzero
    if we are making a new object of this type.  */
@@ -642,8 +663,12 @@ set_mem_attributes (ref, t, objectp)
 
   /* Get the alias set from the expression or type (perhaps using a
      front-end routine) and then copy bits from the type.  */
+
+  /* It is incorrect to set RTX_UNCHANGING_P from TREE_READONLY (type)
+     here, because, in C and C++, the fact that a location is accessed
+     through a const expression does not mean that the value there can
+     never change.  */
   MEM_ALIAS_SET (ref) = get_alias_set (t);
-  RTX_UNCHANGING_P (ref) = TYPE_READONLY (type);
   MEM_VOLATILE_P (ref) = TYPE_VOLATILE (type);
   MEM_IN_STRUCT_P (ref) = AGGREGATE_TYPE_P (type);
 
@@ -657,8 +682,7 @@ set_mem_attributes (ref, t, objectp)
   if (TYPE_P (t))
     return;
 
-  if (TREE_READONLY (t) || TREE_CODE_CLASS (TREE_CODE (t)) == 'c')
-    RTX_UNCHANGING_P (ref) = 1;
+  maybe_set_unchanging (ref, t);
   if (TREE_THIS_VOLATILE (t))
     MEM_VOLATILE_P (ref) = 1;
 
index 852b6c0efe629301f6fb485a83fc3e7463c7c25e..b822ea24815cd37cb60f28448c493798cc34e6ef 100644 (file)
@@ -1150,6 +1150,11 @@ extern rtx change_address PARAMS ((rtx, enum machine_mode, rtx));
 extern rtx validize_mem PARAMS ((rtx));
 
 #ifdef TREE_CODE
+/* Given REF, either a MEM or a REG, and T, either the type of X or
+   the expression corresponding to REF, set RTX_UNCHANGING_P if
+   appropriate.  */
+extern void maybe_set_unchanging PARAMS ((rtx, tree));
+
 /* Given REF, a MEM, and T, either the type of X or the expression
    corresponding to REF, set the memory attributes.  OBJECTP is nonzero
    if we are making a new object of this type.  */
index 5016e67c9f22a6f611dc3b5bf7573b4a5bb01cdd..fe0d58e9a4972388707106c840aaa48ffdc9511f 100644 (file)
@@ -3817,9 +3817,8 @@ expand_decl (decl)
       if (POINTER_TYPE_P (type))
        mark_reg_pointer (DECL_RTL (decl),
                          TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
-                         
-      if (TREE_READONLY (decl))
-       RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
+
+      maybe_set_unchanging (DECL_RTL (decl), decl);
     }
 
   else if (TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST