[InstCombine] Add support for max(a,b) + min(a,b) => a + b.
authorSerguei Katkov <serguei.katkov@azul.com>
Fri, 31 Mar 2023 02:35:06 +0000 (09:35 +0700)
committerSerguei Katkov <serguei.katkov@azul.com>
Fri, 7 Apr 2023 03:24:07 +0000 (10:24 +0700)
commitb86a06ef284f2637bef89bf5bb20157a8b195568
tree12483f70fd23116db45207d1b18c717a1cf11b17
parent5f036799f4d39c1aa5a6fac0e972050373e9fa78
[InstCombine] Add support for max(a,b) + min(a,b) => a + b.

The same optimization for
  max(a,b) * min(a,b) => a * b
is added.

Correctness check:
uadd: https://alive2.llvm.org/ce/z/2rXDek
sadd: https://alive2.llvm.org/ce/z/zNu_er
uadd + nuw/nsw: https://alive2.llvm.org/ce/z/EaiNjB
sadd + nuw/nsw: https://alive2.llvm.org/ce/z/w_2Nrs

umul: https://alive2.llvm.org/ce/z/dgXRLr
smul: https://alive2.llvm.org/ce/z/hBjGzz
umul + nuw/nsw: https://alive2.llvm.org/ce/z/EaiNjB
smul + nuw/nsw: https://alive2.llvm.org/ce/z/87MNeS

Reviewed By: goldstein.w.n
Differential Revision: https://reviews.llvm.org/D147296
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/add-min-max.ll
llvm/test/Transforms/InstCombine/mul-min-max.ll