[PATCH] D116135: [InstCombine] ((~a & ~b & c) | ~(a | b | c) -> ~(a | b)

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 21 15:05:02 PST 2021


rampitec created this revision.
rampitec added a reviewer: spatel.
Herald added a subscriber: hiraditya.
rampitec requested review of this revision.
Herald added a project: LLVM.

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!


https://reviews.llvm.org/D116135

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  llvm/test/Transforms/InstCombine/and-xor-or.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116135.395759.patch
Type: text/x-patch
Size: 30035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211221/ceca5d33/attachment-0001.bin>


More information about the llvm-commits mailing list