This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] ((~a & ~b & c) | ~(a | b | c) -> ~(a | b)
AbandonedPublic

Authored by rampitec on Dec 21 2021, 3:05 PM.

Details

Reviewers
spatel
Summary

This is a version of (~(a | b) & c) | ~(a | b | c) -> ~(a | b) which is
already handled. However, LHS needs demorganing for the transformation to
happen and it is not demorganed if there are multiple uses of the ~a or ~b.

----------------------------------------
define i4 @src(i4 %a, i4 %b, i4 %c) {
%0:
  %or1 = or i4 %b, %c
  %or2 = or i4 %or1, %a
  %not1 = xor i4 %or2, 15
  %nota = xor i4 %a, 15
  %notb = xor i4 %b, 15
  %and1 = and i4 %nota, %notb
  %and2 = and i4 %and1, %c
  %or4 = or i4 %and2, %not1
  ret i4 %or4
}
=>
define i4 @tgt(i4 %a, i4 %b, i4 %c) {
%0:
  %or = or i4 %a, %b
  %not = xor i4 %or, 15
  ret i4 %not
}
Transformation seems to be correct!

The inverted case: (~a | ~b | c) | ~(a & b & c) -> ~(a & b)

----------------------------------------
define i4 @src(i4 %a, i4 %b, i4 %c) {
%0:
  %and1 = and i4 %b, %c
  %and2 = and i4 %and1, %a
  %not1 = xor i4 %and2, 15
  %nota = xor i4 %a, 15
  %notb = xor i4 %b, 15
  %or1 = or i4 %nota, %notb
  %or2 = or i4 %or1, %c
  %and4 = and i4 %or2, %not1
  ret i4 %and4
}
=>
define i4 @tgt(i4 %a, i4 %b, i4 %c) {
%0:
  %and = and i4 %a, %b
  %not = xor i4 %and, 15
  ret i4 %not
}
Transformation seems to be correct!

Diff Detail

Unit TestsFailed

Event Timeline

rampitec created this revision.Dec 21 2021, 3:05 PM
rampitec requested review of this revision.Dec 21 2021, 3:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2021, 3:05 PM

I will precommit tests if that is generally OK.

Handling of all the code in the previous block dealing with (~(A | B) & C) is possible, but will overcomplicate the patch a lot and not exactly trivial for the symmetrical case (~(A | B) & C) | (~(A | C) & B).

In general a lot of things would become easier after D114126 if accepted.

rampitec updated this revision to Diff 396072.Dec 23 2021, 11:59 AM

Fixed formatting.
It will go under the same LHS as above after D116231 (plus it will need some more tests in this case).

rampitec abandoned this revision.Feb 3 2022, 2:03 PM