[llvm] r271051 - [InstCombine] move and/sext fold to helper function; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri May 27 14:41:29 PDT 2016
Author: spatel
Date: Fri May 27 16:41:29 2016
New Revision: 271051
URL: http://llvm.org/viewvc/llvm-project?rev=271051&view=rev
Log:
[InstCombine] move and/sext fold to helper function; NFCI
We need to enhance the pattern matching on these to look through bitcasts.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=271051&r1=271050&r2=271051&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Fri May 27 16:41:29 2016
@@ -1328,6 +1328,32 @@ Instruction *InstCombiner::foldCastedBit
return nullptr;
}
+static Instruction *foldBoolSextMaskToSelect(BinaryOperator &I) {
+ Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
+
+ // Canonicalize SExt or Not to the LHS
+ if (match(Op1, m_SExt(m_Value())) || match(Op1, m_Not(m_Value()))) {
+ std::swap(Op0, Op1);
+ }
+
+ // Fold (and (sext bool to A), B) --> (select bool, B, 0)
+ Value *X = nullptr;
+ if (match(Op0, m_SExt(m_Value(X))) &&
+ X->getType()->getScalarType()->isIntegerTy(1)) {
+ Value *Zero = Constant::getNullValue(Op1->getType());
+ return SelectInst::Create(X, Op1, Zero);
+ }
+
+ // Fold (and ~(sext bool to A), B) --> (select bool, 0, B)
+ if (match(Op0, m_Not(m_SExt(m_Value(X)))) &&
+ X->getType()->getScalarType()->isIntegerTy(1)) {
+ Value *Zero = Constant::getNullValue(Op0->getType());
+ return SelectInst::Create(X, Zero, Op1);
+ }
+
+ return nullptr;
+}
+
Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
bool Changed = SimplifyAssociativeOrCommutative(I);
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
@@ -1586,33 +1612,8 @@ Instruction *InstCombiner::visitAnd(Bina
}
}
- {
- Value *X = nullptr;
- bool OpsSwapped = false;
- // Canonicalize SExt or Not to the LHS
- if (match(Op1, m_SExt(m_Value())) ||
- match(Op1, m_Not(m_Value()))) {
- std::swap(Op0, Op1);
- OpsSwapped = true;
- }
-
- // Fold (and (sext bool to A), B) --> (select bool, B, 0)
- if (match(Op0, m_SExt(m_Value(X))) &&
- X->getType()->getScalarType()->isIntegerTy(1)) {
- Value *Zero = Constant::getNullValue(Op1->getType());
- return SelectInst::Create(X, Op1, Zero);
- }
-
- // Fold (and ~(sext bool to A), B) --> (select bool, 0, B)
- if (match(Op0, m_Not(m_SExt(m_Value(X)))) &&
- X->getType()->getScalarType()->isIntegerTy(1)) {
- Value *Zero = Constant::getNullValue(Op0->getType());
- return SelectInst::Create(X, Zero, Op1);
- }
-
- if (OpsSwapped)
- std::swap(Op0, Op1);
- }
+ if (Instruction *Select = foldBoolSextMaskToSelect(I))
+ return Select;
return Changed ? &I : nullptr;
}
More information about the llvm-commits
mailing list