This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] tree-vrp.c: Remove has_assert_expr.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dnovillo at redhat dot com
- Date: Wed, 04 May 2005 10:52:13 -0400 (EDT)
- Subject: [patch] tree-vrp.c: Remove has_assert_expr.
Hi,
Attached is a patch to remove has_assert_expr as it is currently a
no-op.
AFAICT, has_assert_expr was designed to avoid insertions of redundant
ASSERT_EXPRs. For example, given
p->a = 3;
p->b = 5;
we do not want to insert two ASSERT_EXPRs like so
p->a = 3;
p = ASSERT_EXPR <p, p != 0B>;
p->b = 5;
p = ASSERT_EXPR <p, p != 0B>;
because the second is totally redundant given the first one. However,
it's not functioning at all. The reason is that it always returns
false immediately.
if (TREE_CODE (def_stmt) != MODIFY_EXPR
|| TREE_CODE (TREE_OPERAND (def_stmt, 1)) != ASSERT_EXPR)
return false;
While inserting ASSERT_EXPRs, there is no SSA_NAME that has at least
one use and is defined by an ASERT_EXPR. This is because ASSERT_EXPRs
are born in VRP. They aren't present in prior passes.
Tested on i686-pc-linux-gnu. OK to apply?
p.s.
I am playing with a quick-n-dirty pruning now. Specifically, for each
SSA_NAME, I am keeping track of a basic block where a "nonnull"
ASSERT_EXPR is last inserted. This cuts down the number of
ASSERT_EXPRs significantly, about 50%. I'll post a separate message
about this.
Kazu Hirata
2005-05-04 Kazu Hirata <kazu@cs.umass.edu>
PR tree-optimization/pr21348
* tree-vrp.c (has_assert_expr): Remove.
(maybe_add_assert_expr): Don't call has_assert_expr.
Index: tree-vrp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.16
diff -u -d -p -r2.16 tree-vrp.c
--- tree-vrp.c 2 May 2005 22:54:37 -0000 2.16
+++ tree-vrp.c 3 May 2005 02:23:50 -0000
@@ -1431,61 +1431,6 @@ infer_value_range (tree stmt, tree op)
}
-/* Return true if OP is the result of an ASSERT_EXPR that tests the
- same condition as COND. */
-
-static bool
-has_assert_expr (tree op, tree cond)
-{
- tree def_stmt = SSA_NAME_DEF_STMT (op);
- tree assert_expr, other_cond, other_op;
-
- /* If OP was not generated by an ASSERT_EXPR, return false. */
- if (TREE_CODE (def_stmt) != MODIFY_EXPR
- || TREE_CODE (TREE_OPERAND (def_stmt, 1)) != ASSERT_EXPR)
- return false;
-
- assert_expr = TREE_OPERAND (def_stmt, 1);
- other_cond = ASSERT_EXPR_COND (assert_expr);
- other_op = ASSERT_EXPR_VAR (assert_expr);
-
- if (TREE_CODE (cond) == TREE_CODE (other_cond))
- {
- tree t1, t2;
-
- /* If COND is not a comparison predicate, something is wrong. */
- gcc_assert (COMPARISON_CLASS_P (cond));
-
- /* Note that we only need to compare against one of the operands
- of OTHER_COND.
-
- Suppose that we are about to insert the assertion ASSERT_EXPR
- <x_4, x_4 != 0> and the defining statement for x_4 is x_4 =
- ASSERT_EXPR <x_3, x_3 != 0>.
-
- In this case, we don't really want to insert a new
- ASSERT_EXPR for x_4 because that would be redundant. We
- already know that x_4 is not 0. So, when comparing the
- conditionals 'x_3 != 0' and 'x_4 != 0', we don't want to
- compare x_3 and x_4, we just want to compare the predicate's
- code (!=) and the other operand (0). */
- if (TREE_OPERAND (cond, 0) == op)
- t1 = TREE_OPERAND (cond, 1);
- else
- t1 = TREE_OPERAND (cond, 0);
-
- if (TREE_OPERAND (other_cond, 0) == other_op)
- t2 = TREE_OPERAND (other_cond, 1);
- else
- t2 = TREE_OPERAND (other_cond, 0);
-
- return (t1 == t2 || operand_equal_p (t1, t2, 0));
- }
-
- return false;
-}
-
-
/* Traverse all the statements in block BB looking for used variables.
Variables used in BB are added to bitmap FOUND. The algorithm
works in three main parts:
@@ -1584,9 +1529,6 @@ maybe_add_assert_expr (basic_block bb)
(unless OP already has an ASSERT_EXPR). */
gcc_assert (!is_ctrl_stmt (stmt));
- if (has_assert_expr (op, cond))
- continue;
-
if (!stmt_ends_bb_p (stmt))
{
/* If STMT does not end the block, we can insert the new