[COMMITTED] Avoid threading circular paths.

Message ID 20211021081205.875196-1-aldyh@redhat.com
State Committed
Commit e53fbb17839723ea1697fcbaf76b1c092675eaaf
Headers
Series [COMMITTED] Avoid threading circular paths. |

Commit Message

Aldy Hernandez Oct. 21, 2021, 8:12 a.m. UTC
  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.

Committed as obvious.

gcc/ChangeLog:

	* tree-ssa-threadbackward.c (back_threader::maybe_register_path):
	Avoid threading circular paths.
---
 gcc/tree-ssa-threadbackward.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Jeff Law Oct. 21, 2021, 2:35 p.m. UTC | #1
On 10/21/2021 2:12 AM, Aldy Hernandez wrote:
> 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.
>
> Committed as obvious.
>
> gcc/ChangeLog:
>
> 	* tree-ssa-threadbackward.c (back_threader::maybe_register_path):
> 	Avoid threading circular paths.
I noticed you already reverted.  I won't complain about the morning test 
results :-)

Jeff
  
Aldy Hernandez Oct. 21, 2021, 2:37 p.m. UTC | #2
Sorry, I tried to revert as soon as I noticed, but it's always a race
against the 20 CI bots and fuzzers that keep us honest ;-).

Aldy

On Thu, Oct 21, 2021 at 4:35 PM Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
>
> On 10/21/2021 2:12 AM, Aldy Hernandez wrote:
> > 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.
> >
> > Committed as obvious.
> >
> > gcc/ChangeLog:
> >
> >       * tree-ssa-threadbackward.c (back_threader::maybe_register_path):
> >       Avoid threading circular paths.
> I noticed you already reverted.  I won't complain about the morning test
> results :-)
>
> Jeff
>
>
  

Patch

diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index d94e3b962db..38913b06717 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);