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]
Other format: [Raw text]

[PATCH][mem-ref] Re-enable IVOPTs, build MEM_REF instead of TARGET_MEM_REF (help!)


This patch (tries to) enables IVOPTs again and replaces built
TARGET_MEM_REFs with MEM_REFs or INDIRECT_MEM_REFs instead.  It works
nicely apart from IVOPTs sometimes (well, a lot of times) tries
to force me to build a memory access with just an integer index!?

For example with gcc.c-torture/execute/loop-12.c

#2  0x085a1520 in create_mem_ref_raw (bsi=0xbf94494c, type=0xb7c361a0, 
    addr=0xbf9448f8) at 
/home/richard/src/mem-ref/gcc/tree-ssa-address.c:370
warning: Source file is more recent than executable.
370	    ref = build_gimple_mem_ref (INDIRECT_MEM_REF, type, 
addr->base, idx,
(gdb) print *addr
$1 = {symbol = 0x0, base = 0x0, index = 0xb7ca5000, step = 0x0, offset = 
0x0}
(gdb) call debug_tree (addr->index)
 <ssa_name 0xb7ca5000
    type <integer_type 0xb7c36340 unsigned int public unsigned SI
        size <integer_cst 0xb7c28658 constant invariant 32>
        unit size <integer_cst 0xb7c28444 constant invariant 4>
        align 32 symtab 0 alias set -1 canonical type 0xb7c36340 precision 
32 min <integer_cst 0xb7c28674 0> max <integer_cst 0xb7c2863c 4294967295>>
    var <var_decl 0xb7ca6318 ivtmp.37> def_stmt <phi_node 0xb7c92e70>
    version 5>

if I tell it that I don't like this I get the same index with integer
type in addr->base.

Ugh.  Zdenek, can you help me here?  Why does it even start with
this index-only address info?

The patch is not yet applied to the branch.

Thanks,
Richard.


2008-03-09  Richard Guenther  <rguenther@suse.de>

	* gimplify.c (build_gimple_mem_ref): Assert that we get a
	base and an offset.
	* tree-ssa-address.c (create_mem_ref_raw): Take bsi argument,
	built MEM_REF or INDIRECT_MEM_REF properly with optionally
	building an IDX_EXPR.
	(create_mem_ref): Pass bsi to create_mem_ref_raw.
	(maybe_fold_tmr): Likewise.
	* tree-ssa-copy.c (merge_alias_info): Disable type checking,
	losen checking for compatible SMTs.
	* tree-ssa-loop-ivopts.c (copy_ref_info): Copy alias-set
	and alignment information from old MEM_REF, merge alias
	info of the two bases of INDIRECT_MEM_REFs.
	* tree-ssa-loop.c (gate_tree_ssa_loop_ivopts): Enable again.

Index: mem-ref/gcc/gimplify.c
===================================================================
*** mem-ref.orig/gcc/gimplify.c	2008-03-09 18:20:43.000000000 +0100
--- mem-ref/gcc/gimplify.c	2008-03-09 18:21:17.000000000 +0100
*************** build_gimple_mem_ref (enum tree_code cod
*** 3460,3465 ****
--- 3460,3466 ----
  		      alias_set_type alias_set, unsigned int align)
  {
    gcc_assert (code == MEM_REF || code == INDIRECT_MEM_REF);
+   gcc_assert (base != NULL_TREE && offset != NULL_TREE);
    gcc_assert (useless_type_conversion_p (sizetype, TREE_TYPE (offset)));
    gcc_assert (code == MEM_REF || POINTER_TYPE_P (TREE_TYPE (base)));
  
Index: mem-ref/gcc/tree-ssa-address.c
===================================================================
*** mem-ref.orig/gcc/tree-ssa-address.c	2008-03-09 17:00:51.000000000 +0100
--- mem-ref/gcc/tree-ssa-address.c	2008-03-09 18:20:11.000000000 +0100
*************** valid_mem_ref_p (enum machine_mode mode,
*** 322,329 ****
     TARGET_MEM_REF.  */
  
  static tree
! create_mem_ref_raw (tree type, struct mem_address *addr)
  {
    if (!valid_mem_ref_p (TYPE_MODE (type), addr))
      return NULL_TREE;
  
--- 322,332 ----
     TARGET_MEM_REF.  */
  
  static tree
! create_mem_ref_raw (block_stmt_iterator *bsi,
! 		    tree type, struct mem_address *addr)
  {
+   tree ref, idx, offset;
+ 
    if (!valid_mem_ref_p (TYPE_MODE (type), addr))
      return NULL_TREE;
  
*************** create_mem_ref_raw (tree type, struct me
*** 333,341 ****
    if (addr->offset && integer_zerop (addr->offset))
      addr->offset = NULL_TREE;
  
!   return build7 (TARGET_MEM_REF, type,
! 		 addr->symbol, addr->base, addr->index,
! 		 addr->step, addr->offset, NULL, NULL);
  }
  
  /* Returns true if OBJ is an object whose address is a link time constant.  */
--- 336,377 ----
    if (addr->offset && integer_zerop (addr->offset))
      addr->offset = NULL_TREE;
  
!   if (!(cfun->curr_properties & PROP_gimple_lmem))
!     return build7 (TARGET_MEM_REF, type,
! 		   addr->symbol, addr->base, addr->index,
! 		   addr->step, addr->offset, NULL, NULL);
! 
!   /* If required, build an IDX_EXPR for the MEM_REF.  */
!   if (addr->symbol && addr->base && addr->offset)
!     return NULL_TREE;
!   if (addr->symbol && addr->base)
!     offset = addr->base;
!   else
!     offset = addr->offset;
!   idx = NULL_TREE;
!   if (addr->index != NULL_TREE)
!     {
!       tree step = addr->step;
!       if (step == NULL_TREE)
! 	step = size_one_node;
!       if (offset == NULL_TREE)
! 	offset = size_zero_node;
!       idx = fold_build3 (IDX_EXPR, sizetype,
! 			 offset, addr->index, step);
!     }
!   if (idx == NULL_TREE)
!     idx = offset;
!   if (idx == NULL_TREE)
!     idx = size_zero_node;
!   if (addr->symbol)
!     ref = build_gimple_mem_ref (MEM_REF, type, addr->symbol, idx,
! 				get_alias_set (type), 1);
!   else
!     ref = build_gimple_mem_ref (INDIRECT_MEM_REF, type, addr->base, idx,
! 				get_alias_set (type), 1);
!   ref = force_gimple_operand_bsi (bsi, ref, false, NULL_TREE,
! 				  true, BSI_SAME_STMT);
!   return ref;
  }
  
  /* Returns true if OBJ is an object whose address is a link time constant.  */
*************** create_mem_ref (block_stmt_iterator *bsi
*** 576,582 ****
  
    addr_to_parts (addr, &parts);
    gimplify_mem_ref_parts (bsi, &parts);
!   mem_ref = create_mem_ref_raw (type, &parts);
    if (mem_ref)
      return mem_ref;
  
--- 612,618 ----
  
    addr_to_parts (addr, &parts);
    gimplify_mem_ref_parts (bsi, &parts);
!   mem_ref = create_mem_ref_raw (bsi, type, &parts);
    if (mem_ref)
      return mem_ref;
  
*************** create_mem_ref (block_stmt_iterator *bsi
*** 592,598 ****
  				true, NULL_TREE, true, BSI_SAME_STMT);
        parts.step = NULL_TREE;
    
!       mem_ref = create_mem_ref_raw (type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
--- 628,634 ----
  				true, NULL_TREE, true, BSI_SAME_STMT);
        parts.step = NULL_TREE;
    
!       mem_ref = create_mem_ref_raw (bsi, type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
*************** create_mem_ref (block_stmt_iterator *bsi
*** 627,633 ****
  	parts.base = tmp;
        parts.symbol = NULL_TREE;
  
!       mem_ref = create_mem_ref_raw (type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
--- 663,669 ----
  	parts.base = tmp;
        parts.symbol = NULL_TREE;
  
!       mem_ref = create_mem_ref_raw (bsi, type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
*************** create_mem_ref (block_stmt_iterator *bsi
*** 648,654 ****
  	parts.base = parts.index;
        parts.index = NULL_TREE;
  
!       mem_ref = create_mem_ref_raw (type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
--- 684,690 ----
  	parts.base = parts.index;
        parts.index = NULL_TREE;
  
!       mem_ref = create_mem_ref_raw (bsi, type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
*************** create_mem_ref (block_stmt_iterator *bsi
*** 670,676 ****
  
        parts.offset = NULL_TREE;
  
!       mem_ref = create_mem_ref_raw (type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
--- 706,712 ----
  
        parts.offset = NULL_TREE;
  
!       mem_ref = create_mem_ref_raw (bsi, type, &parts);
        if (mem_ref)
  	return mem_ref;
      }
*************** maybe_fold_tmr (tree ref)
*** 759,765 ****
    if (!changed)
      return NULL_TREE;
    
!   ret = create_mem_ref_raw (TREE_TYPE (ref), &addr);
    if (!ret)
      return NULL_TREE;
  
--- 795,801 ----
    if (!changed)
      return NULL_TREE;
    
!   ret = create_mem_ref_raw (NULL, TREE_TYPE (ref), &addr);
    if (!ret)
      return NULL_TREE;
  
Index: mem-ref/gcc/tree-ssa-copy.c
===================================================================
*** mem-ref.orig/gcc/tree-ssa-copy.c	2008-03-09 18:37:15.000000000 +0100
--- mem-ref/gcc/tree-ssa-copy.c	2008-03-09 18:37:19.000000000 +0100
*************** merge_alias_info (tree orig_name, tree n
*** 224,230 ****
  	      && POINTER_TYPE_P (TREE_TYPE (new_name)));
  
  #if defined ENABLE_CHECKING
!   gcc_assert (useless_type_conversion_p (TREE_TYPE (orig_name),
  					TREE_TYPE (new_name)));
  
    /* Check that flow-sensitive information is compatible.  Notice that
--- 224,233 ----
  	      && POINTER_TYPE_P (TREE_TYPE (new_name)));
  
  #if defined ENABLE_CHECKING
!   /* ???  IVOPTs messes with pointers too much, so disable the
!      following.  Alternatively we could add a "force" parameter to
!      this function.  */
!   gcc_assert (1 || useless_type_conversion_p (TREE_TYPE (orig_name),
  					TREE_TYPE (new_name)));
  
    /* Check that flow-sensitive information is compatible.  Notice that
*************** merge_alias_info (tree orig_name, tree n
*** 269,276 ****
      }
  #endif
  
!   /* Synchronize the symbol tags.  If both pointers had a tag and they
!      are different, then something has gone wrong.  Symbol tags can
       always be merged because they are flow insensitive, all the SSA
       names of the same base DECL share the same symbol tag.  */
    if (new_ann->symbol_mem_tag == NULL_TREE)
--- 272,280 ----
      }
  #endif
  
!   /* Synchronize the symbol tags.  If both pointers had a tag and any
!      access conflicting with the old set does not conflict with the
!      new set, then something has gone wrong.  Symbol tags can
       always be merged because they are flow insensitive, all the SSA
       names of the same base DECL share the same symbol tag.  */
    if (new_ann->symbol_mem_tag == NULL_TREE)
*************** merge_alias_info (tree orig_name, tree n
*** 278,284 ****
    else if (orig_ann->symbol_mem_tag == NULL_TREE)
      orig_ann->symbol_mem_tag = new_ann->symbol_mem_tag;
    else
!     gcc_assert (new_ann->symbol_mem_tag == orig_ann->symbol_mem_tag);
  
    /* Copy flow-sensitive alias information in case that NEW_NAME
       didn't get a NMT but was set to pt_anything for optimization
--- 282,293 ----
    else if (orig_ann->symbol_mem_tag == NULL_TREE)
      orig_ann->symbol_mem_tag = new_ann->symbol_mem_tag;
    else
!     {
!       alias_set_type new_set = get_alias_set (new_ann->symbol_mem_tag);
!       alias_set_type orig_set = get_alias_set (orig_ann->symbol_mem_tag);
!       gcc_assert (orig_set == new_set
! 		  || alias_set_subset_of (orig_set, new_set));
!     }
  
    /* Copy flow-sensitive alias information in case that NEW_NAME
       didn't get a NMT but was set to pt_anything for optimization
Index: mem-ref/gcc/tree-ssa-loop-ivopts.c
===================================================================
*** mem-ref.orig/gcc/tree-ssa-loop-ivopts.c	2008-03-09 17:27:06.000000000 +0100
--- mem-ref/gcc/tree-ssa-loop-ivopts.c	2008-03-09 18:01:18.000000000 +0100
*************** copy_ref_info (tree new_ref, tree old_re
*** 5188,5193 ****
--- 5188,5203 ----
  {
    if (TREE_CODE (old_ref) == TARGET_MEM_REF)
      copy_mem_ref_info (new_ref, old_ref);
+   else if (cfun->curr_properties & PROP_gimple_lmem)
+     {
+       /* Copy MEM_REF_ALIAS_SET and MEM_REF_ALIGN.  */
+       TREE_OPERAND (new_ref, 2) = TREE_OPERAND (old_ref, 2);
+       TREE_OPERAND (new_ref, 3) = TREE_OPERAND (old_ref, 3);
+       if (TREE_CODE (new_ref) == INDIRECT_MEM_REF
+ 	  && TREE_CODE (old_ref) == INDIRECT_MEM_REF)
+ 	merge_alias_info (TREE_OPERAND (old_ref, 0),
+ 			  TREE_OPERAND (new_ref, 0));
+     }
    else
      {
        TMR_ORIGINAL (new_ref) = unshare_and_remove_ssa_names (old_ref);
Index: mem-ref/gcc/tree-ssa-loop.c
===================================================================
*** mem-ref.orig/gcc/tree-ssa-loop.c	2008-03-09 16:57:59.000000000 +0100
--- mem-ref/gcc/tree-ssa-loop.c	2008-03-09 16:58:17.000000000 +0100
*************** tree_ssa_loop_ivopts (void)
*** 554,562 ****
  static bool
  gate_tree_ssa_loop_ivopts (void)
  {
!   return flag_ivopts != 0
! 	 /* ???  MEM_REF  */
! 	 && !(cfun->curr_properties & PROP_gimple_lmem);
  }
  
  struct tree_opt_pass pass_iv_optimize =
--- 554,560 ----
  static bool
  gate_tree_ssa_loop_ivopts (void)
  {
!   return flag_ivopts != 0;
  }
  
  struct tree_opt_pass pass_iv_optimize =


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