[llvm] [DAG] foldAddToAvg - split nested m_Reassociatable matchers (PR #171681)
Artur Bermond Torres via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 14 09:20:32 PST 2025
bermondd wrote:
> perhaps changing the container type (from `SmallVector<SDValue>`) as you pointed out in another place has a larger impact
Sadly, I think the results were pretty small as well. Here: https://llvm-compile-time-tracker.com/compare.php?from=f785ca0d72cc37ac951afe81cba37c292b0027eb&to=755a6932993b8ef02082860fad2c72df4ca85a72&stat=instructions%3Au
But at least the crashes related to `SmallVector` should be fixed now. I'll try to look into a way to improve the `O(n!)` sometime this week.
By the way, another possible improvement besides splitting the ADD / AND could be to move the nested AND to the leftmost position, swapping the `m_Deferred`s and `m_Value`s. As `m_Reassociatable` tries to match each pattern in the order they were provided, if you do it like that, you avoid having to recompute the expensive inner AND with every failed attempt to match the previous two during the ADD. If I'm thinking of this right, then doing it like this reduces the complexity from `O(n! * m!)` to `O((n * m!) + (n-1)!)`, where `n` is the number of patterns in the ADD and `m` in the AND.
https://github.com/llvm/llvm-project/pull/171681
More information about the llvm-commits
mailing list