gcc/
* gimple.h (gimple_cond_make_false): Require a gimple_cond.
(gimple_cond_make_true): Likewise.
* tree-cfg.c (fold_cond_expr_cond): Add a checked cast to
gimple_cond within region guarded by check for GIMPLE_COND.
* tree-ssa-ccp.c (ccp_fold_stmt): Likewise.
* tree-loop-distribution.c (generate_loops_for_partition): Replace
a check for GIMPLE_COND with a dyn_cast_gimple_cond.
* tree-ssa-ccp.c (optimize_unreachable): Likewise.
* tree-ssa-loop-niter.c (number_of_iterations_exit): Likewise.
* tree-ssa-pre.c (eliminate_dom_walker::before_dom_children):
Likewise.
* tree-vrp.c (fold_predicate_in): Add a checked cast to
gimple_cond. We must be dealing with a GIMPLE_COND since logic
at top of the function ensures we only act on GIMPLE_ASSIGN and
GIMPLE_COND statements, and we're now within a "not a GIMPLE_ASSIGN"
clause.
* tree-ssa-loop-ivcanon.c (remove_exits_and_undefined_stmts): Add
checked cast of elt->stmt to gimple_cond. The existing code requires
this to be a GIMPLE_COND, though it's not clear to me how this
requirement is enforced.
(remove_redundant_iv_tests): Likewise.
(try_unroll_loop_completely): Likewise, for the last_stmt of the
preceding bb along edge_to_cancel.
* tree-ssa-reassoc.c (maybe_optimize_range_tests): Likewise, for the
last_stmt of bb.
---
gcc/gimple.h | 4 ++--
gcc/tree-cfg.c | 11 +++++++----
gcc/tree-loop-distribution.c | 4 ++--
gcc/tree-ssa-ccp.c | 13 +++++++------
gcc/tree-ssa-loop-ivcanon.c | 17 +++++++++--------
gcc/tree-ssa-loop-niter.c | 10 +++++++---
gcc/tree-ssa-pre.c | 15 ++++++++-------
gcc/tree-ssa-reassoc.c | 15 ++++++++-------
gcc/tree-vrp.c | 5 +++--
9 files changed, 53 insertions(+), 41 deletions(-)
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 395c432..ed99d02 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3399,7 +3399,7 @@ gimple_cond_false_label (const_gimple gs)
/* Set the conditional COND_STMT to be of the form 'if (1 == 0)'. */
static inline void
-gimple_cond_make_false (gimple gs)
+gimple_cond_make_false (gimple_cond gs)
{
gimple_cond_set_lhs (gs, boolean_true_node);
gimple_cond_set_rhs (gs, boolean_false_node);
@@ -3410,7 +3410,7 @@ gimple_cond_make_false (gimple gs)
/* Set the conditional COND_STMT to be of the form 'if (1 == 1)'. */
static inline void
-gimple_cond_make_true (gimple gs)
+gimple_cond_make_true (gimple_cond gs)
{
gimple_cond_set_lhs (gs, boolean_true_node);
gimple_cond_set_rhs (gs, boolean_true_node);
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 68093de..1000bbb 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -548,13 +548,16 @@ fold_cond_expr_cond (void)
if (stmt && gimple_code (stmt) == GIMPLE_COND)
{
+ gimple_cond cond_stmt = stmt->as_a_gimple_cond ();
location_t loc = gimple_location (stmt);
tree cond;
bool zerop, onep;
fold_defer_overflow_warnings ();
- cond = fold_binary_loc (loc, gimple_cond_code (stmt),
boolean_type_node,
- gimple_cond_lhs (stmt), gimple_cond_rhs (stmt));
+ cond = fold_binary_loc (loc, gimple_cond_code (cond_stmt),
+ boolean_type_node,
+ gimple_cond_lhs (cond_stmt),
+ gimple_cond_rhs (cond_stmt));
if (cond)
{
zerop = integer_zerop (cond);
@@ -567,9 +570,9 @@ fold_cond_expr_cond (void)
stmt,
WARN_STRICT_OVERFLOW_CONDITIONAL);
if (zerop)
- gimple_cond_make_false (stmt);
+ gimple_cond_make_false (cond_stmt);
else if (onep)
- gimple_cond_make_true (stmt);
+ gimple_cond_make_true (cond_stmt);
}
}
}
diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index 8ce25f5..2d25277 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -680,9 +680,9 @@ generate_loops_for_partition (struct loop *loop,
partition_t partition,
{
/* Choose an arbitrary path through the empty CFG part
that this unnecessary control stmt controls. */
- if (gimple_code (stmt) == GIMPLE_COND)
+ if (gimple_cond cond_stmt = stmt->dyn_cast_gimple_cond ())
{
- gimple_cond_make_false (stmt);
+ gimple_cond_make_false (cond_stmt);
update_stmt (stmt);
}
else if (gimple_code (stmt) == GIMPLE_SWITCH)
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 3509d31..cc8c78b 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -2006,6 +2006,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
{
case GIMPLE_COND:
{
+ gimple_cond cond_stmt = stmt->as_a_gimple_cond ();
prop_value_t val;
/* Statement evaluation will handle type mismatches in constants
more gracefully than the final propagation. This allows us to
@@ -2025,9 +2026,9 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
}
if (integer_zerop (val.value))
- gimple_cond_make_false (stmt);
+ gimple_cond_make_false (cond_stmt);
else
- gimple_cond_make_true (stmt);
+ gimple_cond_make_true (cond_stmt);
return true;
}
@@ -2543,15 +2544,15 @@ optimize_unreachable (gimple_stmt_iterator i)
continue;
stmt = gsi_stmt (gsi);
- if (gimple_code (stmt) == GIMPLE_COND)
+ if (gimple_cond cond_stmt = stmt->dyn_cast_gimple_cond ())
{
if (e->flags & EDGE_TRUE_VALUE)
- gimple_cond_make_false (stmt);
+ gimple_cond_make_false (cond_stmt);
else if (e->flags & EDGE_FALSE_VALUE)
- gimple_cond_make_true (stmt);
+ gimple_cond_make_true (cond_stmt);
else
gcc_unreachable ();
- update_stmt (stmt);
+ update_stmt (cond_stmt);
}
else
{
diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c
index 6049f81..52f8e85 100644
--- a/gcc/tree-ssa-loop-ivcanon.c
+++ b/gcc/tree-ssa-loop-ivcanon.c
@@ -520,11 +520,12 @@ remove_exits_and_undefined_stmts (struct loop *loop,
unsigned int npeeled)
if (!loop_exit_edge_p (loop, exit_edge))
exit_edge = EDGE_SUCC (bb, 1);
gcc_checking_assert (loop_exit_edge_p (loop, exit_edge));
+ gimple_cond cond_stmt = elt->stmt->as_a_gimple_cond ();
if (exit_edge->flags & EDGE_TRUE_VALUE)
- gimple_cond_make_true (elt->stmt);
+ gimple_cond_make_true (cond_stmt);
else
- gimple_cond_make_false (elt->stmt);
- update_stmt (elt->stmt);
+ gimple_cond_make_false (cond_stmt);
+ update_stmt (cond_stmt);
changed = true;
}
}
@@ -573,11 +574,12 @@ remove_redundant_iv_tests (struct loop *loop)
fprintf (dump_file, "Removed pointless exit: ");
print_gimple_stmt (dump_file, elt->stmt, 0, 0);
}
+ gimple_cond cond_stmt = elt->stmt->as_a_gimple_cond ();
if (exit_edge->flags & EDGE_TRUE_VALUE)
- gimple_cond_make_false (elt->stmt);
+ gimple_cond_make_false (cond_stmt);
else
- gimple_cond_make_true (elt->stmt);
- update_stmt (elt->stmt);
+ gimple_cond_make_true (cond_stmt);
+ update_stmt (cond_stmt);
changed = true;
}
}
@@ -657,7 +659,6 @@ try_unroll_loop_completely (struct loop *loop,
location_t locus)
{
unsigned HOST_WIDE_INT n_unroll, ninsns, max_unroll, unr_insns;
- gimple cond;
struct loop_size size;
bool n_unroll_found = false;
edge edge_to_cancel = NULL;
@@ -854,7 +855,7 @@ try_unroll_loop_completely (struct loop *loop,
/* Remove the conditional from the last copy of the loop. */
if (edge_to_cancel)
{
- cond = last_stmt (edge_to_cancel->src);
+ gimple_cond cond = last_stmt (edge_to_cancel->src)->as_a_gimple_cond ();
if (edge_to_cancel->flags & EDGE_TRUE_VALUE)
gimple_cond_make_false (cond);
else
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 1d0ed34..5709ddd 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -1922,7 +1922,8 @@ number_of_iterations_exit (struct loop *loop, edge exit,
struct tree_niter_desc *niter,
bool warn, bool every_iteration)
{
- gimple stmt;
+ gimple last;
+ gimple_cond stmt;
tree type;
tree op0, op1;
enum tree_code code;
@@ -1935,8 +1936,11 @@ number_of_iterations_exit (struct loop *loop, edge exit,
return false;
niter->assumptions = boolean_false_node;
- stmt = last_stmt (exit->src);
- if (!stmt || gimple_code (stmt) != GIMPLE_COND)
+ last = last_stmt (exit->src);
+ if (!last)
+ return false;
+ stmt = last->dyn_cast_gimple_cond ();
+ if (!stmt)
return false;
/* We want the condition for staying inside loop. */
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index f081349..b8047a4 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -4315,25 +4315,26 @@ eliminate_dom_walker::before_dom_children (basic_block
b)
}
/* Visit COND_EXPRs and fold the comparison with the
available value-numbers. */
- else if (gimple_code (stmt) == GIMPLE_COND)
+ else if (gimple_cond cond_stmt = stmt->dyn_cast_gimple_cond ())
{
- tree op0 = gimple_cond_lhs (stmt);
- tree op1 = gimple_cond_rhs (stmt);
+ tree op0 = gimple_cond_lhs (cond_stmt);
+ tree op1 = gimple_cond_rhs (cond_stmt);
tree result;
if (TREE_CODE (op0) == SSA_NAME)
op0 = VN_INFO (op0)->valnum;
if (TREE_CODE (op1) == SSA_NAME)
op1 = VN_INFO (op1)->valnum;
- result = fold_binary (gimple_cond_code (stmt), boolean_type_node,
+ result = fold_binary (gimple_cond_code (cond_stmt),
+ boolean_type_node,
op0, op1);
if (result && TREE_CODE (result) == INTEGER_CST)
{
if (integer_zerop (result))
- gimple_cond_make_false (stmt);
+ gimple_cond_make_false (cond_stmt);
else
- gimple_cond_make_true (stmt);
- update_stmt (stmt);
+ gimple_cond_make_true (cond_stmt);
+ update_stmt (cond_stmt);
el_todo = TODO_cleanup_cfg;
}
}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 932d82b..47b7e8c 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -3009,18 +3009,19 @@ maybe_optimize_range_tests (gimple stmt)
&& bbinfo[idx].op == NULL_TREE
&& ops[bbinfo[idx].first_idx]->op != NULL_TREE)
{
- stmt = last_stmt (bb);
+ gimple_cond cond_stmt = last_stmt (bb)->as_a_gimple_cond ();
if (integer_zerop (ops[bbinfo[idx].first_idx]->op))
- gimple_cond_make_false (stmt);
+ gimple_cond_make_false (cond_stmt);
else if (integer_onep (ops[bbinfo[idx].first_idx]->op))
- gimple_cond_make_true (stmt);
+ gimple_cond_make_true (cond_stmt);
else
{
- gimple_cond_set_code (stmt, NE_EXPR);
- gimple_cond_set_lhs (stmt, ops[bbinfo[idx].first_idx]->op);
- gimple_cond_set_rhs (stmt, boolean_false_node);
+ gimple_cond_set_code (cond_stmt, NE_EXPR);
+ gimple_cond_set_lhs (cond_stmt,
+ ops[bbinfo[idx].first_idx]->op);
+ gimple_cond_set_rhs (cond_stmt, boolean_false_node);
}
- update_stmt (stmt);
+ update_stmt (cond_stmt);
}
if (bb == first_bb)
break;
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 902b879..62ec9f5 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -9517,10 +9517,11 @@ fold_predicate_in (gimple_stmt_iterator *si)
else
{
gcc_assert (gimple_code (stmt) == GIMPLE_COND);
+ gimple_cond cond_stmt = stmt->as_a_gimple_cond ();
if (integer_zerop (val))
- gimple_cond_make_false (stmt);
+ gimple_cond_make_false (cond_stmt);
else if (integer_onep (val))
- gimple_cond_make_true (stmt);
+ gimple_cond_make_true (cond_stmt);
else
gcc_unreachable ();
}
--
1.8.5.3