diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2022-04-25 09:56:35 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2022-04-25 09:58:53 -0400 |
commit | 362e2a9c6297203bcf7f66bfb51dffb82b42d3b3 (patch) | |
tree | 01abff06b790a4d219fa4951900128723aa45313 | |
parent | 46cd445fc0714cc6c834b680c3f59dbad0b94a3c (diff) |
Retain existing range knowledge when prefilling statements.
When range_of_stmt was adjusted to avoid large recursion depth, we need to
intersect the calculated range whth the any known range to avoid losing
info. Range_of_stmt does this, but the new prefill code missed it.
PR tree-optimization/105276
gcc/
* gimple-range.cc (gimple_ranger::prefill_stmt_dependencies): Include
existing global range with calculated value.
gcc/testsuite/
* g++.dg/pr105276.C: New.
-rw-r--r-- | gcc/gimple-range.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/pr105276.C | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 04075a98a80..f0caefce2a3 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -394,6 +394,10 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa) // Fold and save the value for NAME. stmt = SSA_NAME_DEF_STMT (name); fold_range_internal (r, stmt, name); + // Make sure we don't lose any current global info. + int_range_max tmp; + m_cache.get_global_range (tmp, name); + r.intersect (tmp); m_cache.set_global_range (name, r); } continue; diff --git a/gcc/testsuite/g++.dg/pr105276.C b/gcc/testsuite/g++.dg/pr105276.C new file mode 100644 index 00000000000..ad0e9dd7e09 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr105276.C @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +bool +foo(unsigned i) +{ + bool result = true; + while (i) + { + i = i % 3; + i = i - (i == 2 ? 2 : i ? 1 : 0); + result = !result; + } + return result; +} + +/* We should be able to eliminate the i - operation. */ +/* { dg-final { scan-tree-dump-not "i_.* - " "optimized" } } */ |