[InstCombine] Add support for max(a,b) + min(a,b) => a + b. Re-land.
authorSerguei Katkov <serguei.katkov@azul.com>
Fri, 7 Apr 2023 04:16:29 +0000 (11:16 +0700)
committerSerguei Katkov <serguei.katkov@azul.com>
Fri, 7 Apr 2023 04:56:05 +0000 (11:56 +0700)
commit624973806c5644ccfa84805319b5852edb68d48d
treebef2ee0e9b79c65c73f9e98c637eff7ad9259c45
parent371cb1af61d668234a242b34c773c146cb9077e7
[InstCombine] Add support for max(a,b) + min(a,b) => a + b. Re-land.

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