[llvm-commits] [PATCH] Reduce complexity of DAGCombiner

James Molloy james.molloy at arm.com
Wed Feb 15 02:57:48 PST 2012


Hi,

 

One of PlumHall's testcases generates a function with half a million
SDNodes. This brings out the O(n) complexity in DAGCombiner::AddToWorkList()
and means that in debug mode the test has not been seen to complete
compilation, and in release mode it takes several hours. KCacheGrind showed
99% of the time is being spent in std::remove, doing linear scans of the
DAGCombiner's worklist during AddToWorkList.

 

The problem the algorithm is trying to solve is: When inserting node N into
the worklist, check the worklist to see if it contains N. If so, remove it.
Then add N to the end of the worklist (first to be popped).

 

Reducing this to log(n) time requires use of a set and a vector, as
essentially you have two orderings. I wanted to use SetVector for this
purpose but SetVector::insert has a different semantic to what I need. On
insert, if N already exists it will do nothing (i.e. N will not be the first
item to be popped from the vector). This breaks the DAGCombiner.

 

My solution was to allow duplicate items in the vector, and on every pop to
query the set to see if the item should actually be in the vector. If not,
discard and grab the next item. This means that the vector could potentially
grow larger than it would previously.

 

I've implemented this directly in DAGCombiner without adding a separate ADT.
If people feel this is worthwhile, I could add another ADT or
template-specialise SetVector to have this behaviour? (I'm not too keen on
template specialization changing semantics however).

 

This change means that in release mode the testcase with half a million
nodes compiles in 30secs, and around 2 minutes in debug mode.

 

Please review!

 

Cheers,

 

James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120215/24bfc048/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: addtoworklist.patch
Type: application/octet-stream
Size: 3829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120215/24bfc048/attachment.obj>


More information about the llvm-commits mailing list