[PATCH] D114126: [PatternMatch] Create match method to track uses complexity. WIP.

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 18 01:49:17 PST 2021


rampitec added a comment.

In D114126#3139528 <https://reviews.llvm.org/D114126#3139528>, @lebedev.ri wrote:

> I'm somewhat unconvinced that we can solve this problem at the match stage.
> Consider
>
>   v0 = a + c
>   v1 = v0 + c
>   v2 = v1 + c
>   r = v2 + c
>
> if you do `match(m_Add(m_Add(m_Add(m_Add(m_Value(A), m_Value(C)), m_Specific(C)), m_Specific(C)), m_Specific(C)))`,
> i think `UseComplexity` will be 4(?), but that doesn't mean that you can create 4 instructions,
> in reality it depends on the pattern you will produce. If you want to produce a + 4*c, sure, you can do that,
> because none of the instructions you matched are used in the pattern. But if you want to produce
> `v2 + 1*c`, you can not, because that would increase instruction count...

In that match complexity will be zero because none of the values have more than one use. Than you can rule what is your complexity to use as a limit based on your target transform, just like I did in the example transform with 4 instructions being a threshold just on the grounds of comparing source and target code.

The assumption is that all that instructions go away after transform except those which have uses outside of the source pattern. And then even if not you can adjust the limit. I guess I will have to do it where I am reusing a subexpression, because a reused value shall not count, it just stays, but that needs a proper handling of m_CombineAnd as a max of complexity of its operands, which I have not done yet. Then speaking of that m_CombineOr shall use a complexity of a selected leg.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114126/new/

https://reviews.llvm.org/D114126



More information about the llvm-commits mailing list