[PATCH] D114462: [InstSimplify] fold xor logic of 2 variables

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 23 12:46:04 PST 2021


spatel added a comment.

In D114462#3149477 <https://reviews.llvm.org/D114462#3149477>, @rampitec wrote:

> LGTM.
>
> Thanks Sanjay! This really helps D113216 <https://reviews.llvm.org/D113216> with -O3, but then not a more complex version of it which needs demorganing and reassociation:
>
>   ; (~a & ~b & c) | ~(a | (b | c)) -> ~(a | b)
>   ; (~a & ~b & c) | ~(b | (a | c)) -> ~(a | b)
>   
>   define i32 @not_and_not_and_or_not_or_or(i32 %a, i32 %b, i32 %c) {
>   ; CHECK-LABEL: @not_and_not_and_or_not_or_or(
>   ; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
>   ; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR3]], -1
>   ; CHECK-NEXT:    ret i32 [[NOT2]]
>   ;
>     %or1 = or i32 %b, %c
>     %or2 = or i32 %or1, %a
>     %not1 = xor i32 %or2, -1
>     %nota = xor i32 %a, -1
>     %notb = xor i32 %b, -1
>     %and1 = and i32 %nota, %notb
>     %and2 = and i32 %and1, %c
>     %or4 = or i32 %and2, %not1
>     call void @use(i32 %nota)
>     call void @use(i32 %notb)
>     ret i32 %or4
>   }
>   
>   declare void @use(i32)
>
> In this case reassociation is blocked by uses, so I was looking into extending LHS match in D113216 <https://reviews.llvm.org/D113216> to catch `(~a & ~b & c)` in addition to `(~(a | b) & c)`. I still need to look into that, but this is clearly LGTM.

Thanks!
Yes, I think we'll always be able to find cracks in the logic folds that allow some cases to get through.
If we can find a few more of these simplifications/combines though, I wonder if that will be enough to handle all of the patterns in the source example that you showed in D112276 <https://reviews.llvm.org/D112276>?


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

https://reviews.llvm.org/D114462



More information about the llvm-commits mailing list