From 84dd478f2b83f54ebb2577a751c7d2b31bdc5c21 Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Sat, 23 Oct 2004 18:00:01 +0000 Subject: [PATCH] tree-ssa-dom.c (record_equality): Use loop depth to determine which way to record the equality as well. 2004-10-23 Daniel Berlin * tree-ssa-dom.c (record_equality): Use loop depth to determine which way to record the equality as well. (loop_depth_of_name): New function. From-SVN: r89491 --- gcc/ChangeLog | 6 ++++++ gcc/tree-ssa-dom.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fa86a45990c..10a63b38763 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-10-23 Daniel Berlin + + * tree-ssa-dom.c (record_equality): Use loop depth to determine + which way to record the equality as well. + (loop_depth_of_name): New function. + 2004-10-23 Eric Botcazou PR middle-end/17793 diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index c74537ca79b..edd74e03c2e 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -1491,6 +1491,35 @@ record_const_or_copy_1 (tree x, tree y, tree prev_x) VARRAY_PUSH_TREE (const_and_copies_stack, x); } + +/* Return the loop depth of the basic block of the defining statement of X. + This number should not be treated as absolutely correct because the loop + information may not be completely up-to-date when dom runs. However, it + will be relatively correct, and as more passes are taught to keep loop info + up to date, the result will become more and more accurate. */ + +static int +loop_depth_of_name (tree x) +{ + tree defstmt; + basic_block defbb; + + /* If it's not an SSA_NAME, we have no clue where the definition is. */ + if (TREE_CODE (x) != SSA_NAME) + return 0; + + /* Otherwise return the loop depth of the defining statement's bb. + Note that there may not actually be a bb for this statement, if the + ssa_name is live on entry. */ + defstmt = SSA_NAME_DEF_STMT (x); + defbb = bb_for_stmt (defstmt); + if (!defbb) + return 0; + + return defbb->loop_depth; +} + + /* Record that X is equal to Y in const_and_copies. Record undo information in the block-local varray. */ @@ -1522,12 +1551,13 @@ record_equality (tree x, tree y) if (TREE_CODE (y) == SSA_NAME) prev_y = SSA_NAME_VALUE (y); - /* If one of the previous values is invariant, then use that. + /* If one of the previous values is invariant, or invariant in more loops + (by depth), then use that. Otherwise it doesn't matter which value we choose, just so long as we canonicalize on one value. */ if (TREE_INVARIANT (y)) ; - else if (TREE_INVARIANT (x)) + else if (TREE_INVARIANT (x) || (loop_depth_of_name (x) <= loop_depth_of_name (y))) prev_x = x, x = y, y = prev_x, prev_x = prev_y; else if (prev_x && TREE_INVARIANT (prev_x)) x = y, y = prev_x, prev_x = prev_y; -- 2.30.2