diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-11-29 00:51:17 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-11-29 00:51:17 +0000 |
| commit | cd261c9c261d9dac036d7d6d14f0fe885446067a (patch) | |
| tree | b0bf340899213c8b9237c509d3aac0b277550755 /llvm/lib/Transforms | |
| parent | 218a3393f4322c8a1923792673c42a5b266d06fd (diff) | |
| download | bcm5719-llvm-cd261c9c261d9dac036d7d6d14f0fe885446067a.tar.gz bcm5719-llvm-cd261c9c261d9dac036d7d6d14f0fe885446067a.zip | |
Implement PR5634.
llvm-svn: 90046
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index c591ef841c0..ce471b398c5 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4067,6 +4067,21 @@ Value *InstCombiner::FoldLogicalPlusAnd(Value *LHS, Value *RHS, /// FoldAndOfICmps - Fold (icmp)&(icmp) if possible. Instruction *InstCombiner::FoldAndOfICmps(Instruction &I, ICmpInst *LHS, ICmpInst *RHS) { + // (icmp eq A, null) & (icmp eq B, null) --> + // (icmp eq (ptrtoint(A)|ptrtoint(B)), 0) + if (TD && + LHS->getPredicate() == ICmpInst::ICMP_EQ && + RHS->getPredicate() == ICmpInst::ICMP_EQ && + isa<ConstantPointerNull>(LHS->getOperand(1)) && + isa<ConstantPointerNull>(RHS->getOperand(1))) { + const Type *IntPtrTy = TD->getIntPtrType(I.getContext()); + Value *A = Builder->CreatePtrToInt(LHS->getOperand(0), IntPtrTy); + Value *B = Builder->CreatePtrToInt(RHS->getOperand(0), IntPtrTy); + Value *NewOr = Builder->CreateOr(A, B); + return new ICmpInst(ICmpInst::ICMP_EQ, NewOr, + Constant::getNullValue(IntPtrTy)); + } + Value *Val, *Val2; ConstantInt *LHSCst, *RHSCst; ICmpInst::Predicate LHSCC, RHSCC; @@ -4078,12 +4093,20 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I, m_ConstantInt(RHSCst)))) return 0; - // (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C) - // where C is a power of 2 - if (LHSCst == RHSCst && LHSCC == RHSCC && LHSCC == ICmpInst::ICMP_ULT && - LHSCst->getValue().isPowerOf2()) { - Value *NewOr = Builder->CreateOr(Val, Val2); - return new ICmpInst(LHSCC, NewOr, LHSCst); + if (LHSCst == RHSCst && LHSCC == RHSCC) { + // (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C) + // where C is a power of 2 + if (LHSCC == ICmpInst::ICMP_ULT && + LHSCst->getValue().isPowerOf2()) { + Value *NewOr = Builder->CreateOr(Val, Val2); + return new ICmpInst(LHSCC, NewOr, LHSCst); + } + + // (icmp eq A, 0) & (icmp eq B, 0) --> (icmp eq (A|B), 0) + if (LHSCC == ICmpInst::ICMP_EQ && LHSCst->isZero()) { + Value *NewOr = Builder->CreateOr(Val, Val2); + return new ICmpInst(LHSCC, NewOr, LHSCst); + } } // From here on, we only handle: @@ -4739,16 +4762,37 @@ static Instruction *MatchSelectFromAndOr(Value *A, Value *B, /// FoldOrOfICmps - Fold (icmp)|(icmp) if possible. Instruction *InstCombiner::FoldOrOfICmps(Instruction &I, ICmpInst *LHS, ICmpInst *RHS) { + // (icmp ne A, null) | (icmp ne B, null) --> + // (icmp ne (ptrtoint(A)|ptrtoint(B)), 0) + if (TD && + LHS->getPredicate() == ICmpInst::ICMP_NE && + RHS->getPredicate() == ICmpInst::ICMP_NE && + isa<ConstantPointerNull>(LHS->getOperand(1)) && + isa<ConstantPointerNull>(RHS->getOperand(1))) { + const Type *IntPtrTy = TD->getIntPtrType(I.getContext()); + Value *A = Builder->CreatePtrToInt(LHS->getOperand(0), IntPtrTy); + Value *B = Builder->CreatePtrToInt(RHS->getOperand(0), IntPtrTy); + Value *NewOr = Builder->CreateOr(A, B); + return new ICmpInst(ICmpInst::ICMP_NE, NewOr, + Constant::getNullValue(IntPtrTy)); + } + Value *Val, *Val2; ConstantInt *LHSCst, *RHSCst; ICmpInst::Predicate LHSCC, RHSCC; // This only handles icmp of constants: (icmp1 A, C1) | (icmp2 B, C2). - if (!match(LHS, m_ICmp(LHSCC, m_Value(Val), - m_ConstantInt(LHSCst))) || - !match(RHS, m_ICmp(RHSCC, m_Value(Val2), - m_ConstantInt(RHSCst)))) + if (!match(LHS, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))) || + !match(RHS, m_ICmp(RHSCC, m_Value(Val2), m_ConstantInt(RHSCst)))) return 0; + + + // (icmp ne A, 0) | (icmp ne B, 0) --> (icmp ne (A|B), 0) + if (LHSCst == RHSCst && LHSCC == RHSCC && + LHSCC == ICmpInst::ICMP_NE && LHSCst->isZero()) { + Value *NewOr = Builder->CreateOr(Val, Val2); + return new ICmpInst(LHSCC, NewOr, LHSCst); + } // From here on, we only handle: // (icmp1 A, C1) | (icmp2 A, C2) --> something simpler. |

