summaryrefslogtreecommitdiff
path: root/gcc/fold-const.h
diff options
context:
space:
mode:
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-08 16:49:24 +0000
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-08 16:49:24 +0000
commitee23033372b5fa1a237d4d536721be287e74bc54 (patch)
tree61678cfe315bf4f20ccae0603f837d13eeab72a5 /gcc/fold-const.h
parent58111f65c1d006a4a124b1145e464661da723725 (diff)
downloadgcc-ee23033372b5fa1a237d4d536721be287e74bc54.tar.gz
Make tree_expr_nonnegative_warnv_p recurse into SSA names
The upcoming patch to move sqrt and cbrt simplifications to match.pd caused a regression because the (abs @0)->@0 simplification didn't trigger for: (abs (convert (abs X))) The simplification is based on tree_expr_nonnegative_p, which at the moment just gives up if it sees an SSA_NAME. This patch makes tree_expr_nonnegative_p recurse into SSA name definitions, but limits the depth of recursion to a small number for the reason mentioned in the comment (adapted from an existing comment in gimple_val_nonnegative_real_p). The patch reuses code in tree-vrp.c, moving it to gimple-fold.c. It also replaces calls to gimple_val_nonnegative_real_p with calls to tree_expr_nonnegative_p. A knock-on effect is that we can now prove _i_589 < 0 is false in sequences like: i_1917 = ASSERT_EXPR <i_1075, i_1075 == 0>; _i_589 = (const int) i_1917; _i_1507 = ASSERT_EXPR <_i_589, _i_589 < 0>; This defeats an assert in tree-vrp.c that ASSERT_EXPR conditions are never known to be false. Previously the assert only ever used local knowledge and so would be limited to cases like x != x for integer x. Now that we use global knowledge it's possible to prove the assertion condition is false in blocks that are in practice unreachable. The patch therefore removes the assert. Bootstrapped & regression-tested on x86_64-linux-gnu. I didn't write a specific test because this is already covered by the testsuite if the follow-on patch is also applied. gcc/ * params.def (PARAM_MAX_SSA_NAME_QUERY_DEPTH): New param. * doc/invoke.texi (--param max-ssa-name-query-depth): Document. * fold-const.h (tree_unary_nonnegative_warnv_p) (tree_single_nonnegative_warnv_p, tree_call_nonnegative_warnv_p) (tree_expr_nonnegative_warnv_p): Add depth parameters. * fold-const.c: Include gimple-fold.h and params.h. (tree_ssa_name_nonnegative_warnv_p): New function. (tree_unary_nonnegative_warnv_p, tree_binary_nonnegative_warnv_p) (tree_single_nonnegative_warnv_p, tree_call_nonnegative_warnv_p) (tree_invalid_nonnegative_warnv_p, tree_expr_nonnegative_warnv_p): Add a depth parameter and increment it for recursive calls to tree_expr_nonnegative_warnv_p. Use tree_ssa_name_nonnegative_warnv_p to handle SSA names. * gimple-fold.h (gimple_val_nonnegative_real_p): Delete. (gimple_stmt_nonnegative_warnv_p): Declare. * tree-vrp.c (remove_range_assertions): Remove assert that condition cannot be proven false. (gimple_assign_nonnegative_warnv_p, gimple_call_nonnegative_warnv_p) (gimple_stmt_nonnegative_warnv_p): Move to... * gimple-fold.c: ...here. Add depth parameters and pass them down to the tree routines. Accept statements that aren't assignments or calls but just return false for them. (gimple_val_nonnegative_real_p): Delete. * tree-ssa-math-opts.c (gimple_expand_builtin_pow): Use tree_expr_nonnegative_p instead of gimple_val_nonnegative_real_p. Check HONOR_NANs first. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228614 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.h')
-rw-r--r--gcc/fold-const.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index 4a31e62600f..ee74dc87b6b 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -132,11 +132,13 @@ extern bool tree_unary_nonzero_warnv_p (enum tree_code, tree, tree, bool *);
extern bool tree_binary_nonzero_warnv_p (enum tree_code, tree, tree, tree op1,
bool *);
extern bool tree_single_nonzero_warnv_p (tree, bool *);
-extern bool tree_unary_nonnegative_warnv_p (enum tree_code, tree, tree, bool *);
+extern bool tree_unary_nonnegative_warnv_p (enum tree_code, tree, tree,
+ bool *, int);
extern bool tree_binary_nonnegative_warnv_p (enum tree_code, tree, tree, tree,
- bool *);
-extern bool tree_single_nonnegative_warnv_p (tree t, bool *strict_overflow_p);
-extern bool tree_call_nonnegative_warnv_p (tree, tree, tree, tree, bool *);
+ bool *, int);
+extern bool tree_single_nonnegative_warnv_p (tree, bool *, int);
+extern bool tree_call_nonnegative_warnv_p (tree, tree, tree, tree, bool *,
+ int);
extern bool fold_real_zero_addition_p (const_tree, const_tree, int);
extern tree combine_comparisons (location_t, enum tree_code, enum tree_code,
@@ -160,7 +162,7 @@ extern tree size_diffop_loc (location_t, tree, tree);
extern tree non_lvalue_loc (location_t, tree);
extern bool tree_expr_nonnegative_p (tree);
-extern bool tree_expr_nonnegative_warnv_p (tree, bool *);
+extern bool tree_expr_nonnegative_warnv_p (tree, bool *, int = 0);
extern tree make_range (tree, int *, tree *, tree *, bool *);
extern tree make_range_step (location_t, enum tree_code, tree, tree, tree,
tree *, tree *, int *, bool *);