[InstCombine] Add select simplifications
authorQuentin Colombet <qcolombet@apple.com>
Wed, 20 Sep 2017 17:32:16 +0000 (17:32 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Wed, 20 Sep 2017 17:32:16 +0000 (17:32 +0000)
commitaa103b3d86c0bd9d1b4452244173990457af5a4e
treee757b8f0c038b9f2ef44896ab06283740aa5ac1a
parentd0320d528952991138fcc6f30ace0d8cada6d97b
[InstCombine] Add select simplifications

In these cases, two selects have constant selectable operands for
both the true and false components and have the same conditional
expression.
We then create two arithmetic operations of the same type and feed a
final select operation using the result of the true arithmetic for the true
operand and the result of the false arithmetic for the false operand and reuse
the original conditionl expression.
The arithmetic operations are naturally folded as a consequence, leaving
only the newly formed select to replace the old arithmetic operation.

Patch by: Michael Berg <michael_c_berg@apple.com>
Differential Revision: https://reviews.llvm.org/D37019

llvm-svn: 313774
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/select_arithmetic.ll [new file with mode: 0644]