public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167)
@ 2016-01-07 21:41 Jakub Jelinek
  2016-01-08  9:12 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2016-01-07 21:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

Various places check that (ab) SSA_NAMEs that weren't referenced on a stmt
before don't appear on it, but all the checking is done on the gimple tuple
operands, while in this case it is added to operands of a comparison of
COND_EXPR/VEC_COND_EXPR.  The following patch fixes it,
bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-01-07  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/69167
	* gimple-match-head.c (gimple_simplify) <case GIMPLE_TERNARY_RHS>:
	Don't simplify condition if the condition simplification would
	introduce use of SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAME not
	previously mentioned on the insn.
	* gimple-fold.h (has_use_on_stmt): New prototype.
	* gimple-fold.c (has_use_on_stmt): No longer static.

	* gcc.dg/pr69167.c: New test.

--- gcc/gimple-match-head.c.jj	2016-01-04 14:55:53.000000000 +0100
+++ gcc/gimple-match-head.c	2016-01-07 12:54:42.237334530 +0100
@@ -655,9 +655,23 @@ gimple_simplify (gimple *stmt,
 			  valueized = true;
 			  if (TREE_CODE_CLASS ((enum tree_code)rcode2)
 			      == tcc_comparison)
-			    rhs1 = build2 (rcode2, TREE_TYPE (rhs1),
-					   ops2[0], ops2[1]);
-			  else if (rcode2 == SSA_NAME
+			    {
+			      if (TREE_CODE (ops2[0]) == SSA_NAME
+				  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops2[0])
+				  && !has_use_on_stmt (ops2[0], stmt))
+				valueized = false;
+			      if (TREE_CODE (ops2[1]) == SSA_NAME
+				  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops2[1])
+				  && !has_use_on_stmt (ops2[1], stmt))
+				valueized = false;
+			      if (valueized)
+				rhs1 = build2 (rcode2, TREE_TYPE (rhs1),
+					       ops2[0], ops2[1]);
+			    }
+			  else if ((rcode2 == SSA_NAME
+				    && (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI
+								      (ops2[0])
+					|| has_use_on_stmt (ops2[0], stmt)))
 				   || rcode2 == INTEGER_CST
 				   || rcode2 == VECTOR_CST)
 			    rhs1 = ops2[0];
--- gcc/gimple-fold.h.jj	2016-01-04 14:55:53.000000000 +0100
+++ gcc/gimple-fold.h	2016-01-07 13:01:52.938315972 +0100
@@ -34,6 +34,7 @@ extern tree maybe_fold_or_comparisons (e
 				       enum tree_code, tree, tree);
 extern bool arith_overflowed_p (enum tree_code, const_tree, const_tree,
 				const_tree);
