diff options
author | Nadav Rotem <nrotem@apple.com> | 2013-01-30 06:35:22 +0000 |
---|---|---|
committer | Nadav Rotem <nrotem@apple.com> | 2013-01-30 06:35:22 +0000 |
commit | cc687faba373e6aa3cefe594bd9f3212e18617eb (patch) | |
tree | a53df8faf4e5c5121303786d1805606a54407be2 /lib/Transforms | |
parent | 581126e4a1daf5e7e6203bf81769f96bea25e601 (diff) | |
download | external_llvm-cc687faba373e6aa3cefe594bd9f3212e18617eb.zip external_llvm-cc687faba373e6aa3cefe594bd9f3212e18617eb.tar.gz external_llvm-cc687faba373e6aa3cefe594bd9f3212e18617eb.tar.bz2 |
InstCombine: canonicalize sext-and --> select
sext-not-and --> select.
Patch by Muhammad Tauqir Ahmad.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173901 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index c1e60d4..bf065fe 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1245,6 +1245,34 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { } } + { + Value *X = 0; + 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); + } + return Changed ? &I : 0; } |