From: Jeff Law Date: Thu, 10 Dec 2015 19:40:23 +0000 (-0700) Subject: re PR tree-optimization/61515 (Extremely long compile time for generated code) X-Git-Tag: releases/gcc-4.9.4~454 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e76a494420b0f23c2a21f97be12412f34c1ea2a3;p=thirdparty%2Fgcc.git re PR tree-optimization/61515 (Extremely long compile time for generated code) PR tree-optimization/61515 PR tree-optimization/46590 Backport from mainline. * tree-ssa-threadedge.c (invalidate_equivalences): Walk the unwinding stack rather than looking at every SSA_NAME's value. From-SVN: r231542 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 38477faf1b95..cf789fb94381 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-12-10 Jeff Law + + PR tree-optimization/61515 + PR tree-optimization/46590 + Backport from mainline. + * tree-ssa-threadedge.c (invalidate_equivalences): Walk the unwinding + stack rather than looking at every SSA_NAME's value. + 2015-12-10 Uros Bizjak Backport from mainline diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index c715e842d997..149af547e3eb 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -282,15 +282,40 @@ fold_assignment_stmt (gimple stmt) } /* A new value has been assigned to LHS. If necessary, invalidate any - equivalences that are no longer valid. */ + equivalences that are no longer valid. This includes invaliding + LHS and any objects that are currently equivalent to LHS. + + Finding the objects that are currently marked as equivalent to LHS + is a bit tricky. We could walk the ssa names and see if any have + SSA_NAME_VALUE that is the same as LHS. That's expensive. + + However, it's far more efficient to look at the unwinding stack as + that will have all context sensitive equivalences which are the only + ones that we really have to worry about here. */ static void invalidate_equivalences (tree lhs, vec *stack) { - for (unsigned int i = 1; i < num_ssa_names; i++) - if (ssa_name (i) && SSA_NAME_VALUE (ssa_name (i)) == lhs) - record_temporary_equivalence (ssa_name (i), NULL_TREE, stack); + /* The stack is an unwinding stack. If the current element is NULL + then it's a "stop unwinding" marker. Else the current marker is + the SSA_NAME with an equivalence and the prior entry in the stack + is what the current element is equivalent to. */ + for (int i = stack->length() - 1; i >= 0; i--) + { + /* Ignore the stop unwinding markers. */ + if ((*stack)[i] == NULL) + continue; + + /* We want to check the current value of stack[i] to see if + it matches LHS. If so, then invalidate. */ + if (SSA_NAME_VALUE ((*stack)[i]) == lhs) + record_temporary_equivalence ((*stack)[i], NULL_TREE, stack); + + /* Remember, we're dealing with two elements in this case. */ + i--; + } + /* And invalidate any known value for LHS itself. */ if (SSA_NAME_VALUE (lhs)) record_temporary_equivalence (lhs, NULL_TREE, stack); }