diff mbox

Fix PR54782

Message ID CAO2gOZUX_51+F6E_49-uWeon9TaeMqQV-0pVs=ZDQhuZZVhKvw@mail.gmail.com
State New
Headers show

Commit Message

Dehao Chen Oct. 3, 2012, 6:26 p.m. UTC
Hi,

Attached patch fixes PR54782. phi_arg_location is not correctly
updated in move_block_to_fn. This patch fixes the problem.

Bootstrapped and passed gcc regression tests on x86.

Okay for trunk?

Thanks,
Dehao

gcc/ChangeLog:
2012-10-03  Dehao Chen  <dehao@google.com>

PR middle-end/54782
* tree-cfg.c (move_block_to_fn): Update lexical block for phi_args.

gcc/testsuite/ChangeLog:
2012-10-03  Dehao Chen  <dehao@google.com>

PR middle-end/54782
* gcc.dg/pr54782.c: New test.

Comments

Jakub Jelinek Oct. 3, 2012, 6:46 p.m. UTC | #1
On Wed, Oct 03, 2012 at 11:26:09AM -0700, Dehao Chen wrote:
> @@ -6340,6 +6341,20 @@ move_block_to_fn (struct function *dest_cfun, basi
>  	    SET_USE (use, replace_ssa_name (op, d->vars_map, dest_cfun->decl));
>  	}
>  
> +      for (i = 0; i < EDGE_COUNT (bb->preds); i++)
> +	{
> +	  location_t locus = gimple_phi_arg_location (phi, i);
> +	  if (locus != UNKNOWN_LOCATION)
> +	    {
> +	      tree block = LOCATION_BLOCK (locus);
> +	      if (d->orig_block == NULL_TREE
		  || block == d->orig_block)
> +		gimple_phi_arg_set_location (phi, i, d->new_block ?
> +		    COMBINE_LOCATION_DATA (line_table, locus, d->new_block) :
> +		    LOCATION_LOCUS (locus));
> +	    }
> +	}
> +

The formatting is wrong on this.  ? and : would need to go to the next line
and even the indentation of part of an argument is weird.
IMHO better just do:
	      if (d->orig_block == NULL_TREE || block == d->orig_block)
		{
		  if (d->new_block)
		    locus = COMBINE_LOCATION_DATA (line_table, locus,
						   d->new_block);
		  else
		    locus = LOCATION_LOCUS (locus);
		  gimple_phi_arg_set_location (phi, i, locus);
		}

It will be far more readable.
And/or to decrease indentation level you could do
	  if (locus == UNKNOWN_LOCATION)
	    continue;
	  block = LOCATION_BLOCK (locus);
	  ...

	Jakub
diff mbox

Patch

Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c	(revision 192041)
+++ gcc/tree-cfg.c	(working copy)
@@ -6322,6 +6322,7 @@  move_block_to_fn (struct function *dest_cfun, basi
       use_operand_p use;
       tree op = PHI_RESULT (phi);
       ssa_op_iter oi;
+      unsigned i;
 
       if (virtual_operand_p (op))
 	{
@@ -6340,6 +6341,20 @@  move_block_to_fn (struct function *dest_cfun, basi
 	    SET_USE (use, replace_ssa_name (op, d->vars_map, dest_cfun->decl));
 	}
 
+      for (i = 0; i < EDGE_COUNT (bb->preds); i++)
+	{
+	  location_t locus = gimple_phi_arg_location (phi, i);
+	  if (locus != UNKNOWN_LOCATION)
+	    {
+	      tree block = LOCATION_BLOCK (locus);
+	      if (d->orig_block == NULL_TREE
+		  || block == d->orig_block)
+		gimple_phi_arg_set_location (phi, i, d->new_block ?
+		    COMBINE_LOCATION_DATA (line_table, locus, d->new_block) :
+		    LOCATION_LOCUS (locus));
+	    }
+	}
+
       gsi_next (&si);
     }
 
Index: gcc/testsuite/gcc.dg/pr54782.c
===================================================================
--- gcc/testsuite/gcc.dg/pr54782.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pr54782.c	(revision 0)
@@ -0,0 +1,18 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O -ffast-math -ftree-parallelize-loops=2 -g" } */
+
+struct S
+{
+  int n;
+  float *a;
+};
+
+int
+foo (struct S *s)
+{
+  float sum = 0;
+  int i;
+  for (i = 0; i < s->n; i++)
+    sum += s->a[i];
+  return sum;
+}