diff options
author | David Majnemer <david.majnemer@gmail.com> | 2012-12-12 20:48:54 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2012-12-12 20:48:54 +0000 |
commit | 63522b1998289e694385a45a719313c95f3350cf (patch) | |
tree | 828fbbd68520689aea20b838689e8e944d88961a /lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 8ceb8b764f266ff00a590c88a7ecc654b13a8f0b (diff) | |
download | external_llvm-63522b1998289e694385a45a719313c95f3350cf.zip external_llvm-63522b1998289e694385a45a719313c95f3350cf.tar.gz external_llvm-63522b1998289e694385a45a719313c95f3350cf.tar.bz2 |
Simplify negated bit test
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170020 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCompares.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 1b96c3c..b0fc82f 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2034,6 +2034,15 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { CI->countTrailingZeros())); } + // Turn x&~y == 0 into x&y != 0 if x is a power of 2. + Value *X = 0, *Y = 0; + if (match(Op0, m_And(m_Value(X), m_Not(m_Value(Y)))) && + match(Op1, m_Zero()) && isPowerOfTwo(X, TD)) { + return new ICmpInst(ICmpInst::ICMP_NE, + Builder->CreateAnd(X, Y), + Op1); + } + break; } case ICmpInst::ICMP_NE: { @@ -2071,6 +2080,15 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { CI->countTrailingZeros())); } + // Turn x&~y != 0 into x&y == 0 if x is a power of 2. + Value *X = 0, *Y = 0; + if (match(Op0, m_And(m_Value(X), m_Not(m_Value(Y)))) && + match(Op1, m_Zero()) && isPowerOfTwo(X, TD)) { + return new ICmpInst(ICmpInst::ICMP_EQ, + Builder->CreateAnd(X, Y), + Op1); + } + break; } case ICmpInst::ICMP_ULT: |