[PATCH] D112276: [InstCombine] Fold `(c & ~(a | b)) | (b & ~(a | c))` to `~a & (b ^ c)`

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 26 13:12:46 PDT 2021


rampitec added a comment.

In D112276#3088469 <https://reviews.llvm.org/D112276#3088469>, @rampitec wrote:

> In D112276#3088399 <https://reviews.llvm.org/D112276#3088399>, @lebedev.ri wrote:
>
>> In D112276#3088380 <https://reviews.llvm.org/D112276#3088380>, @spatel wrote:
>>
>>> @lebedev.ri - do you have any suggestions for how to specify that constraint in the code?
>>
>> There is no nice way to do that, we are missing some common infra.
>> What you want is to check that at least one of the hands of the outer `or` is single-use,
>> and either the other hand is one-use either, or the `not` operand of the single-use hand is also single-use.
>
> I can see an awkward way to do this, count a sum of `(int)hasOneUse()` expressions and compare to 7. Definitely do not like it.

Potentially I can see a specialized version of `match()` taking 2 additional arguments: pointer to unsigned to return a number of multiply used values in the pattern matched and another unsigned argument to limit this and stop the match as soon as the limit is reached.
For this case for example first call will have all `m_OneUse()` removed. The first limit will be `4` and for the second call it will be `4 - NumMutliUsedValues` returned by the first call.
Maybe not a most elegant interface though, and certainly a separate change if we even want it.


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

https://reviews.llvm.org/D112276



More information about the llvm-commits mailing list