diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-01-08 21:12:51 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-01-08 21:12:51 +0000 |
commit | d4242d8ab11b0da74867299cec7c2f6354c037dd (patch) | |
tree | 19ea87c88e227555c78e1522905c011730d6ed68 /lib/Transforms | |
parent | 79aa048d2102a7d4c8abbba82b4b8a41dbc32214 (diff) | |
download | external_llvm-d4242d8ab11b0da74867299cec7c2f6354c037dd.zip external_llvm-d4242d8ab11b0da74867299cec7c2f6354c037dd.tar.gz external_llvm-d4242d8ab11b0da74867299cec7c2f6354c037dd.tar.bz2 |
Tweak my last commit to be less conservative about uses.
We still save an instruction when just the "and" part is replaced.
Also change the code to match comments more closely.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147753 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 96ca40a..b4d3e62 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -745,18 +745,17 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) { } // (X & C) == 0 & X > -1 -> (X & (C | SignBit)) == 0 - if (LHS->hasOneUse() && RHS->hasOneUse() && - ((LHSCC == ICmpInst::ICMP_EQ && LHSCst->isZero() && - RHSCC == ICmpInst::ICMP_SGT && RHSCst->isAllOnesValue()) || - (RHSCC == ICmpInst::ICMP_EQ && RHSCst->isZero() && - LHSCC == ICmpInst::ICMP_SGT && LHSCst->isAllOnesValue()))) { - BinaryOperator *BO = - dyn_cast<BinaryOperator>(LHSCC == ICmpInst::ICMP_EQ ? Val : Val2); - ConstantInt *AndCst; - if (BO && match(BO, m_OneUse(m_And(m_Value(), m_ConstantInt(AndCst))))) { - APInt New = AndCst->getValue() | APInt::getSignBit(AndCst->getBitWidth()); - BO->setOperand(1, ConstantInt::get(AndCst->getContext(), New)); - return BO == Val ? LHS : RHS; + if ((LHSCC == ICmpInst::ICMP_EQ && LHSCst->isZero() && + RHSCC == ICmpInst::ICMP_SGT && RHSCst->isAllOnesValue()) || + (RHSCC == ICmpInst::ICMP_EQ && RHSCst->isZero() && + LHSCC == ICmpInst::ICMP_SGT && LHSCst->isAllOnesValue())) { + ICmpInst *I = LHSCC == ICmpInst::ICMP_EQ ? LHS : RHS; + Value *X; ConstantInt *C; + if (I->hasOneUse() && + match(I->getOperand(0), m_OneUse(m_And(m_Value(X), m_ConstantInt(C))))){ + APInt New = C->getValue() | APInt::getSignBit(C->getBitWidth()); + return Builder->CreateICmpEQ(Builder->CreateAnd(X, Builder->getInt(New)), + I->getOperand(1)); } } @@ -1458,19 +1457,18 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS) { } } - // (X & C) != 0 & X < 0 -> (X & (C | SignBit)) != 0 - if (LHS->hasOneUse() && RHS->hasOneUse() && - ((LHSCC == ICmpInst::ICMP_NE && LHSCst->isZero() && - RHSCC == ICmpInst::ICMP_SLT && RHSCst->isZero()) || - (RHSCC == ICmpInst::ICMP_NE && RHSCst->isZero() && - LHSCC == ICmpInst::ICMP_SLT && LHSCst->isZero()))) { - BinaryOperator *BO = - dyn_cast<BinaryOperator>(LHSCC == ICmpInst::ICMP_NE ? Val : Val2); - ConstantInt *AndCst; - if (BO && match(BO, m_OneUse(m_And(m_Value(), m_ConstantInt(AndCst))))) { - APInt New = AndCst->getValue() | APInt::getSignBit(AndCst->getBitWidth()); - BO->setOperand(1, ConstantInt::get(AndCst->getContext(), New)); - return BO == Val ? LHS : RHS; + // (X & C) != 0 | X < 0 -> (X & (C | SignBit)) != 0 + if ((LHSCC == ICmpInst::ICMP_NE && LHSCst->isZero() && + RHSCC == ICmpInst::ICMP_SLT && RHSCst->isZero()) || + (RHSCC == ICmpInst::ICMP_NE && RHSCst->isZero() && + LHSCC == ICmpInst::ICMP_SLT && LHSCst->isZero())) { + ICmpInst *I = LHSCC == ICmpInst::ICMP_NE ? LHS : RHS; + Value *X; ConstantInt *C; + if (I->hasOneUse() && + match(I->getOperand(0), m_OneUse(m_And(m_Value(X), m_ConstantInt(C))))){ + APInt New = C->getValue() | APInt::getSignBit(C->getBitWidth()); + return Builder->CreateICmpNE(Builder->CreateAnd(X, Builder->getInt(New)), + I->getOperand(1)); } } |