]> granicus.if.org Git - llvm/commit
[InstCombine] move add after smin/smax
authorSanjay Patel <spatel@rotateright.com>
Sat, 2 Mar 2019 16:45:10 +0000 (16:45 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sat, 2 Mar 2019 16:45:10 +0000 (16:45 +0000)
commit20aaebbdebe3a6e61bee3bccac98843f300f4d0f
tree54ba227703316c07ce1e56b979d3084bdf8c4688
parent1f4f16a829d3caa7a79027879fa465c2c301ddc6
[InstCombine] move add after smin/smax

Follow-up to rL355221.
This isn't specifically called for within PR14613,
but we'll get there eventually if it's not already
requested in some other bug report.

https://rise4fun.com/Alive/5b0

  Name: smax
  Pre: WillNotOverflowSignedSub(C1,C0)
  %a = add nsw i8 %x, C0
  %cond = icmp sgt i8 %a, C1
  %r = select i1 %cond, i8 %a, i8 C1
  =>
  %c2 = icmp sgt i8 %x, C1-C0
  %u2 = select i1 %c2, i8 %x, i8 C1-C0
  %r = add nsw i8 %u2, C0

  Name: smin
  Pre: WillNotOverflowSignedSub(C1,C0)
  %a = add nsw i32 %x, C0
  %cond = icmp slt i32 %a, C1
  %r = select i1 %cond, i32 %a, i32 C1
  =>
  %c2 = icmp slt i32 %x, C1-C0
  %u2 = select i1 %c2, i32 %x, i32 C1-C0
  %r = add nsw i32 %u2, C0

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355272 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/minmax-fold.ll