[InstCombine] narrow min/max intrinsics with extended inputs
authorSanjay Patel <spatel@rotateright.com>
Sun, 24 Jan 2021 17:57:11 +0000 (12:57 -0500)
committerSanjay Patel <spatel@rotateright.com>
Mon, 25 Jan 2021 12:52:50 +0000 (07:52 -0500)
commit09a136bcc6947128df86492d88f1733bdff745d1
treefe7948478e7113beadbfd2ddb207a0f66a972dbd
parent07b60d0060688dea121be36b46de859bafcec29b
[InstCombine] narrow min/max intrinsics with extended inputs

We can sink extends after min/max if they match and would
not change the sign-interpreted compare. The only combo
that doesn't work is zext+smin/smax because the zexts
could change a negative number into positive:
https://alive2.llvm.org/ce/z/D6sz6J

Sext+umax/umin works:

  define i32 @src(i8 %x, i8 %y) {
  %0:
    %sx = sext i8 %x to i32
    %sy = sext i8 %y to i32
    %m = umax i32 %sx, %sy
    ret i32 %m
  }
  =>
  define i32 @tgt(i8 %x, i8 %y) {
  %0:
    %m = umax i8 %x, %y
    %r = sext i8 %m to i32
    ret i32 %r
  }
  Transformation seems to be correct!
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/minmax-intrinsics.ll