[InstCombine] Fold ~A - Min/Max(~A, O) -> Max/Min(A, ~O) - A
authorDavid Green <david.green@arm.com>
Tue, 2 Oct 2018 09:48:34 +0000 (09:48 +0000)
committerDavid Green <david.green@arm.com>
Tue, 2 Oct 2018 09:48:34 +0000 (09:48 +0000)
commit1e44c3b62c3d80d438785f2dc0d2c7cff3f4389a
tree3ca7803fd93bec17d6619a90b3b44740e87bef04
parentae45d0a4fd772a01aeacc3d25891c4ead8acbc9a
[InstCombine] Fold ~A - Min/Max(~A, O) -> Max/Min(A, ~O) - A

This is an attempt to get out of a local-minimum that instcombine currently
gets stuck in. We essentially combine two optimisations at once, ~a - ~b = b-a
and min(~a, ~b) = ~max(a, b), only doing the transform if the result is at
least neutral. This involves using IsFreeToInvert, which has been expanded a
little to include selects that can be easily inverted.

This is trying to fix PR35875, using the ideas from Sanjay. It is a large
improvement to one of our rgb to cmy kernels.

Differential Revision: https://reviews.llvm.org/D52177

llvm-svn: 343569
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/test/Transforms/InstCombine/sub-minmax.ll