[PATCH] Fix mem-ref related oversights

Richard Guenther rguenther@suse.de
Mon Nov 22 15:37:00 GMT 2010


While working on another patch I noticed the following.  Bootstrapped
and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2010-11-22  Richard Guenther  <rguenther@suse.de>

	* gimple-fold.c (maybe_fold_reference): When canonicalizing
	MEM_REFs, preserve volatileness.
	* cgraphbuild.c (mark_address): Properly check for FUNCTION_DECL
	addresses.

Index: gcc/gimple-fold.c
===================================================================
*** gcc/gimple-fold.c	(revision 167026)
--- gcc/gimple-fold.c	(working copy)
*************** maybe_fold_reference (tree expr, bool is
*** 600,614 ****
      }
    /* Canonicalize MEM_REFs invariant address operand.  */
    else if (TREE_CODE (*t) == MEM_REF
! 	   && TREE_CODE (TREE_OPERAND (*t, 0)) == ADDR_EXPR
! 	   && !DECL_P (TREE_OPERAND (TREE_OPERAND (*t, 0), 0))
! 	   && !CONSTANT_CLASS_P (TREE_OPERAND (TREE_OPERAND (*t, 0), 0)))
      {
        tree tem = fold_binary (MEM_REF, TREE_TYPE (*t),
  			      TREE_OPERAND (*t, 0),
  			      TREE_OPERAND (*t, 1));
        if (tem)
  	{
  	  *t = tem;
  	  tem = maybe_fold_reference (expr, is_lhs);
  	  if (tem)
--- 600,614 ----
      }
    /* Canonicalize MEM_REFs invariant address operand.  */
    else if (TREE_CODE (*t) == MEM_REF
! 	   && !is_gimple_mem_ref_addr (TREE_OPERAND (*t, 0)))
      {
+       bool volatile_p = TREE_THIS_VOLATILE (*t);
        tree tem = fold_binary (MEM_REF, TREE_TYPE (*t),
  			      TREE_OPERAND (*t, 0),
  			      TREE_OPERAND (*t, 1));
        if (tem)
  	{
+ 	  TREE_THIS_VOLATILE (tem) = volatile_p;
  	  *t = tem;
  	  tem = maybe_fold_reference (expr, is_lhs);
  	  if (tem)
Index: gcc/cgraphbuild.c
===================================================================
*** gcc/cgraphbuild.c	(revision 167026)
--- gcc/cgraphbuild.c	(working copy)
*************** static bool
*** 237,242 ****
--- 237,243 ----
  mark_address (gimple stmt ATTRIBUTE_UNUSED, tree addr,
  	      void *data ATTRIBUTE_UNUSED)
  {
+   addr = get_base_address (addr);
    if (TREE_CODE (addr) == FUNCTION_DECL)
      {
        struct cgraph_node *node = cgraph_node (addr);
*************** mark_address (gimple stmt ATTRIBUTE_UNUS
*** 245,268 ****
  			    node, NULL,
  			    IPA_REF_ADDR, stmt);
      }
!   else
      {
!       addr = get_base_address (addr);
!       if (addr && TREE_CODE (addr) == VAR_DECL
! 	  && (TREE_STATIC (addr) || DECL_EXTERNAL (addr)))
! 	{
! 	  struct varpool_node *vnode = varpool_node (addr);
! 	  int walk_subtrees;
  
! 	  if (lang_hooks.callgraph.analyze_expr)
! 	    lang_hooks.callgraph.analyze_expr (&addr, &walk_subtrees);
! 	  varpool_mark_needed_node (vnode);
! 	  if (vnode->alias && vnode->extra_name)
! 	    vnode = vnode->extra_name;
! 	  ipa_record_reference ((struct cgraph_node *)data, NULL,
! 				NULL, vnode,
! 				IPA_REF_ADDR, stmt);
! 	}
      }
  
    return false;
--- 246,265 ----
  			    node, NULL,
  			    IPA_REF_ADDR, stmt);
      }
!   else if (addr && TREE_CODE (addr) == VAR_DECL
! 	   && (TREE_STATIC (addr) || DECL_EXTERNAL (addr)))
      {
!       struct varpool_node *vnode = varpool_node (addr);
!       int walk_subtrees;
  
!       if (lang_hooks.callgraph.analyze_expr)
! 	lang_hooks.callgraph.analyze_expr (&addr, &walk_subtrees);
!       varpool_mark_needed_node (vnode);
!       if (vnode->alias && vnode->extra_name)
! 	vnode = vnode->extra_name;
!       ipa_record_reference ((struct cgraph_node *)data, NULL,
! 			    NULL, vnode,
! 			    IPA_REF_ADDR, stmt);
      }
  
    return false;



More information about the Gcc-patches mailing list