]> granicus.if.org Git - llvm/commit
[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)
commit6de5879eecb1de26d10e69aebe0df7cb5d60035e
tree253d08070338692f9bfe1a0847e8635c02f0a39e
parent5c63b2cd251f9a670689516952167b644ff41512
[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.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354224 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/saturating-add-sub.ll