diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-06-29 23:44:53 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-06-29 23:44:53 +0000 |
commit | 7a69d2c06adefd557ce2eb58ad0ccbb69de78c22 (patch) | |
tree | 66c45fed0162904d99bfb615a1288785b991034e /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 3cc579a95bd5907d813855d9782a5c4e32348cd1 (diff) | |
download | bcm5719-llvm-7a69d2c06adefd557ce2eb58ad0ccbb69de78c22.tar.gz bcm5719-llvm-7a69d2c06adefd557ce2eb58ad0ccbb69de78c22.zip |
ValueTracking: Teach isKnownToBeAPowerOfTwo about (ADD X, (XOR X, Y)) where X is a power of two
This allows us to simplify urem instructions involving the add+xor to
turn into simpler math.
llvm-svn: 185272
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index d2e13b78152..39bc1a355c3 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -855,16 +855,24 @@ bool llvm::isKnownToBeAPowerOfTwo(Value *V, bool OrZero, unsigned Depth) { return false; } - // Adding a power of two to the same power of two is a power of two or zero. - if (OrZero && match(V, m_Add(m_Value(X), m_Value(Y)))) { - if (match(X, m_And(m_Value(), m_Specific(Y)))) { - if (isKnownToBeAPowerOfTwo(Y, /*OrZero*/true, Depth)) - return true; - } else if (match(Y, m_And(m_Value(), m_Specific(X)))) { - if (isKnownToBeAPowerOfTwo(X, /*OrZero*/true, Depth)) - return true; - } - } + if (match(V, m_Add(m_Value(X), m_Value(Y)))) + if (OverflowingBinaryOperator *VOBO = cast<OverflowingBinaryOperator>(V)) + if (OrZero || VOBO->hasNoUnsignedWrap() || VOBO->hasNoSignedWrap()) { + // Adding a power of two to the same power of two is a power of two or + // zero. + if (BinaryOperator *XBO = dyn_cast<BinaryOperator>(X)) + if (XBO->getOpcode() == Instruction::And || + XBO->getOpcode() == Instruction::Xor) + if (XBO->getOperand(0) == Y || XBO->getOperand(1) == Y) + if (isKnownToBeAPowerOfTwo(Y, /*OrZero*/true, Depth)) + return true; + if (BinaryOperator *YBO = dyn_cast<BinaryOperator>(Y)) + if (YBO->getOpcode() == Instruction::And || + YBO->getOpcode() == Instruction::Xor) + if (YBO->getOperand(0) == X || YBO->getOperand(1) == X) + if (isKnownToBeAPowerOfTwo(X, /*OrYero*/true, Depth)) + return true; + } // An exact divide or right shift can only shift off zero bits, so the result // is a power of two only if the first operand is a power of two and not |