Reapply [InstCombine] Simplify select operand based on equality condition
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 10 Sep 2020 16:45:53 +0000 (18:45 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 16 Sep 2020 18:53:58 +0000 (20:53 +0200)
commit222bf3ffbc8419570fc2266a2e7d1c5f58cedaa7
treece790f24276ee9ea6a784b77bc7e737dd74d77ea
parent0bb06f297fe52a5125952cb6f1e264b4e7c48097
Reapply [InstCombine] Simplify select operand based on equality condition

Reapply after fixing SimplifyWithOpReplaced() to never return
the original value, which would lead to an infinite loop in this
transform.

-----

For selects of the type X == Y ? A : B, check if we can simplify A
by using the X == Y equality and replace the operand if that's
possible. We already try to do this in InstSimplify, but will only
fold if the result of the simplification is the same as B, in which
case the select can be dropped entirely. Here the select will be
retained, just one operand simplified.

As we are performing an actual replacement here, we don't have
problems with refinement / poison values.

Differential Revision: https://reviews.llvm.org/D87480
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/rem.ll
llvm/test/Transforms/InstCombine/select-binop-cmp.ll
llvm/test/Transforms/InstCombine/select.ll