summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-dom.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/tree-ssa-dom.c')
-rw-r--r--gcc/tree-ssa-dom.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 829863794a3..3eeaa9cdcf9 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -387,11 +387,16 @@ record_edge_info (basic_block bb)
/* Special case comparing booleans against a constant as we
know the value of OP0 on both arms of the branch. i.e., we
- can record an equivalence for OP0 rather than COND. */
- if ((code == EQ_EXPR || code == NE_EXPR)
- && TREE_CODE (op0) == SSA_NAME
+ can record an equivalence for OP0 rather than COND.
+
+ However, don't do this if the constant isn't zero or one.
+ Such conditionals will get optimized more thoroughly during
+ the domwalk. */
+ if ((code == EQ_EXPR || code == NE_EXPR)
+ && TREE_CODE (op0) == SSA_NAME
&& ssa_name_has_boolean_range (op0)
- && is_gimple_min_invariant (op1))
+ && is_gimple_min_invariant (op1)
+ && (integer_zerop (op1) || integer_onep (op1)))
{
tree true_val = constant_boolean_node (true, TREE_TYPE (op0));
tree false_val = constant_boolean_node (false, TREE_TYPE (op0));
@@ -1828,6 +1833,31 @@ optimize_stmt (basic_block bb, gimple_stmt_iterator si,
}
}
+ if (gimple_code (stmt) == GIMPLE_COND)
+ {
+ tree lhs = gimple_cond_lhs (stmt);
+ tree rhs = gimple_cond_rhs (stmt);
+
+ /* If the LHS has a range [0..1] and the RHS has a range ~[0..1],
+ then this conditional is computable at compile time. We can just
+ shove either 0 or 1 into the LHS, mark the statement as modified
+ and all the right things will just happen below.
+
+ Note this would apply to any case where LHS has a range
+ narrower than its type implies and RHS is outside that
+ narrower range. Future work. */
+ if (TREE_CODE (lhs) == SSA_NAME
+ && ssa_name_has_boolean_range (lhs)
+ && TREE_CODE (rhs) == INTEGER_CST
+ && ! (integer_zerop (rhs) || integer_onep (rhs)))
+ {
+ gimple_cond_set_lhs (as_a <gcond *> (stmt),
+ fold_convert (TREE_TYPE (lhs),
+ integer_zero_node));
+ gimple_set_modified (stmt, true);
+ }
+ }
+
update_stmt_if_modified (stmt);
eliminate_redundant_computations (&si, const_and_copies,
avail_exprs_stack);