summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2010-09-17 15:48:55 +0000
committerdim <dim@FreeBSD.org>2010-09-17 15:48:55 +0000
commit5d5cc59cc77afe655b3707cb0e69e0827b444cad (patch)
tree36453626c792cccd91f783a38a169d610a6b9db9 /lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
parent786a18553586229ad99ecb5ecde8a9d914c45e27 (diff)
downloadFreeBSD-src-5d5cc59cc77afe655b3707cb0e69e0827b444cad.zip
FreeBSD-src-5d5cc59cc77afe655b3707cb0e69e0827b444cad.tar.gz
Vendor import of llvm r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/llvm/branches/release_28@114020 Approved by: rpaulo (mentor)
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineAndOrXor.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineAndOrXor.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 5876f40..19a05bf 100644
--- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -474,19 +474,16 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
}
// (icmp ne (A & C1), 0) & (icmp ne (A & C2), 0) -->
- // (icmp eq (A & (C1|C2)), (C1|C2))
+ // (icmp eq (A & (C1|C2)), (C1|C2)) where C1 and C2 are non-zero POT
if (LHSCC == ICmpInst::ICMP_NE && LHSCst->isZero()) {
- Instruction *I1 = dyn_cast<Instruction>(Val);
- Instruction *I2 = dyn_cast<Instruction>(Val2);
- if (I1 && I1->getOpcode() == Instruction::And &&
- I2 && I2->getOpcode() == Instruction::And &&
- I1->getOperand(0) == I1->getOperand(0)) {
- ConstantInt *CI1 = dyn_cast<ConstantInt>(I1->getOperand(1));
- ConstantInt *CI2 = dyn_cast<ConstantInt>(I2->getOperand(1));
- if (CI1 && !CI1->isZero() && CI2 && !CI2->isZero() &&
- CI1->getValue().operator&(CI2->getValue()) == 0) {
+ Value *Op1 = 0, *Op2 = 0;
+ ConstantInt *CI1 = 0, *CI2 = 0;
+ if (match(LHS->getOperand(0), m_And(m_Value(Op1), m_ConstantInt(CI1))) &&
+ match(RHS->getOperand(0), m_And(m_Value(Op2), m_ConstantInt(CI2)))) {
+ if (Op1 == Op2 && !CI1->isZero() && !CI2->isZero() &&
+ CI1->getValue().isPowerOf2() && CI2->getValue().isPowerOf2()) {
Constant *ConstOr = ConstantExpr::getOr(CI1, CI2);
- Value *NewAnd = Builder->CreateAnd(I1->getOperand(0), ConstOr);
+ Value *NewAnd = Builder->CreateAnd(Op1, ConstOr);
return Builder->CreateICmp(ICmpInst::ICMP_EQ, NewAnd, ConstOr);
}
}
@@ -1170,11 +1167,28 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
ConstantInt *RHSCst = dyn_cast<ConstantInt>(RHS->getOperand(1));
if (LHSCst == 0 || RHSCst == 0) 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 Builder->CreateICmp(LHSCC, NewOr, LHSCst);
+ if (LHSCst == RHSCst && LHSCC == RHSCC) {
+ // (icmp ne A, 0) | (icmp ne B, 0) --> (icmp ne (A|B), 0)
+ if (LHSCC == ICmpInst::ICMP_NE && LHSCst->isZero()) {
+ Value *NewOr = Builder->CreateOr(Val, Val2);
+ return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
+ }
+
+ // (icmp eq (A & C1), 0) | (icmp eq (A & C2), 0) -->
+ // (icmp ne (A & (C1|C2)), (C1|C2)) where C1 and C2 are non-zero POT
+ if (LHSCC == ICmpInst::ICMP_EQ && LHSCst->isZero()) {
+ Value *Op1 = 0, *Op2 = 0;
+ ConstantInt *CI1 = 0, *CI2 = 0;
+ if (match(LHS->getOperand(0), m_And(m_Value(Op1), m_ConstantInt(CI1))) &&
+ match(RHS->getOperand(0), m_And(m_Value(Op2), m_ConstantInt(CI2)))) {
+ if (Op1 == Op2 && !CI1->isZero() && !CI2->isZero() &&
+ CI1->getValue().isPowerOf2() && CI2->getValue().isPowerOf2()) {
+ Constant *ConstOr = ConstantExpr::getOr(CI1, CI2);
+ Value *NewAnd = Builder->CreateAnd(Op1, ConstOr);
+ return Builder->CreateICmp(ICmpInst::ICMP_NE, NewAnd, ConstOr);
+ }
+ }
+ }
}
// From here on, we only handle:
OpenPOWER on IntegriCloud