]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid threading circular paths.
authorAldy Hernandez <aldyh@redhat.com>
Wed, 20 Oct 2021 16:52:45 +0000 (18:52 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Thu, 21 Oct 2021 08:10:45 +0000 (10:10 +0200)
The backward threader keeps a hash of visited blocks to avoid crossing
the same block twice.  Interestingly, we haven't been checking it for
the final block out of the path.  This may be inherited from the old
code, as it was simple enough that it didn't matter.  With the
upcoming changes enabling the fully resolving threader, it gets
tripped often enough to cause wrong code to be generated.

Tested on x86-64 Linux.

gcc/ChangeLog:

* tree-ssa-threadbackward.c (back_threader::maybe_register_path):
Avoid threading circular paths.

gcc/tree-ssa-threadbackward.c

index d94e3b962db415bb071b771c0331be5aa127aa5d..38913b06717c5d01bb9da311e605460abd0a08a3 100644 (file)
@@ -140,6 +140,10 @@ back_threader::maybe_register_path ()
 
   if (taken_edge && taken_edge != UNREACHABLE_EDGE)
     {
+      // Avoid circular paths.
+      if (m_visited_bbs.contains (taken_edge->dest))
+       return UNREACHABLE_EDGE;
+
       bool irreducible = false;
       bool profitable
        = m_profit.profitable_path_p (m_path, m_name, taken_edge, &irreducible);