diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2020-10-21 19:55:28 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2020-10-21 20:02:22 -0400 |
commit | ca5f4666f7a9404cdb04832324de3dd7d71e35c3 (patch) | |
tree | 1009d2a11e595ce97796371bcab61744f85f7581 /gcc | |
parent | 2ab1fc7a322e2582772f0e4ed916508c890175e3 (diff) | |
download | gcc-ca5f4666f7a9404cdb04832324de3dd7d71e35c3.zip gcc-ca5f4666f7a9404cdb04832324de3dd7d71e35c3.tar.gz gcc-ca5f4666f7a9404cdb04832324de3dd7d71e35c3.tar.bz2 |
Check for undefined before not returning a constant value
Don't return UNDEFINED for a range in an unreachable block if the global
value evaluates to a constant. Return that constant instead.
PR tree-optimization/97515
* value-query.cc (range_query::value_of_expr): If the result is
UNDEFINED, check to see if the global value is a constant.
(range_query::value_on_edge): Ditto.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/pr97515.c | 21 | ||||
-rw-r--r-- | gcc/value-query.cc | 23 |
2 files changed, 40 insertions, 4 deletions
diff --git a/gcc/testsuite/gcc.dg/pr97515.c b/gcc/testsuite/gcc.dg/pr97515.c new file mode 100644 index 0000000..2b6185e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97515.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int +e7 (int gg) +{ + int xe = 0; + + while (xe < 1) + { + int ui; + + ui = ~xe; + if (ui == 0) + ui = xe >> gg; + + xe %= !ui; + } + + return xe; +} diff --git a/gcc/value-query.cc b/gcc/value-query.cc index 5370a23..23ba48d 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -82,8 +82,16 @@ range_query::value_of_expr (tree name, gimple *stmt) if (!irange::supports_type_p (TREE_TYPE (name))) return NULL_TREE; - if (range_of_expr (r, name, stmt) && r.singleton_p (&t)) - return t; + + if (range_of_expr (r, name, stmt)) + { + // A constant used in an unreachable block oftens returns as UNDEFINED. + // If the result is undefined, check the global value for a constant. + if (r.undefined_p ()) + range_of_expr (r, name); + if (r.singleton_p (&t)) + return t; + } return NULL_TREE; } @@ -95,8 +103,15 @@ range_query::value_on_edge (edge e, tree name) if (!irange::supports_type_p (TREE_TYPE (name))) return NULL_TREE; - if (range_on_edge (r, e, name) && r.singleton_p (&t)) - return t; + if (range_on_edge (r, e, name)) + { + // A constant used in an unreachable block oftens returns as UNDEFINED. + // If the result is undefined, check the global value for a constant. + if (r.undefined_p ()) + range_of_expr (r, name); + if (r.singleton_p (&t)) + return t; + } return NULL_TREE; } |