diff options
author | Jeff Law <law@redhat.com> | 2013-04-09 07:05:08 -0600 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2013-04-09 07:05:08 -0600 |
commit | a32dfe9d0614b2460957ee107baf25e88ff3f026 (patch) | |
tree | 4c26150320e73f69086aed708a6b834ab32644cb /gcc/tree-vrp.c | |
parent | ab4425be3016e8e144c9a4971ad78cb32bbbfa65 (diff) | |
download | gcc-a32dfe9d0614b2460957ee107baf25e88ff3f026.zip gcc-a32dfe9d0614b2460957ee107baf25e88ff3f026.tar.gz gcc-a32dfe9d0614b2460957ee107baf25e88ff3f026.tar.bz2 |
tree-vrp.c (simplify_cond_using_ranges): Simplify test of boolean when the boolean was created by converting a wider...
* 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
From-SVN: r197631
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r-- | gcc/tree-vrp.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 250a506..e1b88a9 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; } |