aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range-fold.cc
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2021-11-23 14:12:29 -0500
committerAndrew MacLeod <amacleod@redhat.com>2021-11-25 08:44:27 -0500
commit661c02e54ea72fb55205df0a717951ff28bb739e (patch)
tree95da0613a67a1427bd0c59a55fabe050cd158b0e /gcc/gimple-range-fold.cc
parentf4e470d44e8104bada6a95c12765f6ed8bd505e2 (diff)
downloadgcc-661c02e54ea72fb55205df0a717951ff28bb739e.zip
gcc-661c02e54ea72fb55205df0a717951ff28bb739e.tar.gz
gcc-661c02e54ea72fb55205df0a717951ff28bb739e.tar.bz2
Check for equivalences between PHI argument and def.
If a PHI argument on an edge is equivalent with the DEF, then it doesn't provide any new information, defer processing it unless they are all equivalences. PR tree-optimization/103359 gcc/ * gimple-range-fold.cc (fold_using_range::range_of_phi): If arg is equivalent to def, don't initially include it's range. gcc/testsuite/ * gcc.dg/pr103359.c: New.
Diffstat (limited to 'gcc/gimple-range-fold.cc')
-rw-r--r--gcc/gimple-range-fold.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index ec9690b..d66ada5 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -771,6 +771,7 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src)
tree phi_def = gimple_phi_result (phi);
tree type = gimple_range_type (phi);
int_range_max arg_range;
+ int_range_max equiv_range;
unsigned x;
if (!type)
@@ -794,6 +795,16 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src)
// Get the range of the argument on its edge.
src.get_phi_operand (arg_range, arg, e);
+ // Likewise, if the incoming PHI argument is equivalent to this
+ // PHI definition, it provides no new info. Accumulate these ranges
+ // in case all arguments are equivalences.
+ if (src.query ()->query_relation (e, arg, phi_def, false) == EQ_EXPR)
+ {
+ single_arg = arg;
+ equiv_range.union_(arg_range);
+ continue;
+ }
+
if (!arg_range.undefined_p ())
{
// Register potential dependencies for stale value tracking.
@@ -816,6 +827,11 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src)
break;
}
+ // If all arguments were equivalences, use the equivalence ranges as no
+ // arguments were processed.
+ if (!seen_arg)
+ r = equiv_range;
+
// If the PHI boils down to a single effective argument, look at it.
if (single_arg)
{