[PATCH] Fix ICE during niter computation (PR tree-optimization/70177)

Jakub Jelinek jakub@redhat.com
Fri Mar 11 12:04:00 GMT 2016


Hi!

On the following testcase we ICE, because we call extract_ops_from_tree
on COND_EXPR, and that inline asserts it doesn't have 3 operands.  
derive_constant_upper_bound_ops has a big switch on various tree codes,
but doesn't handle any 3 argument ones right now, so there is no need
to pass the extra argument there, but we just shouldn't ICE on it.

While at it, I've renamed extract_ops_from_tree_1 to
extract_ops_from_tree so that we can use C++ function overloading on
something where it makes lots of sense.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-03-11  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/70177
	* gimple-expr.h (extract_ops_from_tree_1): Renamed to ...
	(extract_ops_from_tree): ... this.  In the 2 argument
	overload remove _1 suffix.
	* gimple-expr.c (extract_ops_from_tree_1): Renamed to ...
	(extract_ops_from_tree): ... this.
	* gimple.c (gimple_build_assign, gimple_assign_set_rhs_from_tree):
	Adjust callers.
	* tree-ssa-loop-niter.c (derive_constant_upper_bound): Likewise.
	* tree-ssa-forwprop.c (defcodefor_name): Call 3 operand
	extract_ops_from_tree instead of 2 operand one.

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

--- gcc/gimple-expr.h.jj	2016-01-04 14:55:50.000000000 +0100
+++ gcc/gimple-expr.h	2016-03-11 10:53:22.867513568 +0100
@@ -35,8 +35,8 @@ extern tree create_tmp_reg (tree, const
 extern tree create_tmp_reg_fn (struct function *, tree, const char *);
 
 
-extern void extract_ops_from_tree_1 (tree, enum tree_code *, tree *, tree *,
-				     tree *);
+extern void extract_ops_from_tree (tree, enum tree_code *, tree *, tree *,
+				   tree *);
 extern void gimple_cond_get_ops_from_tree (tree, enum tree_code *, tree *,
 					   tree *);
 extern bool is_gimple_lvalue (tree);
@@ -146,15 +146,15 @@ is_gimple_constant (const_tree t)
     }
 }
 
-/* A wrapper around extract_ops_from_tree_1, for callers which expect
-   to see only a maximum of two operands.  */
+/* A wrapper around extract_ops_from_tree with 3 ops, for callers which
+   expect to see only a maximum of two operands.  */
 
 static inline void
 extract_ops_from_tree (tree expr, enum tree_code *code, tree *op0,
 		       tree *op1)
 {
   tree op2;
-  extract_ops_from_tree_1 (expr, code, op0, op1, &op2);
+  extract_ops_from_tree (expr, code, op0, op1, &op2);
   gcc_assert (op2 == NULL_TREE);
 }
 
--- gcc/gimple-expr.c.jj	2016-01-07 09:45:20.000000000 +0100
+++ gcc/gimple-expr.c	2016-03-11 10:53:38.965302034 +0100
@@ -519,8 +519,8 @@ create_tmp_reg_fn (struct function *fn,
    *OP1_P, *OP2_P and *OP3_P respectively.  */
 
 void
-extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
-			 tree *op2_p, tree *op3_p)
+extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p,
+		       tree *op2_p, tree *op3_p)
 {
   enum gimple_rhs_class grhs_class;
 
--- gcc/gimple.c.jj	2016-01-19 13:31:09.000000000 +0100
+++ gcc/gimple.c	2016-03-11 10:52:36.124128366 +0100
@@ -387,7 +387,7 @@ gimple_build_assign (tree lhs, tree rhs
   enum tree_code subcode;
   tree op1, op2, op3;
 
-  extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3);
+  extract_ops_from_tree (rhs, &subcode, &op1, &op2, &op3);
   return gimple_build_assign (lhs, subcode, op1, op2, op3 PASS_MEM_STAT);
 }
 
@@ -1578,7 +1578,7 @@ gimple_assign_set_rhs_from_tree (gimple_
   enum tree_code subcode;
   tree op1, op2, op3;
 
-  extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3);
+  extract_ops_from_tree (expr, &subcode, &op1, &op2, &op3);
   gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2, op3);
 }
 
--- gcc/tree-ssa-forwprop.c.jj	2016-01-04 14:55:52.000000000 +0100
+++ gcc/tree-ssa-forwprop.c	2016-03-11 10:53:54.961091841 +0100
@@ -1477,7 +1477,7 @@ defcodefor_name (tree name, enum tree_co
 	   || GIMPLE_BINARY_RHS
 	   || GIMPLE_UNARY_RHS
 	   || GIMPLE_SINGLE_RHS)
-    extract_ops_from_tree_1 (name, &code1, &arg11, &arg21, &arg31);
+    extract_ops_from_tree (name, &code1, &arg11, &arg21, &arg31);
 
   *code = code1;
   *arg1 = arg11;
--- gcc/tree-ssa-loop-niter.c.jj	2016-02-24 14:52:16.000000000 +0100
+++ gcc/tree-ssa-loop-niter.c	2016-03-11 10:54:38.463520194 +0100
@@ -2742,9 +2742,9 @@ static widest_int
 derive_constant_upper_bound (tree val)
 {
   enum tree_code code;
-  tree op0, op1;
+  tree op0, op1, op2;
 
-  extract_ops_from_tree (val, &code, &op0, &op1);
+  extract_ops_from_tree (val, &code, &op0, &op1, &op2);
   return derive_constant_upper_bound_ops (TREE_TYPE (val), op0, code, op1);
 }
 
--- gcc/testsuite/gcc.dg/pr70177.c.jj	2016-03-11 10:58:49.211225229 +0100
+++ gcc/testsuite/gcc.dg/pr70177.c	2016-03-11 10:58:40.000000000 +0100
@@ -0,0 +1,15 @@
+/* PR tree-optimization/70177 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int b[128];
+
+void
+foo (int i, int j)
+{
+  int c, f, g, h;
+  for (g = 0; g < 64; g++)
+    for (h = g, f = 0; f <= i; f++, h++)
+      for (c = 0; c < j; c++)
+	b[h] = 0;
+}

	Jakub



More information about the Gcc-patches mailing list