From 83b58b6b0e75383fb01cd65b29a8fa1779050269 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 4 Dec 2015 17:23:27 +0100 Subject: [PATCH] re PR tree-optimization/68671 (gcc.dg/torture/pr66952.c FAILs with -fno-tree-dce) PR tree-optimization/68671 * tree-ssa-reassoc.c (maybe_optimize_range_tests): For basic blocks starting with the successor of first bb we've modified and ending with last_bb call reset_flow_sensitive_info_in_bb. * gcc.dg/pr68671.c: New test. From-SVN: r231278 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr68671.c | 23 +++++++++++++++++++++++ gcc/tree-ssa-reassoc.c | 18 +++++++++++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr68671.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a3bde22653e..446e74b3468 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-12-04 Jakub Jelinek + + PR tree-optimization/68671 + * tree-ssa-reassoc.c (maybe_optimize_range_tests): For basic + blocks starting with the successor of first bb we've modified + and ending with last_bb call reset_flow_sensitive_info_in_bb. + 2015-12-04 Jeff Law * tree-ssa-reassoc.c (maybe_optimize_range_tests): Return boolean diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4b1b1a3cee3..1a037e6c1dc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-12-04 Jakub Jelinek + + PR tree-optimization/68671 + * gcc.dg/pr68671.c: New test. + 2015-12-02 Jeff Law * gcc.dg/tree-ssa/reassoc-43.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr68671.c b/gcc/testsuite/gcc.dg/pr68671.c new file mode 100644 index 00000000000..bec4639f80a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr68671.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/68671 */ +/* { dg-do run } */ +/* { dg-options " -O2 -fno-tree-dce" } */ + +volatile int a = -1; +volatile int b; + +static inline int +fn1 (signed char p1, int p2) +{ + return (p1 < 0) || (p1 > (1 >> p2)) ? 0 : (p1 << 1); +} + +int +main () +{ + signed char c = a; + b = fn1 (c, 1); + c = ((128 | c) < 0 ? 1 : 0); + if (c != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 315b0bfc7ff..e54700e2271 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -3211,7 +3211,7 @@ maybe_optimize_range_tests (gimple *stmt) any_changes = optimize_range_tests (ERROR_MARK, &ops); if (any_changes) { - unsigned int idx; + unsigned int idx, max_idx = 0; /* update_ops relies on has_single_use predicates returning the same values as it did during get_ops earlier. Additionally it never removes statements, only adds new ones and it should walk @@ -3227,6 +3227,7 @@ maybe_optimize_range_tests (gimple *stmt) { tree new_op; + max_idx = idx; stmt = last_stmt (bb); new_op = update_ops (bbinfo[idx].op, (enum tree_code) @@ -3296,6 +3297,10 @@ maybe_optimize_range_tests (gimple *stmt) && ops[bbinfo[idx].first_idx]->op != NULL_TREE) { gcond *cond_stmt = as_a (last_stmt (bb)); + + if (idx > max_idx) + max_idx = idx; + /* If we collapse the conditional to a true/false condition, then bubble that knowledge up to our caller. */ if (integer_zerop (ops[bbinfo[idx].first_idx]->op)) @@ -3320,6 +3325,17 @@ maybe_optimize_range_tests (gimple *stmt) if (bb == first_bb) break; } + + /* The above changes could result in basic blocks after the first + modified one, up to and including last_bb, to be executed even if + they would not be in the original program. If the value ranges of + assignment lhs' in those bbs were dependent on the conditions + guarding those basic blocks which now can change, the VRs might + be incorrect. As no_side_effect_bb should ensure those SSA_NAMEs + are only used within the same bb, it should be not a big deal if + we just reset all the VRs in those bbs. See PR68671. */ + for (bb = last_bb, idx = 0; idx < max_idx; bb = single_pred (bb), idx++) + reset_flow_sensitive_info_in_bb (bb); } return cfg_cleanup_needed; } -- 2.30.2