diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-07-09 07:58:32 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-07-09 07:58:32 +0000 |
commit | 11c29bafd584da2e39ee5d885ca2d53035bc1372 (patch) | |
tree | e6c74cff6f23d7a23b5c783c2597dc0b80b91c93 /lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 377a5c1a87b879b7a05a635ed7bbf125b0b61e28 (diff) | |
download | llvm-11c29bafd584da2e39ee5d885ca2d53035bc1372.tar.gz llvm-11c29bafd584da2e39ee5d885ca2d53035bc1372.tar.bz2 llvm-11c29bafd584da2e39ee5d885ca2d53035bc1372.tar.xz |
Commit r185909 was a misapplied patch, fix it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185910 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCompares.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index d843842cb3..fd2b68a9ec 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1564,13 +1564,23 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, } } - // X-C1 <u 2 -> (X & -2) == C1 - // iff C1 & 1 == 0 + // X-C1 <u C2 -> (X & -C2) == C1 + // iff C1 & (C2-1) == 0 + // C2 is a power of 2 if (ICI.getPredicate() == ICmpInst::ICMP_ULT && LHSI->hasOneUse() && - LHSV[0] == 0 && RHSV == 2) + RHSV.isPowerOf2() && (LHSV & (RHSV - 1)) == 0) return new ICmpInst(ICmpInst::ICMP_EQ, Builder->CreateAnd(LHSI->getOperand(0), -RHSV), ConstantExpr::getNeg(LHSC)); + + // X-C1 >u C2 -> (X & ~C2) == C1 + // iff C1 & C2 == 0 + // C2+1 is a power of 2 + if (ICI.getPredicate() == ICmpInst::ICMP_UGT && LHSI->hasOneUse() && + (RHSV + 1).isPowerOf2() && (LHSV & RHSV) == 0) + return new ICmpInst(ICmpInst::ICMP_NE, + Builder->CreateAnd(LHSI->getOperand(0), ~RHSV), + ConstantExpr::getNeg(LHSC)); } break; } @@ -1732,24 +1742,6 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, default: break; } - - // X-C1 <u C2 -> (X & -C2) == C1 - // iff C1 & (C2-1) == 0 - // C2 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_ULT && LHSI->hasOneUse() && - RHSV.isPowerOf2() && (LHSV & (RHSV - 1)) == 0) - return new ICmpInst(ICmpInst::ICMP_EQ, - Builder->CreateAnd(LHSI->getOperand(0), -RHSV), - ConstantExpr::getNeg(LHSC)); - - // X-C1 >u C2 -> (X & ~C2) == C1 - // iff C1 & C2 == 0 - // C2+1 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_UGT && LHSI->hasOneUse() && - (RHSV + 1).isPowerOf2() && (LHSV & RHSV) == 0) - return new ICmpInst(ICmpInst::ICMP_NE, - Builder->CreateAnd(LHSI->getOperand(0), ~RHSV), - ConstantExpr::getNeg(LHSC)); } } return 0; |