[InstCombine] move add after umin/umax
authorSanjay Patel <spatel@rotateright.com>
Fri, 1 Mar 2019 19:42:40 +0000 (19:42 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 1 Mar 2019 19:42:40 +0000 (19:42 +0000)
commit6e1e7e1c3ecc66db573ebd85c5d9570e0665b248
treeed2148503bb488a1b068f151f1673da4c18fadd0
parent20292a0526869b45e72f58bec272dd9b68f4aa4a
[InstCombine] move add after umin/umax

In the motivating cases from PR14613:
https://bugs.llvm.org/show_bug.cgi?id=14613
...moving the add enables us to narrow the
min/max which eliminates zext/trunc which
enables signficantly better vectorization.
But that bug is still not completely fixed.

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

  Name: umax
  Pre: C1 u>= C0
  %a = add nuw i8 %x, C0
  %cond = icmp ugt i8 %a, C1
  %r = select i1 %cond, i8 %a, i8 C1
  =>
  %c2 = icmp ugt i8 %x, C1-C0
  %u2 = select i1 %c2, i8 %x, i8 C1-C0
  %r = add nuw i8 %u2, C0

  Name: umin
  Pre: C1 u>= C0
  %a = add nuw i32 %x, C0
  %cond = icmp ult i32 %a, C1
  %r = select i1 %cond, i32 %a, i32 C1
  =>
  %c2 = icmp ult i32 %x, C1-C0
  %u2 = select i1 %c2, i32 %x, i32 C1-C0
  %r = add nuw i32 %u2, C0

llvm-svn: 355221
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/minmax-fold.ll