[PATCH] D114462: [InstSimplify] fold xor logic of 2 variables
Stanislav Mekhanoshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 23 11:31:31 PST 2021
rampitec accepted this revision.
rampitec added a comment.
This revision is now accepted and ready to land.
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.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114462/new/
https://reviews.llvm.org/D114462
More information about the llvm-commits
mailing list