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]

[tree-ssa] Improve aliasing and optimizing constant string reads (again)


While looking at missed optimization opportunities for the dominator
optimizer I ran across cases where we had set up a may alias relationship
between an object which was stored and an object in readonly memory.
We can't ever have an interesting alias relationship between such objects.

By not setting up these may-alias relationships we get slightly better
alias info -- which results in fewer virtual operands which speeds up
the compiler in slight measurable ways.  Unfortunately, the reduction
in may-alias relationships only resulted in removal of on additional
redundant load in my tests (sigh).

The second hunk re-introduces optimization of reads from constant strings,
but does so inside fold_stmt, which is only used late enough that we don't
have to worry about *&"foo" sillyness.

	* tree-dfa.c (compute_alias_sets): A memory tag used for stores can
	not conflict with objects marked TREE_READONLY.

	* tree-ssa-ccp.c (fold_stmt): Optimize reads from constant strings.

Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.147
diff -c -3 -p -r1.1.4.147 tree-dfa.c
*** tree-dfa.c	21 Aug 2003 07:44:57 -0000	1.1.4.147
--- tree-dfa.c	22 Aug 2003 23:18:44 -0000
*************** compute_alias_sets (void)
*** 1921,1926 ****
--- 1921,1930 ----
  	  if (!mem_ann->is_stored && !v_ann->is_stored)
  	    continue;
  	     
+ 	  /* Skip memory tags which are written if the variable is readonly.  */
+ 	  if (mem_ann->is_stored && TREE_READONLY (var->var))
+ 	    continue;
+ 
  	  if (may_alias_p (ptr->var, ptr->set, var->var, var->set))
  	    {
  	      /* If MEM has less than 5 aliases in its alias set, add
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.84
diff -c -3 -p -r1.1.2.84 tree-ssa-ccp.c
*** tree-ssa-ccp.c	11 Aug 2003 21:30:34 -0000	1.1.2.84
--- tree-ssa-ccp.c	22 Aug 2003 23:18:48 -0000
*************** fold_stmt (tree *stmt_p)
*** 1296,1301 ****
--- 1296,1323 ----
  	    result = ccp_fold_builtin (stmt, rhs);
  	}
  
+       /* Optimize *"foo" into 'f'.  This is done here rather than
+          in fold to avoid problems with stuff like &*"foo".  */
+       if (TREE_CODE (rhs) == INDIRECT_REF)
+ 	{
+ 	  tree exp1 = TREE_OPERAND (rhs, 0);
+ 	  tree index;
+ 	  tree string = string_constant (exp1, &index);
+ 
+ 	  if (string
+ 	      && TREE_CODE (string) == STRING_CST
+ 	      && TREE_CODE (index) == INTEGER_CST
+ 	      && compare_tree_int (index, TREE_STRING_LENGTH (string)) < 0
+ 	      && TREE_CODE (TREE_TYPE (string)) == ARRAY_TYPE
+ 	      && (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_TYPE (string))))
+ 		  == MODE_INT)
+ 	      && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (string))))
+ 		  == 1))
+ 	    result = build_int_2 ((TREE_STRING_POINTER (string)
+ 				   [TREE_INT_CST_LOW (index)]), 0);
+ 	}
+ 	  
+ 
        /* If we couldn't fold the RHS, hand it over to the generic fold
  	 routines.  */
        if (result == NULL_TREE)





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