[InstCombine] reduce more unsigned saturated add with 'not' op
authorSanjay Patel <spatel@rotateright.com>
Sun, 17 Feb 2019 16:48:50 +0000 (16:48 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 17 Feb 2019 16:48:50 +0000 (16:48 +0000)
commitb341ee7071c1e836d8ebd3d2ef25a78fdab8da32
tree77593ee72e823d4005baada98fdaecee1d3b010d
parentdb02293d9dd572e146f85a65d103f08f59449dc6
[InstCombine] reduce more unsigned saturated add with 'not' op

We want to use the sum in the icmp to allow matching with
m_UAddWithOverflow and eliminate the 'not'. This is discussed
in D51929 and is another step towards solving PR14613:
https://bugs.llvm.org/show_bug.cgi?id=14613

  Name: not op
  %notx = xor i32 %x, -1
  %a = add i32 %x, %y
  %c = icmp ult i32 %notx, %y
  %r = select i1 %c, i32 -1, i32 %a
  =>
  %a = add i32 %x, %y
  %c2 = icmp ult i32 %a, %y
  %r = select i1 %c2, i32 -1, i32 %a

  Name: not op ugt
  %notx = xor i32 %x, -1
  %a = add i32 %x, %y
  %c = icmp ugt i32 %y, %notx
  %r = select i1 %c, i32 -1, i32 %a
  =>
  %a = add i32 %x, %y
  %c2 = icmp ult i32 %a, %y
  %r = select i1 %c2, i32 -1, i32 %a

https://rise4fun.com/Alive/niom

(The matching here is still incomplete.)

llvm-svn: 354224
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/saturating-add-sub.ll