[InstCombine] canonicalize "(C2 - Y) > C" as (Y + ~C2) < ~C
authorSanjay Patel <spatel@rotateright.com>
Sun, 10 Oct 2021 14:58:58 +0000 (10:58 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sun, 10 Oct 2021 15:06:49 +0000 (11:06 -0400)
commitda210f5d3425e8877ceabaf6ed3483d52cbd7448
treec4063454652411d6080beba8f01e9fa4e4c5b408
parentc00cab878aa523e20a5dbd618e9852e191504cfe
[InstCombine] canonicalize "(C2 - Y) > C" as (Y + ~C2) < ~C

The test diffs show that we have better analysis/folds for 'add'
(although we should at least have the simplifications
independently, so we don't have the one-use restriction).

This is related to solving regressions that would appear in
transforms related to D111410, and that is part of a series
of enhancements that may eventually helpi solve PR34047.

https://alive2.llvm.org/ce/z/3tB9KG

  define i1 @src(i8 %x, i8 %C, i8 %C2) {
    %sub = sub nuw i8 %C2, %x
    %r = icmp slt i8 %sub, %C
    ret i1 %r
  }

  define i1 @tgt(i8 %x, i8 %C, i8 %C2) {
    %Cnot = xor i8 %C, -1
    %C2not = xor i8 %C2, -1
    %add = add nuw i8 %x, %C2not
    %r = icmp sgt i8 %add, %Cnot
    ret i1 %r
  }
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll
llvm/test/Transforms/InstCombine/icmp-sub.ll
llvm/test/Transforms/InstCombine/or.ll