[InstCombine] Reduce absolute diff from min+max+sub
authorJun Zhang <jun@junz.org>
Fri, 10 Mar 2023 00:00:41 +0000 (08:00 +0800)
committerJun Zhang <jun@junz.org>
Fri, 10 Mar 2023 00:00:40 +0000 (08:00 +0800)
commit3ecf731376cb4661d85c10932bd7bd7c11998ad8
tree846640986524c5d95b8a50b427b13dcf9371caa3
parent9e0c2626f3d4282a135da112320139d9fba32fb5
[InstCombine] Reduce absolute diff from min+max+sub

This patch implements fold: max(a,b) nsw/nuw - min(a,b) --> abs(a nsw - b)

Alive2: https://alive2.llvm.org/ce/z/4yLp7D
Fixes: https://github.com/llvm/llvm-project/issues/61228

Signed-off-by: Jun Zhang <jun@junz.org>
Differential Revision: https://reviews.llvm.org/D145540
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub-minmax.ll