[InstCombine] enhance icmp with sub folds
authorSanjay Patel <spatel@rotateright.com>
Sat, 9 Oct 2021 15:34:48 +0000 (11:34 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sat, 9 Oct 2021 15:39:49 +0000 (11:39 -0400)
commitacafde09a3fa9560148605f35f9c3d3f1444bc15
tree4b2b2fd817bed402f7ca7a59a60efb93c89d3947
parentcd76fa79b01aef8afe219323f713ca1607d7a98f
[InstCombine] enhance icmp with sub folds

There were 2 related but over-specified folds for:
C1 - X == C

One allowed multi-use but was limited to equal constants.
The other allowed different constants but disallowed multi-use.

This combines the 2 folds into a more general match.
The test diffs show the multi-use cases that were falling
through the cracks.

https://alive2.llvm.org/ce/z/4_hEt2

  define i1 @src(i8 %x, i8 %subC, i8 %C) {
    %s = sub i8 %subC, %x
    %r = icmp eq i8 %s, %C
    ret i1 %r
  }

  define i1 @tgt(i8 %x, i8 %subC, i8 %C) {
    %newC = sub i8 %subC, %C
    %isneg = icmp eq i8 %x, %newC
    ret i1 %isneg
  }
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-sub.ll