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]

Patch to set_mem_attributes


Kenner's recent set_mem_attributes change (part of the aliasing patch)
was too agressive about setting RTX_UNCHANGING_P; any node with
TREE_READONLY set was treated as an invariant, which breaks loops
pretty badly; in particular, it broke all the libstdc++ tests and some
C testcases that rth will check in soon.

This patch significantly restricts the situations where we set that
flag to better reflect the state of affairs before Kenner's patch.
See the comment in maybe_set_unchanging.

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.

Index: expr.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/expr.h,v
retrieving revision 1.64
diff -c -p -r1.64 expr.h
*** expr.h	2000/06/03 00:32:58	1.64
--- expr.h	2000/06/06 03:30:22
*************** extern rtx change_address PARAMS ((rtx, 
*** 1150,1155 ****
--- 1150,1160 ----
  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: explow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/explow.c,v
retrieving revision 1.49
diff -c -p -r1.49 explow.c
*** explow.c	2000/05/31 18:36:03	1.49
--- explow.c	2000/06/06 03:30:23
*************** validize_mem (ref)
*** 628,633 ****
--- 628,654 ----
    return change_address (ref, GET_MODE (ref), XEXP (ref, 0));
  }
  
+ /* 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.  */
*************** set_mem_attributes (ref, t, objectp)
*** 642,649 ****
  
    /* Get the alias set from the expression or type (perhaps using a
       front-end routine) and then copy bits from the type.  */
    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);
  
--- 663,674 ----
  
    /* 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);
    MEM_VOLATILE_P (ref) = TYPE_VOLATILE (type);
    MEM_IN_STRUCT_P (ref) = AGGREGATE_TYPE_P (type);
  
*************** set_mem_attributes (ref, t, objectp)
*** 657,664 ****
    if (TYPE_P (t))
      return;
  
!   if (TREE_READONLY (t) || TREE_CODE_CLASS (TREE_CODE (t)) == 'c')
!     RTX_UNCHANGING_P (ref) = 1;
    if (TREE_THIS_VOLATILE (t))
      MEM_VOLATILE_P (ref) = 1;
  
--- 682,688 ----
    if (TYPE_P (t))
      return;
  
!   maybe_set_unchanging (ref, t);
    if (TREE_THIS_VOLATILE (t))
      MEM_VOLATILE_P (ref) = 1;
  
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/stmt.c,v
retrieving revision 1.150
diff -c -p -r1.150 stmt.c
*** stmt.c	2000/06/05 13:16:13	1.150
--- stmt.c	2000/06/06 03:30:25
*************** expand_decl (decl)
*** 3817,3825 ****
        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;
      }
  
    else if (TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST
--- 3817,3824 ----
        if (POINTER_TYPE_P (type))
  	mark_reg_pointer (DECL_RTL (decl),
  			  TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
! 
!       maybe_set_unchanging (DECL_RTL (decl), decl);
      }
  
    else if (TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST

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