summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2017-08-04 16:07:20 +0000
committerCraig Topper <craig.topper@intel.com>2017-08-04 16:07:20 +0000
commit760ff6ee872aaefdbbe780667b6597b6a742067f (patch)
tree89b6250602daeb056abc20690bda1168e2d87c71 /llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
parent3b74a68cc707b776633fc501a822dae3c3ac9400 (diff)
downloadbcm5719-llvm-760ff6ee872aaefdbbe780667b6597b6a742067f.tar.gz
bcm5719-llvm-760ff6ee872aaefdbbe780667b6597b6a742067f.zip
[InstCombine] Remove the (not (sext)) case from foldBoolSextMaskToSelect and inline the remaining code to match visitOr
Summary: The (not (sext)) case is really (xor (sext), -1) which should have been simplified to (sext (xor, 1)) before we got here. So we shouldn't need to handle it. With that taken care of we only need to two cases so don't need the swap anymore. This makes us in sync with the equivalent code in visitOr so inline this to match. Reviewers: spatel, eli.friedman, majnemer Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D36240 llvm-svn: 310063
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp35
1 files changed, 8 insertions, 27 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 62a73cca4b7..a3749a1581b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1188,31 +1188,6 @@ Instruction *InstCombiner::foldCastedBitwiseLogic(BinaryOperator &I) {
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()->isIntOrIntVectorTy(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()->isIntOrIntVectorTy(1)) {
- Value *Zero = Constant::getNullValue(Op0->getType());
- return SelectInst::Create(X, Zero, Op1);
- }
-
- return nullptr;
-}
-
static Instruction *foldAndToXor(BinaryOperator &I,
InstCombiner::BuilderTy &Builder) {
assert(I.getOpcode() == Instruction::And);
@@ -1480,8 +1455,14 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
if (Instruction *CastedAnd = foldCastedBitwiseLogic(I))
return CastedAnd;
- if (Instruction *Select = foldBoolSextMaskToSelect(I))
- return Select;
+ // and(sext(A), B) / and(B, sext(A)) --> A ? B : 0, where A is i1 or <N x i1>.
+ Value *A;
+ if (match(Op0, m_OneUse(m_SExt(m_Value(A)))) &&
+ A->getType()->isIntOrIntVectorTy(1))
+ return SelectInst::Create(A, Op1, Constant::getNullValue(I.getType()));
+ if (match(Op1, m_OneUse(m_SExt(m_Value(A)))) &&
+ A->getType()->isIntOrIntVectorTy(1))
+ return SelectInst::Create(A, Op0, Constant::getNullValue(I.getType()));
return Changed ? &I : nullptr;
}
OpenPOWER on IntegriCloud