Patchwork Fix PR44824

login
register
mail settings
Submitter Richard Guenther
Date July 14, 2010, 12:17 p.m.
Message ID <alpine.LNX.2.00.1007141415090.1429@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/58883/
State New
Headers show

Comments

Richard Guenther - July 14, 2010, 12:17 p.m.
Appearantly somebody decided that some VAR_DECLs do not have function
invariant addresses.  This makes them unsuitable for the first operand
of MEM_REFs and thus we shouldn't create these invalid MEM_REFs from
forwprop.

Even though I question that predicates result the following fixes
forwprop to deal with this.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2010-07-14  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/44824
	* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Use
	is_gimple_mem_ref_addr.
	(tree_ssa_forward_propagate_single_use_vars): Do not propagate
	non-decl_address_invariant_p addresses.

Patch

Index: gcc/tree-ssa-forwprop.c
===================================================================
--- gcc/tree-ssa-forwprop.c	(revision 162140)
+++ gcc/tree-ssa-forwprop.c	(working copy)
@@ -804,9 +804,7 @@  forward_propagate_addr_expr_1 (tree name
 				 fold_convert (ptr_type_node,
 					       gimple_assign_rhs2 (use_stmt)));
       if (TREE_CODE (new_def_rhs) == MEM_REF
-	  && TREE_CODE (TREE_OPERAND (new_def_rhs, 0)) == ADDR_EXPR
-	  && !DECL_P (TREE_OPERAND (TREE_OPERAND (new_def_rhs, 0), 0))
-	  && !CONSTANT_CLASS_P (TREE_OPERAND (TREE_OPERAND (new_def_rhs, 0), 0)))
+	  && !is_gimple_mem_ref_addr (TREE_OPERAND (new_def_rhs, 0)))
 	return false;
       new_def_rhs = build_fold_addr_expr_with_type (new_def_rhs,
 						    TREE_TYPE (rhs));
@@ -1398,8 +1396,11 @@  tree_ssa_forward_propagate_single_use_va
 		      && TREE_CODE (rhs) == ADDR_EXPR
 		      && POINTER_TYPE_P (TREE_TYPE (lhs))))
 		{
-		  STRIP_NOPS (rhs);
-		  if (!stmt_references_abnormal_ssa_name (stmt)
+		  tree base = get_base_address (TREE_OPERAND (rhs, 0));
+		  if ((!base
+		       || !DECL_P (base)
+		       || decl_address_invariant_p (base))
+		      && !stmt_references_abnormal_ssa_name (stmt)
 		      && forward_propagate_addr_expr (lhs, rhs))
 		    {
 		      release_defs (stmt);