public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Handle COND_EXPR/VEC_COND_EXPR in walk_stmt_load_store_addr_ops and ssa verification
@ 2011-10-13 13:52 Jakub Jelinek
  2011-10-14  9:37 ` Richard Guenther
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2011-10-13 13:52 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches, Andrew Pinski

Hi!

Andrew mentioned on IRC he found walk_stmt_load_store_addr_ops
doesn't handle COND_EXPR weirdo first argument well, the following
patch is an attempt to handle that.

I've noticed similar spot in verify_ssa, though in that case I'm not
sure about whether the change is so desirable, as it doesn't seem to
handle SSA_NAMEs embedded in MEM_EXPRs, ARRAY_REFs etc. either.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Or just the gimple.c part?

2011-10-13  Jakub Jelinek  <jakub@redhat.com>

	* gimple.c (walk_stmt_load_store_addr_ops): Call visit_addr
	also on COND_EXPR/VEC_COND_EXPR comparison operands if they are
	ADDR_EXPRs.

	* tree-ssa.c (verify_ssa): For COND_EXPR/VEC_COND_EXPR count
	SSA_NAMEs in comparison operand as well.

--- gcc/gimple.c.jj	2011-10-13 11:13:39.000000000 +0200
+++ gcc/gimple.c	2011-10-13 11:15:25.000000000 +0200
@@ -5313,9 +5313,24 @@ walk_stmt_load_store_addr_ops (gimple st
 	       || gimple_code (stmt) == GIMPLE_COND))
     {
       for (i = 0; i < gimple_num_ops (stmt); ++i)
-	if (gimple_op (stmt, i)
-	    && TREE_CODE (gimple_op (stmt, i)) == ADDR_EXPR)
-	  ret |= visit_addr (stmt, TREE_OPERAND (gimple_op (stmt, i), 0), data);
+	{
+	  tree op = gimple_op (stmt, i);
+	  if (op == NULL_TREE)
+	    ;
+	  else if (TREE_CODE (op) == ADDR_EXPR)
+	    ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+	  /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
+	     tree with two operands.  */
+	  else if (i == 1 && COMPARISON_CLASS_P (op))
+	    {
+	      if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
+		ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
+						       0), data);
+	      if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
+		ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
+						       0), data);
+	    }
+	}
     }
   else if (is_gimple_call (stmt))
     {
--- gcc/tree-ssa.c.jj	2011-10-07 10:03:28.000000000 +0200
+++ gcc/tree-ssa.c	2011-10-13 11:19:30.000000000 +0200
@@ -1069,14 +1069,27 @@ verify_ssa (bool check_modified_stmt)
 	  for (i = 0; i < gimple_num_ops (stmt); i++)
 	    {
 	      op = gimple_op (stmt, i);
-	      if (op && TREE_CODE (op) == SSA_NAME && --count < 0)
+	      if (op == NULL_TREE)
+		continue;
+	      if (TREE_CODE (op) == SSA_NAME)
+		--count;
+	      /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
+		 tree with two operands.  */
+	      else if (i == 1 && COMPARISON_CLASS_P (op))
 		{
-		  error ("number of operands and imm-links don%'t agree"
-			 " in statement");
-		  print_gimple_stmt (stderr, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
-		  goto err;
+		  if (TREE_CODE (TREE_OPERAND (op, 0)) == SSA_NAME)
+		    --count;
+		  if (TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
+		    --count;
 		}
 	    }
+	  if (count < 0)
+	    {
+	      error ("number of operands and imm-links don%'t agree"
+		     " in statement");
+	      print_gimple_stmt (stderr, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
+	      goto err;
+	    }
 
 	  FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
 	    {

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Handle COND_EXPR/VEC_COND_EXPR in walk_stmt_load_store_addr_ops and ssa verification
  2011-10-13 13:52 [PATCH] Handle COND_EXPR/VEC_COND_EXPR in walk_stmt_load_store_addr_ops and ssa verification Jakub Jelinek
@ 2011-10-14  9:37 ` Richard Guenther
  2011-10-14 14:26   ` Michael Matz
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Guenther @ 2011-10-14  9:37 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Andrew Pinski

[-- Attachment #1: Type: TEXT/PLAIN, Size: 4579 bytes --]

On Thu, 13 Oct 2011, Jakub Jelinek wrote:

> Hi!
> 
> Andrew mentioned on IRC he found walk_stmt_load_store_addr_ops
> doesn't handle COND_EXPR weirdo first argument well, the following
> patch is an attempt to handle that.
> 
> I've noticed similar spot in verify_ssa, though in that case I'm not
> sure about whether the change is so desirable, as it doesn't seem to
> handle SSA_NAMEs embedded in MEM_EXPRs, ARRAY_REFs etc. either.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> Or just the gimple.c part?

The verify-ssa code is somewhat odd, I'd have expected a
if (count != 0)
  error ();
after that loop, but that of course would have triggered already ;)

The code tries to be more something like verify_operands () which
verifies that update_stmt () was called.  Thus I'd say we
should rather (at the end of processing the stmt) do sth like

saved_need_update = need_ssa_update ();
need_ssa_update = false;
record-state-of-use-operands
update_stmt
compare state-of-use-operands
assert (!need_ssa_update ());
need_ssa_update = saved_need_update;

unfortunately update_stmt may change the operand list even
if no changes occur (IIRC).

But I'm not sure.  I think we should delete this check from
verify_ssa and instead have a corresponding check in
verify_stmts (which already properly walks trees) that
for an SSA name we encounter we do have a properly linked use
(see verify_expr, maybe it's easy to do that for the SSA_NAME
case - at least it's easy without trying to avoid a
FOR_EACH_SSA_USE_OPERAND (, SSA_OP_USE) on the stmt for
each SSA_NAME we encounter).

The gimple.c part is ok.

Thanks,
Richard.

> 2011-10-13  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* gimple.c (walk_stmt_load_store_addr_ops): Call visit_addr
> 	also on COND_EXPR/VEC_COND_EXPR comparison operands if they are
> 	ADDR_EXPRs.
> 
> 	* tree-ssa.c (verify_ssa): For COND_EXPR/VEC_COND_EXPR count
> 	SSA_NAMEs in comparison operand as well.
> 
> --- gcc/gimple.c.jj	2011-10-13 11:13:39.000000000 +0200
> +++ gcc/gimple.c	2011-10-13 11:15:25.000000000 +0200
> @@ -5313,9 +5313,24 @@ walk_stmt_load_store_addr_ops (gimple st
>  	       || gimple_code (stmt) == GIMPLE_COND))
>      {
>        for (i = 0; i < gimple_num_ops (stmt); ++i)
> -	if (gimple_op (stmt, i)
> -	    && TREE_CODE (gimple_op (stmt, i)) == ADDR_EXPR)
> -	  ret |= visit_addr (stmt, TREE_OPERAND (gimple_op (stmt, i), 0), data);
> +	{
> +	  tree op = gimple_op (stmt, i);
> +	  if (op == NULL_TREE)
> +	    ;
> +	  else if (TREE_CODE (op) == ADDR_EXPR)
> +	    ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
> +	  /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
> +	     tree with two operands.  */
> +	  else if (i == 1 && COMPARISON_CLASS_P (op))
> +	    {
> +	      if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
> +		ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
> +						       0), data);
> +	      if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
> +		ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
> +						       0), data);
> +	    }
> +	}
>      }
>    else if (is_gimple_call (stmt))
>      {
> --- gcc/tree-ssa.c.jj	2011-10-07 10:03:28.000000000 +0200
> +++ gcc/tree-ssa.c	2011-10-13 11:19:30.000000000 +0200
> @@ -1069,14 +1069,27 @@ verify_ssa (bool check_modified_stmt)
>  	  for (i = 0; i < gimple_num_ops (stmt); i++)
>  	    {
>  	      op = gimple_op (stmt, i);
> -	      if (op && TREE_CODE (op) == SSA_NAME && --count < 0)
> +	      if (op == NULL_TREE)
> +		continue;
> +	      if (TREE_CODE (op) == SSA_NAME)
> +		--count;
> +	      /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
> +		 tree with two operands.  */
> +	      else if (i == 1 && COMPARISON_CLASS_P (op))
>  		{
> -		  error ("number of operands and imm-links don%'t agree"
> -			 " in statement");
> -		  print_gimple_stmt (stderr, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
> -		  goto err;
> +		  if (TREE_CODE (TREE_OPERAND (op, 0)) == SSA_NAME)
> +		    --count;
> +		  if (TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
> +		    --count;
>  		}
>  	    }
> +	  if (count < 0)
> +	    {
> +	      error ("number of operands and imm-links don%'t agree"
> +		     " in statement");
> +	      print_gimple_stmt (stderr, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
> +	      goto err;
> +	    }
>  
>  	  FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
>  	    {
> 
> 	Jakub
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Handle COND_EXPR/VEC_COND_EXPR in walk_stmt_load_store_addr_ops and ssa verification
  2011-10-14  9:37 ` Richard Guenther
@ 2011-10-14 14:26   ` Michael Matz
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Matz @ 2011-10-14 14:26 UTC (permalink / raw)
  To: Richard Guenther; +Cc: Jakub Jelinek, gcc-patches, Andrew Pinski

Hi,

On Fri, 14 Oct 2011, Richard Guenther wrote:

> But I'm not sure.  I think we should delete this check from
> verify_ssa and instead have a corresponding check in
> verify_stmts (which already properly walks trees) that
> for an SSA name we encounter we do have a properly linked use
> (see verify_expr, maybe it's easy to do that for the SSA_NAME
> case - at least it's easy without trying to avoid a
> FOR_EACH_SSA_USE_OPERAND (, SSA_OP_USE) on the stmt for
> each SSA_NAME we encounter).

Whatever we do with this check, it should be ensured that it still 
triggers on gcc.dg/pr45415.c at revision r163821.  IIRC to find the cause 
for this bug caused some more gray hair on my part :)


Ciao,
Michael.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-14 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-13 13:52 [PATCH] Handle COND_EXPR/VEC_COND_EXPR in walk_stmt_load_store_addr_ops and ssa verification Jakub Jelinek
2011-10-14  9:37 ` Richard Guenther
2011-10-14 14:26   ` Michael Matz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).