[InstCombine] canonicalize cmp/select form of uadd saturate with constant
authorSanjay Patel <spatel@rotateright.com>
Tue, 29 Jan 2019 20:02:45 +0000 (20:02 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 29 Jan 2019 20:02:45 +0000 (20:02 +0000)
commit18db56209c8bf07322aa968571a79acb13c437a6
tree1776bde7bc7ba788d8dcb7135f0fece7d715f96c
parent3f8b9166989709d1d893524f5590f8064e824554
[InstCombine] canonicalize cmp/select form of uadd saturate with constant

I'm circling back around to a loose end from D51929.

The backend (either CGP or DAG) doesn't recognize this pattern, so we end up with different asm for these IR variants.

Regardless of any future changes to canonicalize to saturation/overflow intrinsics, we want to get raw IR variations
into the minimal number of raw IR forms. If/when we can canonicalize to intrinsics, that will make that step easier.

  Pre: C2 == ~C1
  %a = add i32 %x, C1
  %c = icmp ugt i32 %x, C2
  %r = select i1 %c, i32 -1, i32 %a
  =>
  %a = add i32 %x, C1
  %c2 = icmp ult i32 %x, C2
  %r = select i1 %c2, i32 %a, i32 -1

  https://rise4fun.com/Alive/pkH

Differential Revision: https://reviews.llvm.org/D57352

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