summaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2013-04-09 13:05:08 +0000
committerlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2013-04-09 13:05:08 +0000
commit813adf93a967dd2ea307d5cfa3ff7f565f8af6d5 (patch)
tree4c26150320e73f69086aed708a6b834ab32644cb /gcc/tree-vrp.c
parenteb21fcc14b14cc349aec869d0320174c2b5eebc7 (diff)
downloadgcc-813adf93a967dd2ea307d5cfa3ff7f565f8af6d5.tar.gz
* tree-vrp.c (simplify_cond_using_ranges): Simplify test of boolean
when the boolean was created by converting a wider object which had a boolean range. * gcc.dg/tree-ssa/vrp87.c: New test git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@197631 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 250a5063136..e1b88a9e138 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -8584,6 +8584,45 @@ simplify_cond_using_ranges (gimple stmt)
}
}
+ /* If we have a comparison of a SSA_NAME boolean against
+ a constant (which obviously must be [0..1]), see if the
+ SSA_NAME was set by a type conversion where the source
+ of the conversion is another SSA_NAME with a range [0..1].
+
+ If so, we can replace the SSA_NAME in the comparison with
+ the RHS of the conversion. This will often make the type
+ conversion dead code which DCE will clean up. */
+ if (TREE_CODE (op0) == SSA_NAME
+ && (TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE
+ || (INTEGRAL_TYPE_P (TREE_TYPE (op0))
+ && TYPE_PRECISION (TREE_TYPE (op0)) == 1))
+ && TREE_CODE (op1) == INTEGER_CST)
+ {
+ gimple def_stmt = SSA_NAME_DEF_STMT (op0);
+ tree innerop;
+
+ if (!is_gimple_assign (def_stmt)
+ || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt)))
+ return false;
+
+ innerop = gimple_assign_rhs1 (def_stmt);
+
+ if (TREE_CODE (innerop) == SSA_NAME)
+ {
+ value_range_t *vr = get_value_range (innerop);
+
+ if (range_int_cst_p (vr)
+ && operand_equal_p (vr->min, integer_zero_node, 0)
+ && operand_equal_p (vr->max, integer_one_node, 0))
+ {
+ tree newconst = fold_convert (TREE_TYPE (innerop), op1);
+ gimple_cond_set_lhs (stmt, innerop);
+ gimple_cond_set_rhs (stmt, newconst);
+ return true;
+ }
+ }
+ }
+
return false;
}