Patchwork Fix PR45230: Only GIMPLE_ASSIGNs can contain ADDR_EXPRs.

login
register
mail settings
Submitter Richard Guenther
Date Dec. 8, 2010, 11:01 a.m.
Message ID <alpine.LNX.2.00.1012081159170.23074@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/74661/
State New
Headers show

Comments

Richard Guenther - Dec. 8, 2010, 11:01 a.m.
On Tue, 7 Dec 2010, Sebastian Pop wrote:

> Hi,
> 
> This is a slightly modified version of the previous patch: apparently
> force_gimple_operand does not create the MODIFY_EXPR when the
> expression is already simple, so this time we create the MODIFY_EXPR
> before calling force_gimple_operand.  This fixes one more bug.
> 
> Ok for trunk after regstrap on amd64-linux?

See below

> Thanks,
> Sebastian
> 
> 2010-12-07  Sebastian Pop  <sebastian.pop@amd.com>
> 
> 	PR tree-optimization/45230
> 	PR tree-optimization/45370
> 	* sese.c (rename_uses): Call recompute_tree_invariant_for_addr_expr
> 	only on the RHS of a GIMPLE_ASSIGN.  Assign the new expression to
> 	a new variable before renaming.
> 
> 	* gcc.dg/graphite/id-pr45230-1.c: New.
> 	* gfortran.dg/graphite/id-pr45370.f90: New.
> ---
>  gcc/ChangeLog                                     |    8 ++
>  gcc/sese.c                                        |   15 ++-
>  gcc/testsuite/ChangeLog                           |    7 +
>  gcc/testsuite/gcc.dg/graphite/id-pr45230-1.c      |  140 +++++++++++++++++++++
>  gcc/testsuite/gfortran.dg/graphite/id-pr45370.f90 |  103 +++++++++++++++
>  5 files changed, 267 insertions(+), 6 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/graphite/id-pr45230-1.c
>  create mode 100644 gcc/testsuite/gfortran.dg/graphite/id-pr45370.f90
> 
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index ff52686..77eea2d 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,11 @@
> +2010-12-07  Sebastian Pop  <sebastian.pop@amd.com>
> +
> +	PR tree-optimization/45230
> +	PR tree-optimization/45370
> +	* sese.c (rename_uses): Call recompute_tree_invariant_for_addr_expr
> +	only on the RHS of a GIMPLE_ASSIGN.  Assign the new expression to
> +	a new variable before renaming.
> +
>  2010-12-07  Paul Koning  <ni1d@arrl.net>
>  
>  	* config/pdp11/pdp11.c (TARGET_ASM_FUNCTION_SECTION): Define.
> diff --git a/gcc/sese.c b/gcc/sese.c
> index 65f8556..7741bdf 100644
> --- a/gcc/sese.c
> +++ b/gcc/sese.c
> @@ -492,7 +492,8 @@ rename_uses (gimple copy, htab_t rename_map, gimple_stmt_iterator *gsi_tgt,
>    FOR_EACH_SSA_USE_OPERAND (use_p, copy, op_iter, SSA_OP_ALL_USES)
>      {
>        tree old_name = USE_FROM_PTR (use_p);
> -      tree new_expr, scev;
> +      tree type_old_name = TREE_TYPE (old_name);
> +      tree new_expr, scev, var;
>        gimple_seq stmts;
>  
>        if (TREE_CODE (old_name) != SSA_NAME
> @@ -503,20 +504,20 @@ rename_uses (gimple copy, htab_t rename_map, gimple_stmt_iterator *gsi_tgt,
>        new_expr = get_rename (rename_map, old_name);
>        if (new_expr)
>  	{
> -	  tree type_old_name = TREE_TYPE (old_name);
>  	  tree type_new_expr = TREE_TYPE (new_expr);
>  
>  	  if (type_old_name != type_new_expr
>  	      || (TREE_CODE (new_expr) != SSA_NAME
>  		  && is_gimple_reg (old_name)))
>  	    {
> -	      tree var = create_tmp_var (type_old_name, "var");
> +	      var = create_tmp_var (type_old_name, "var");
>  
>  	      if (type_old_name != type_new_expr)
>  		new_expr = fold_convert (type_old_name, new_expr);
>  
>  	      new_expr = build2 (MODIFY_EXPR, type_old_name, var, new_expr);
> -	      new_expr = force_gimple_operand (new_expr, &stmts, true, NULL);
> +	      new_expr = force_gimple_operand (new_expr, &stmts, true,
> +					       NULL_TREE);
>  	      gsi_insert_seq_before (gsi_tgt, stmts, GSI_SAME_STMT);
>  	    }
>  
> @@ -542,13 +543,15 @@ rename_uses (gimple copy, htab_t rename_map, gimple_stmt_iterator *gsi_tgt,
>  		  && !tree_contains_chrecs (new_expr, NULL));
>  
>        /* Replace the old_name with the new_expr.  */
> +      var = create_tmp_var (type_old_name, "var");
> +      new_expr = build2 (MODIFY_EXPR, type_old_name, var, new_expr);
>        new_expr = force_gimple_operand (unshare_expr (new_expr), &stmts,
>  				       true, NULL_TREE);
>        gsi_insert_seq_before (gsi_tgt, stmts, GSI_SAME_STMT);
>        replace_exp (use_p, new_expr);

We expect that you fold a statement when you use replace_exp on it.

Thus, the following would be more appropriate:

Patch

Index: gcc/sese.c
===================================================================
--- gcc/sese.c	(revision 167583)
+++ gcc/sese.c	(working copy)
@@ -472,12 +472,13 @@  set_rename (htab_t rename_map, tree old_
    statement in LOOP, and using the induction variable renaming map
    IV_MAP.  */
 
-static void
+static bool
 rename_uses (gimple copy, htab_t rename_map, gimple_stmt_iterator *gsi_tgt,
 	     sese region, loop_p loop, VEC (tree, heap) *iv_map)
 {
   use_operand_p use_p;
   ssa_op_iter op_iter;
+  bool changed = false;
 
   if (is_gimple_debug (copy))
     {
@@ -500,6 +501,7 @@  rename_uses (gimple copy, htab_t rename_
 	  || SSA_NAME_IS_DEFAULT_DEF (old_name))
 	continue;
 
+      changed = true;
       new_expr = get_rename (rename_map, old_name);
       if (new_expr)
 	{
@@ -547,8 +549,8 @@  rename_uses (gimple copy, htab_t rename_
       gsi_insert_seq_before (gsi_tgt, stmts, GSI_SAME_STMT);
       replace_exp (use_p, new_expr);
 
-
-      if (TREE_CODE (new_expr) == INTEGER_CST)
+      if (TREE_CODE (new_expr) == INTEGER_CST
+	  && is_gimple_assign (copy))
 	{
 	  tree rhs = gimple_assign_rhs1 (copy);
 
@@ -558,6 +560,8 @@  rename_uses (gimple copy, htab_t rename_
 
       set_rename (rename_map, old_name, new_expr);
     }
+
+  return changed;
 }
 
 /* Duplicates the statements of basic block BB into basic block NEW_BB
@@ -611,7 +615,8 @@  graphite_copy_stmts_from_block (basic_bl
 	  set_rename (rename_map, old_name, new_name);
  	}
 
-      rename_uses (copy, rename_map, &gsi_tgt, region, loop, iv_map);
+      if (rename_uses (copy, rename_map, &gsi_tgt, region, loop, iv_map))
+	fold_stmt_inplace (copy);
 
       update_stmt (copy);
     }