+extern bool has_use_on_stmt (tree, gimple *);
 extern tree no_follow_ssa_edges (tree);
 extern tree follow_single_use_edges (tree);
 extern tree gimple_fold_stmt_to_constant_1 (gimple *, tree (*) (tree),
--- gcc/gimple-fold.c.jj	2016-01-07 11:37:36.000000000 +0100
+++ gcc/gimple-fold.c	2016-01-07 13:01:25.793695288 +0100
@@ -3270,7 +3270,7 @@ gimple_fold_call (gimple_stmt_iterator *
 
 /* Return true whether NAME has a use on STMT.  */
 
-static bool
+bool
 has_use_on_stmt (tree name, gimple *stmt)
 {
   imm_use_iterator iter;
--- gcc/testsuite/gcc.dg/pr69167.c.jj	2016-01-07 12:58:40.706002201 +0100
+++ gcc/testsuite/gcc.dg/pr69167.c	2016-01-07 12:58:22.000000000 +0100
@@ -0,0 +1,21 @@
+/* PR tree-optimization/69167 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int sigsetjmp (char *);
+void foo ();
+void bar (void (*) (int *));
+extern char t[];
+
+void
+baz (int *x)
+{
+  int *a = x;
+  foo ();
+  x = 0;
+  if (sigsetjmp (t))
+    while (1)
+      bar (a ? baz : 0);
+  if (x)
+    foo ();
+}

	Jakub

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

* Re: [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167)
  2016-01-07 21:41 [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167) Jakub Jelinek
@ 2016-01-08  9:12 ` Richard Biener
  2016-01-08 20:08   ` [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167, take 2) Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2016-01-08  9:12 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Thu, 7 Jan 2016, Jakub Jelinek wrote:

> Hi!
> 
> Various places check that (ab) SSA_NAMEs that weren't referenced on a stmt
> before don't appear on it, but all the checking is done on the gimple tuple
> operands, while in this case it is added to operands of a comparison of
> COND_EXPR/VEC_COND_EXPR.  The following patch fixes it,
> bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Hmm, I think this needs to go to the stmt replacement part,
replace_stmt_with_simplification.

Richard.

> 2016-01-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/69167
> 	* gimple-match-head.c (gimple_simplify) <case GIMPLE_TERNARY_RHS>:
> 	Don't simplify condition if the condition simplification would
> 	introduce use of SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAME not
> 	previously mentioned on the insn.
> 	* gimple-fold.h (has_use_on_stmt): New prototype.
> 	* gimple-fold.c (has_use_on_stmt): No longer static.
> 
> 	* gcc.dg/pr69167.c: New test.
> 
> --- gcc/gimple-match-head.c.jj	2016-01-04 14:55:53.000000000 +0100
> +++ gcc/gimple-match-head.c	2016-01-07 12:54:42.237334530 +0100
> @@ -655,9 +655,23 @@ gimple_simplify (gimple *stmt,
>  			  valueized = true;
>  			  if (TREE_CODE_CLASS ((enum tree_code)rcode2)
>  			      == tcc_comparison)
> -			    rhs1 = build2 (rcode2, TREE_TYPE (rhs1),
> -					   ops2[0], ops2[1]);
> -			  else if (rcode2 == SSA_NAME
> +			    {
> +			      if (TREE_CODE (ops2[0]) == SSA_NAME
> +				  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops2[0])
> +				  && !has_use_on_stmt (ops2[0], stmt))
> +				valueized = false;
> +			      if (TREE_CODE (ops2[1]) == SSA_NAME
> +				  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops2[1])
> +				  && !has_use_on_stmt (ops2[1], stmt))
> +				valueized = false;
> +			      if (valueized)
> +				rhs1 = build2 (rcode2, TREE_TYPE (rhs1),
> +					       ops2[0], ops2[1]);
> +			    }
> +			  else if ((rcode2 == SSA_NAME
> +				    && (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI
> +								      (ops2[0])
> +					|| has_use_on_stmt (ops2[0], stmt)))
>  				   || rcode2 == INTEGER_CST
>  				   || rcode2 == VECTOR_CST)
>  			    rhs1 = ops2[0];
> --- gcc/gimple-fold.h.jj	2016-01-04 14:55:53.000000000 +0100
> +++ gcc/gimple-fold.h	2016-01-07 13:01:52.938315972 +0100
> @@ -34,6 +34,7 @@ extern tree maybe_fold_or_comparisons (e
>  				       enum tree_code, tree, tree);
>  extern bool arith_overflowed_p (enum tree_code, const_tree, const_tree,
>  				const_tree);
> +extern bool has_use_on_stmt (tree, gimple *);
>  extern tree no_follow_ssa_edges (tree);
>  extern tree follow_single_use_edges (tree);
>  extern tree gimple_fold_stmt_to_constant_1 (gimple *, tree (*) (tree),
> --- gcc/gimple-fold.c.jj	2016-01-07 11:37:36.000000000 +0100
> +++ gcc/gimple-fold.c	2016-01-07 13:01:25.793695288 +0100
> @@ -3270,7 +3270,7 @@ gimple_fold_call (gimple_stmt_iterator *
>  
>  /* Return true whether NAME has a use on STMT.  */
>  
> -static bool
> +bool
>  has_use_on_stmt (tree name, gimple *stmt)
>  {
>    imm_use_iterator iter;
> --- gcc/testsuite/gcc.dg/pr69167.c.jj	2016-01-07 12:58:40.706002201 +0100
> +++ gcc/testsuite/gcc.dg/pr69167.c	2016-01-07 12:58:22.000000000 +0100
> @@ -0,0 +1,21 @@
> +/* PR tree-optimization/69167 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +int sigsetjmp (char *);
> +void foo ();
> +void bar (void (*) (int *));
> +extern char t[];
> +
> +void
> +baz (int *x)
> +{
> +  int *a = x;
> +  foo ();
> +  x = 0;
> +  if (sigsetjmp (t))
> +    while (1)
> +      bar (a ? baz : 0);
> +  if (x)
> +    foo ();
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

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

* [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167, take 2)
  2016-01-08  9:12 ` Richard Biener
@ 2016-01-08 20:08   ` Jakub Jelinek
  2016-01-08 20:43     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2016-01-08 20:08 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

On Fri, Jan 08, 2016 at 10:12:09AM +0100, Richard Biener wrote:
> On Thu, 7 Jan 2016, Jakub Jelinek wrote:
> 
> > Hi!
> > 
> > Various places check that (ab) SSA_NAMEs that weren't referenced on a stmt
> > before don't appear on it, but all the checking is done on the gimple tuple
> > operands, while in this case it is added to operands of a comparison of
> > COND_EXPR/VEC_COND_EXPR.  The following patch fixes it,
> > bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> Hmm, I think this needs to go to the stmt replacement part,
> replace_stmt_with_simplification.

Ok, here is another version that does that.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-01-08  Jakub Jelinek  <jakub@redhat.com>

        PR tree-optimization/69167
        * gimple-fold.c (replace_stmt_with_simplification): Also punt if
	new SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAMEs appear in operands of
	ops[0] comparison.
	* gimple-match-head.c (maybe_push_res_to_seq): Likewise.

	* gcc.dg/pr69167.c: New test.

--- gcc/gimple-fold.c.jj	2016-01-08 11:12:34.000000000 +0100
+++ gcc/gimple-fold.c	2016-01-08 11:20:25.324204191 +0100
@@ -3309,7 +3309,14 @@ replace_stmt_with_simplification (gimple
       || (ops[2]
 	  && TREE_CODE (ops[2]) == SSA_NAME
 	  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])
-	  && !has_use_on_stmt (ops[2], stmt)))
+	  && !has_use_on_stmt (ops[2], stmt))
+      || (COMPARISON_CLASS_P (ops[0])
+	  && ((TREE_CODE (TREE_OPERAND (ops[0], 0)) == SSA_NAME
+	       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], 0))
+	       && !has_use_on_stmt (TREE_OPERAND (ops[0], 0), stmt))
+	      || (TREE_CODE (TREE_OPERAND (ops[0], 1)) == SSA_NAME
+		  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], 1))
+		  && !has_use_on_stmt (TREE_OPERAND (ops[0], 1), stmt)))))
     return false;
 
   /* Don't insert new statements when INPLACE is true, even if we could
--- gcc/gimple-match-head.c.jj	2016-01-08 09:36:14.000000000 +0100
+++ gcc/gimple-match-head.c	2016-01-08 12:26:21.555528562 +0100
@@ -299,7 +299,14 @@ maybe_push_res_to_seq (code_helper rcode
 	      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
 	  || (ops[2]
 	      && TREE_CODE (ops[2]) == SSA_NAME
-	      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
+	      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2]))
+	  || (COMPARISON_CLASS_P (ops[0])
+	      && ((TREE_CODE (TREE_OPERAND (ops[0], 0)) == SSA_NAME
+		   && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0],
+								     0)))
+		  || (TREE_CODE (TREE_OPERAND (ops[0], 1)) == SSA_NAME
+		      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0],
+									1))))))
 	return NULL_TREE;
       if (!res)
 	{
--- gcc/testsuite/gcc.dg/pr69167.c.jj	2016-01-08 11:15:22.498485105 +0100
+++ gcc/testsuite/gcc.dg/pr69167.c	2016-01-08 11:15:22.498485105 +0100
@@ -0,0 +1,21 @@
+/* PR tree-optimization/69167 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int sigsetjmp (char *);
+void foo ();
+void bar (void (*) (int *));
+extern char t[];
+
+void
+baz (int *x)
+{
+  int *a = x;
+  foo ();
+  x = 0;
+  if (sigsetjmp (t))
+    while (1)
+      bar (a ? baz : 0);
+  if (x)
+    foo ();
+}

	Jakub

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

* Re: [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167, take 2)
  2016-01-08 20:08   ` [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167, take 2) Jakub Jelinek
@ 2016-01-08 20:43     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2016-01-08 20:43 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On January 8, 2016 9:08:36 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>On Fri, Jan 08, 2016 at 10:12:09AM +0100, Richard Biener wrote:
>> On Thu, 7 Jan 2016, Jakub Jelinek wrote:
>> 
>> > Hi!
>> > 
>> > Various places check that (ab) SSA_NAMEs that weren't referenced on
>a stmt
>> > before don't appear on it, but all the checking is done on the
>gimple tuple
>> > operands, while in this case it is added to operands of a
>comparison of
>> > COND_EXPR/VEC_COND_EXPR.  The following patch fixes it,
>> > bootstrapped/regtested on x86_64-linux and i686-linux, ok for
>trunk?
>> 
>> Hmm, I think this needs to go to the stmt replacement part,
>> replace_stmt_with_simplification.
>
>Ok, here is another version that does that.
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

>2016-01-08  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/69167
>       * gimple-fold.c (replace_stmt_with_simplification): Also punt if
>	new SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAMEs appear in operands of
>	ops[0] comparison.
>	* gimple-match-head.c (maybe_push_res_to_seq): Likewise.
>
>	* gcc.dg/pr69167.c: New test.
>
>--- gcc/gimple-fold.c.jj	2016-01-08 11:12:34.000000000 +0100
>+++ gcc/gimple-fold.c	2016-01-08 11:20:25.324204191 +0100
>@@ -3309,7 +3309,14 @@ replace_stmt_with_simplification (gimple
>       || (ops[2]
> 	  && TREE_CODE (ops[2]) == SSA_NAME
> 	  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])
>-	  && !has_use_on_stmt (ops[2], stmt)))
>+	  && !has_use_on_stmt (ops[2], stmt))
>+      || (COMPARISON_CLASS_P (ops[0])
>+	  && ((TREE_CODE (TREE_OPERAND (ops[0], 0)) == SSA_NAME
>+	       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], 0))
>+	       && !has_use_on_stmt (TREE_OPERAND (ops[0], 0), stmt))
>+	      || (TREE_CODE (TREE_OPERAND (ops[0], 1)) == SSA_NAME
>+		  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], 1))
>+		  && !has_use_on_stmt (TREE_OPERAND (ops[0], 1), stmt)))))
>     return false;
> 
>  /* Don't insert new statements when INPLACE is true, even if we could
>--- gcc/gimple-match-head.c.jj	2016-01-08 09:36:14.000000000 +0100
>+++ gcc/gimple-match-head.c	2016-01-08 12:26:21.555528562 +0100
>@@ -299,7 +299,14 @@ maybe_push_res_to_seq (code_helper rcode
> 	      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
> 	  || (ops[2]
> 	      && TREE_CODE (ops[2]) == SSA_NAME
>-	      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
>+	      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2]))
>+	  || (COMPARISON_CLASS_P (ops[0])
>+	      && ((TREE_CODE (TREE_OPERAND (ops[0], 0)) == SSA_NAME
>+		   && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0],
>+								     0)))
>+		  || (TREE_CODE (TREE_OPERAND (ops[0], 1)) == SSA_NAME
>+		      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0],
>+									1))))))
> 	return NULL_TREE;
>       if (!res)
> 	{
>--- gcc/testsuite/gcc.dg/pr69167.c.jj	2016-01-08 11:15:22.498485105
>+0100
>+++ gcc/testsuite/gcc.dg/pr69167.c	2016-01-08 11:15:22.498485105 +0100
>@@ -0,0 +1,21 @@
>+/* PR tree-optimization/69167 */
>+/* { dg-do compile } */
>+/* { dg-options "-O2" } */
>+
>+int sigsetjmp (char *);
>+void foo ();
>+void bar (void (*) (int *));
>+extern char t[];
>+
>+void
>+baz (int *x)
>+{
>+  int *a = x;
>+  foo ();
>+  x = 0;
>+  if (sigsetjmp (t))
>+    while (1)
>+      bar (a ? baz : 0);
>+  if (x)
>+    foo ();
>+}
>
>	Jakub


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

end of thread, other threads:[~2016-01-08 20:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-07 21:41 [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167) Jakub Jelinek
2016-01-08  9:12 ` Richard Biener
2016-01-08 20:08   ` [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167, take 2) Jakub Jelinek
2016-01-08 20:43     ` Richard Biener

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).