summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Bolvansky <david.bolvansky@gmail.com>2018-08-12 17:30:07 +0000
committerDavid Bolvansky <david.bolvansky@gmail.com>2018-08-12 17:30:07 +0000
commit01d98cc03f777054e398510d047e06a650e9d466 (patch)
tree6f6f7bec0881ff5a348a330c6bd5b49e71195742 /llvm/lib
parentdc185ee27551c0ed5a66ca999bab6794c39b30f4 (diff)
downloadbcm5719-llvm-01d98cc03f777054e398510d047e06a650e9d466.tar.gz
bcm5719-llvm-01d98cc03f777054e398510d047e06a650e9d466.zip
[InstCombine] Fold Select with binary op - non-commutative opcodes
Summary: Basic version was merged - https://reviews.llvm.org/D49954 This adds support for FP & non-commutative opcodes Precommited tests: https://reviews.llvm.org/rL338727 Reviewers: spatel, lebedev.ri Reviewed By: spatel Subscribers: jfb Differential Revision: https://reviews.llvm.org/D50190 llvm-svn: 339520
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 61e917fd4f8..dc8e8df421e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -68,15 +68,16 @@ static Instruction *foldSelectBinOpIdentity(SelectInst &Sel) {
// A select operand must be a binop, and the compare constant must be the
// identity constant for that binop.
- // TODO: Support non-commutative binops.
bool IsEq = Pred == ICmpInst::ICMP_EQ;
BinaryOperator *BO;
if (!match(Sel.getOperand(IsEq ? 1 : 2), m_BinOp(BO)) ||
- ConstantExpr::getBinOpIdentity(BO->getOpcode(), BO->getType(), false) != C)
+ ConstantExpr::getBinOpIdentity(BO->getOpcode(), BO->getType(), true) != C)
return nullptr;
// Last, match the compare variable operand with a binop operand.
Value *Y;
+ if (!BO->isCommutative() && !match(BO, m_BinOp(m_Value(Y), m_Specific(X))))
+ return nullptr;
if (!match(BO, m_c_BinOp(m_Value(Y), m_Specific(X))))
return nullptr;
OpenPOWER on IntegriCloud