[PATCH] D122152: [InstCombine] Fold two select patterns into and-or

chenglin.bi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 08:49:05 PDT 2022


bcl5980 added a comment.

In D122152#3411428 <https://reviews.llvm.org/D122152#3411428>, @spatel wrote:

> LGTM.
>
> It's not clear how much of 'or' bitwise logic combining we want to replicate for select-of-bools, but this seems ok for now.
>
> Ie, if we are willing to freeze, then any select-of-bools can be converted to logic ops. If the condition is itself composed of bitwise logic with a repeated value, then there's probably some logic reduction that can happen. For example if we change the 'not' on one of the patterns here:
> https://alive2.llvm.org/ce/z/BsyhPk

Thanks for the finding.
i1 logic space with add is an abel group(should be ring)
and -> a * b
xor  -> a + b
or    -> a * b + a + b
not  -> a + 1
select -> c * a + (c + 1) * b

we can use this to simiplify all select with i1 types.
for example:
condition  (~a | c) - > (a + 1) * c + a + 1 + c -> a * c + c + a + 1 +c -> a * c + a + 1
select (~a | c), a, b -> (a * c + a + 1) * a + (a * c + a + 1 + 1) * b -> 
a * a * c + a * a + a + a * c * b + a * b ->
a * c + a + a + a * b * c + a * b ->
a * c + a * b + a * b * c ->
a * (c + b + b * c) ->
and a, (or b, c)

I'm not sure if we need to do this in code or not in the future.
@spatel Can you help me to check in the code ? 
name: chenglin.bi
email: chenglin.bi at cixcomputing.com


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

https://reviews.llvm.org/D122152



More information about the llvm-commits mailing list