CodeGenDAGPatterns::GenerateVariants is a costly function in many tblgen commands (33.87% of the total runtime of x86 -gen-dag-isel), and due to the O(N^2) nature of the function, there are a lot of repeated comparisons of the pattern's vector<Predicate> (19.9% of the total runtime of x86 -gen-dag-isel).
This initial patch at least avoids repeating these comparisons for every Variant per pattern. I began investigating caching all the matches before entering the loop but hit issues with how best to store the data and how to update the cache as patterns were added - until thats solved, this is at least an improvement.
Also, its not clear to me if the inner loop over PatternsToMatch needs to compare against the extra patterns generated in the function or not - if not it should be possible to split these loops and reduce its quadratic nature. @kparzysz can you confirm please?
Saves around 15secs in debug builds of x86 -gen-dag-isel.