aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-threadbackward.c
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2021-10-20 18:52:45 +0200
committerAldy Hernandez <aldyh@redhat.com>2021-10-26 08:20:11 +0200
commite53fbb17839723ea1697fcbaf76b1c092675eaaf (patch)
tree09bd29a57fc2480cb725925c6d0a0a2b0031fd6e /gcc/tree-ssa-threadbackward.c
parent8a04a5fb07f94a2154b362741104f9d48d3e612d (diff)
downloadgcc-e53fbb17839723ea1697fcbaf76b1c092675eaaf.zip
gcc-e53fbb17839723ea1697fcbaf76b1c092675eaaf.tar.gz
gcc-e53fbb17839723ea1697fcbaf76b1c092675eaaf.tar.bz2
Avoid threading circular paths.
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.
Diffstat (limited to 'gcc/tree-ssa-threadbackward.c')
-rw-r--r--gcc/tree-ssa-threadbackward.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index a6b9893a..d9ce056 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -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);