Add transforms for `(max/min (xor X, Pow2), X)` -> `(and/or X, Pow2/~Pow2)`
authorNoah Goldstein <goldstein.w.n@gmail.com>
Thu, 23 Feb 2023 00:36:49 +0000 (18:36 -0600)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Fri, 24 Feb 2023 21:22:09 +0000 (15:22 -0600)
commitf35e3fa53bb7173a8f8ccda8eb017a7ccd986800
tree66cab11e16cbe9f637c0c3aae1da8b87edb281a7
parent890eb4f0a150bce6e4057e946b8d9c0ba5f811fe
Add transforms for `(max/min (xor X, Pow2), X)` -> `(and/or X, Pow2/~Pow2)`

X ^ Pow2 is guranteed to flip one bit. We can use this to speedup
max/min by just selecting X with/without (or/andnot) the flipped bit
respectively.

Alive2 Links:
smax-neg: https://alive2.llvm.org/ce/z/j3QYFs
smin-neg: https://alive2.llvm.org/ce/z/bFYnQW
smax-pos: https://alive2.llvm.org/ce/z/4xYSxR
smin-pos: https://alive2.llvm.org/ce/z/H3RPKj
umax    : https://alive2.llvm.org/ce/z/P4oRcX
umin    : https://alive2.llvm.org/ce/z/vWZG6p

Differential Revision: https://reviews.llvm.org/D144606
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/minmax-of-xor-x.ll