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

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 1 14:23:47 PDT 2021


rampitec added a comment.

A side note: a shorter form would be `(~a & b & c) | ~(b | c) -> ~((a & b) | (b ^ c))`, however it is only mathematically correct and does not verify since it is more undefined than the source:

  ----------------------------------------
  define i4 @src(i4 %a, i4 %b, i4 %c) {
  %0:
    %or1 = or i4 %b, %c
    %not1 = xor i4 %or1, 15
    %and1 = and i4 %a, %not1
    %xor1 = xor i4 %b, %c
    %or2 = or i4 %xor1, %a
    %not2 = xor i4 %or2, 15
    %or3 = or i4 %and1, %not2
    ret i4 %or3
  }
  =>
  define i4 @tgt(i4 %a, i4 %b, i4 %c) {
  %0:
    %and = and i4 %a, %b
    %not1 = xor i4 %b, %c
    %or = or i4 %and, %not1
    %not2 = xor i4 %or, 15
    ret i4 %not2
  }
  Transformation doesn't verify!
  
  ERROR: Target's return value is more undefined
  
  Example:
  i4 %a = #xf (15, -1)
  i4 %b = undef
  i4 %c = #xf (15, -1)
  
  Source:
  i4 %or1 = #xf (15, -1)
  i4 %not1 = #x0 (0)
  i4 %and1 = #x0 (0)
  i4 %xor1 = any
  i4 %or2 = #xf (15, -1)
  i4 %not2 = #x0 (0)
  i4 %or3 = #x0 (0)
  
  Target:
  i4 %and = #x6 (6)
  i4 %not1 = #x8 (8, -8)
  i4 %or = #xe (14, -2)
  i4 %not2 = #x1 (1)
  Source value: #x0 (0)
  Target value: #x1 (1)


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

https://reviews.llvm.org/D112955



More information about the llvm-commits mailing list