[PATCH] D40874: [LV][LoopInfo] Add irreducible CFG detection for outer loops

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 12:58:24 PST 2018


dberlin added a comment.

Hey, can you help me understand the algorithm?
I don't have a good feel for the invariants you expect going in.
It just says "it works on anything given loop info".
IE What info you expect the loopinfo to provide vs the topo ordering.

There are lots of ways to test for reducibility, and it's unclear which you are using here (and why that should be used if the loop info isn't around, for example).

To make it simple, let's take the canonical irreducible graph

  A->B
  A->C
  B->C
  C->B
  C->D
  
       A
   /        \
  B<- -> C
               |
               D

What do you expect to happen here? What do you expect the loopinfo to provide vs the RPO.

The algorithms i'm familiar with to detect irreducibility don't need the loop info:

1. T1/T2
2. Tarjan's algorithm, which is basically (this is borrowed from eric stolz)

  test_dom(a,b) returns TRUE if a dominates b
  push( v ) pushes v onto a reverse topologically-sorted stack
  
  
  Invoke: top_sort( entry node )
  
  
  top_sort( node v ) {
        mark_visited( v );
        Visit all successors s of v {
                if( mark_visited( s ) && !pushed( s ) && !test_dom( s, v ) ) {
                            Irreducible_Graph = TRUE;
                            Exit -- no need to continue now!
                }
                if( !mark_visited( s ) )
                            top_sort( s );
        }
        push( v );
  }



3. (another variant of tarjan's) Build a DFST, remove the back edges, see if the result is acylic.

It's true you can use loop info, but given the dom test is O(1) i'm not sure why it's worth computing to test irreducibility, especially if you are doing an RPO computation anyway.
Can you help me understand the algorithm being used here and why?


https://reviews.llvm.org/D40874





More information about the llvm-commits mailing list