summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp')
-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