[InstCombine] generalize canonicalization of masked equality comparisons
authorSanjay Patel <spatel@rotateright.com>
Sat, 25 Apr 2020 15:25:03 +0000 (11:25 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sat, 25 Apr 2020 15:31:57 +0000 (11:31 -0400)
commit4abab5c5ca7b562b80fdb5fb6279e6d2104dae16
treeb821845c65a53e04d21e8fa6297a1a225926e726
parent46a04940e85cea7d37d7791d18f940a49868c955
[InstCombine] generalize canonicalization of masked equality comparisons

  (X | MaskC) == C --> (X & ~MaskC) == C ^ MaskC
  (X | MaskC) != C --> (X & ~MaskC) != C ^ MaskC

We have more analyis for 'and' patterns and already lean this way
in the existing code, so this should be neutral or better in IR.

If this does not do as well in codegen, the problem already exists
and we should fix that based on target costs/heuristics.

http://volta.cs.utah.edu:8080/z/oP3ecL

define void @src(i8 %x, i8 %OrC, i8 %C, i1* %p0, i1* %p1) {
  %or = or i8 %x, %OrC
  %eq = icmp eq i8 %or, %C
  store i1 %eq, i1* %p0

  %ne = icmp ne i8 %or, %C
  store i1 %ne, i1* %p1
  ret void
}

define void @tgt(i8 %x, i8 %OrC, i8 %C, i1* %p0, i1* %p1) {
  %NotOrC = xor i8 %OrC, -1
  %a = and i8 %x, %NotOrC
  %NewC = xor i8 %C, %OrC
  %eq = icmp eq i8 %a, %NewC
  store i1 %eq, i1* %p0

  %ne = icmp ne i8 %a, %NewC
  store i1 %ne, i1* %p1
  ret void
}
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/and-or-icmps.ll
llvm/test/Transforms/InstCombine/assume2.ll
llvm/test/Transforms/InstCombine/icmp-or.ll
llvm/test/Transforms/InstCombine/icmp.ll
llvm/test/Transforms/InstCombine/load-cmp.ll