This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] PR23049


Hi,

This is a new fix for PR23049, which is an infinite loop and eventually
an ICE in fold, when it tries to fold expressions like "0 == 0 ? a : b",
because it expects the "0 == 0" to be folded already.

(See http://gcc.gnu.org/ml/gcc-patches/2005-09/msg01084.html for the old
proposed fix for this PR.)

This patch nukes a few failures in the testsuite if you run it with
-ftree-vectorize.  Andrew Pinski knows more about that...

Bootstrapped and tested on x86_64-linux.  OK for mainline?

Gr.
Steven



gcc/
	PR tree-optimization/23049
	* tree-ssa-dom.c (thread_across_edge): Make sure that the condition
	of a COND_EXPR is folded before calling fold on the whole rhs of a
	conditional assignment.
	* doc/tree-ssa.texi: Update the GIMPLE grammar for a valid rhs to
	document that a COND_EXPR may appear there.

testsuite/
	* gcc.dg/pr23049.c: New test.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.128
diff -u -3 -p -r2.128 tree-ssa-dom.c
--- tree-ssa-dom.c	26 Sep 2005 19:40:20 -0000	2.128
+++ tree-ssa-dom.c	29 Sep 2005 14:04:40 -0000
@@ -666,7 +666,7 @@ thread_across_edge (struct dom_walk_data
      statements.  This does not prevent threading through E->dest.  */
   for (bsi = bsi_start (e->dest); ! bsi_end_p (bsi); bsi_next (&bsi))
     {
-      tree cached_lhs;
+      tree cached_lhs = NULL;
 
       stmt = bsi_stmt (bsi);
 
@@ -705,7 +705,7 @@ thread_across_edge (struct dom_walk_data
       else
 	{
 	  /* Copy the operands.  */
-	  tree *copy;
+	  tree *copy, pre_fold_expr;
 	  ssa_op_iter iter;
 	  use_operand_p use_p;
 	  unsigned int num, i = 0;
@@ -729,12 +729,31 @@ thread_across_edge (struct dom_walk_data
 
 	  /* Try to fold/lookup the new expression.  Inserting the
 	     expression into the hash table is unlikely to help
-	     simplify anything later, so just query the hashtable.  */
-	  cached_lhs = fold (TREE_OPERAND (stmt, 1));
-	  if (TREE_CODE (cached_lhs) != SSA_NAME
-	      && !is_gimple_min_invariant (cached_lhs))
-	    cached_lhs = lookup_avail_expr (stmt, false);
+	     Sadly, we have to handle conditional assignments specially
+	     here, because fold expects all the operands of an expression
+	     to be folded before the expression itself is folded, but we
+	     can't just substitute the folded condition here.  */
+	  if (TREE_CODE (TREE_OPERAND (stmt, 1)) == COND_EXPR)
+	    {
+	      tree cond = COND_EXPR_COND (TREE_OPERAND (stmt, 1));
+	      cond = fold (cond);
+	      if (cond == boolean_true_node)
+		pre_fold_expr = COND_EXPR_THEN (TREE_OPERAND (stmt, 1));
+	      else if (cond == boolean_false_node)
+		pre_fold_expr = COND_EXPR_ELSE (TREE_OPERAND (stmt, 1));
+	      else
+		pre_fold_expr = TREE_OPERAND (stmt, 1);
+	    }
+	  else
+	    pre_fold_expr = TREE_OPERAND (stmt, 1);
 
+	  if (pre_fold_expr)
+	    {
+	      cached_lhs = fold (pre_fold_expr);
+	      if (TREE_CODE (cached_lhs) != SSA_NAME
+		  && !is_gimple_min_invariant (cached_lhs))
+	        cached_lhs = lookup_avail_expr (stmt, false);
+	    }
 
 	  /* Restore the statement's original uses/defs.  */
 	  i = 0;
Index: doc/tree-ssa.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tree-ssa.texi,v
retrieving revision 1.31
diff -u -3 -p -r1.31 tree-ssa.texi
--- doc/tree-ssa.texi	26 Jul 2005 13:53:54 -0000	1.31
+++ doc/tree-ssa.texi	29 Sep 2005 14:04:42 -0000
@@ -728,6 +728,10 @@ void f()
                 | RELOP
                         op0 -> val
                         op1 -> val
+		| COND_EXPR
+			op0 -> condition
+			op1 -> val
+			op2 -> val
 @end smallexample
 
 @node Annotations
Index: testsuite/gcc.dg/pr23049.c
===================================================================
RCS file: testsuite/gcc.dg/pr23049.c
diff -N testsuite/gcc.dg/pr23049.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/pr23049.c	29 Sep 2005 14:04:44 -0000
@@ -0,0 +1,26 @@
+/* This was an ICE in fold where we tried to fold something like,
+
+     a = 0 == 0 ? 0 : 3988292384
+
+   after doing if-conversion for the vectorizer.  Folding "0 == 0"
+   should have been done before calling fold on the whole rhs of
+   the above expression.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -ftree-vectorize" } */
+
+static unsigned short int crc_table[256];
+void AC3_encode_init(void)
+{
+  unsigned int c, n, k;
+  for(n=0;  n<256; n++)
+  {
+    c = n << 8;
+    for (k = 0; k < 8; k++)
+    {
+      if (c & (1 << 15))
+       c = ((c << 1) & 0xffff) ^ (((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16)) & 0xffff);
+    }
+    crc_table[n] = c;
+  }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]