diff options
author | Chris Lattner <sabre@nondot.org> | 2012-01-26 21:37:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2012-01-26 21:37:55 +0000 |
commit | 61a1d6cb81a14eb977d7278fbde7d563be280533 (patch) | |
tree | 21270e8a64127804370a106e240215be50abcdfa /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 49b1e38e4bee0f0c6f8b49e1a62d5284084e09e7 (diff) | |
download | llvm-61a1d6cb81a14eb977d7278fbde7d563be280533.zip llvm-61a1d6cb81a14eb977d7278fbde7d563be280533.tar.gz llvm-61a1d6cb81a14eb977d7278fbde7d563be280533.tar.bz2 |
progress making the world safe to ConstantDataVector. While
we're at it, allow PatternMatch's "neg" pattern to match integer
vector negations, and enhance ComputeNumSigned bits to handle
shl of vectors.
llvm-svn: 149082
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 21008a1..6403f03 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -89,6 +89,7 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask, } // Handle a constant vector by taking the intersection of the known bits of // each element. + // FIXME: Remove. if (ConstantVector *CV = dyn_cast<ConstantVector>(V)) { KnownZero.setAllBits(); KnownOne.setAllBits(); for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) { @@ -1005,30 +1006,28 @@ unsigned llvm::ComputeNumSignBits(Value *V, const TargetData *TD, Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits(); return ComputeNumSignBits(U->getOperand(0), TD, Depth+1) + Tmp; - case Instruction::AShr: + case Instruction::AShr: { Tmp = ComputeNumSignBits(U->getOperand(0), TD, Depth+1); - // ashr X, C -> adds C sign bits. - if (ConstantInt *C = dyn_cast<ConstantInt>(U->getOperand(1))) { - Tmp += C->getZExtValue(); + // ashr X, C -> adds C sign bits. Vectors too. + const APInt *ShAmt; + if (match(U->getOperand(1), m_APInt(ShAmt))) { + Tmp += ShAmt->getZExtValue(); if (Tmp > TyBits) Tmp = TyBits; } - // vector ashr X, <C, C, C, C> -> adds C sign bits - if (ConstantVector *C = dyn_cast<ConstantVector>(U->getOperand(1))) { - if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue())) { - Tmp += CI->getZExtValue(); - if (Tmp > TyBits) Tmp = TyBits; - } - } return Tmp; - case Instruction::Shl: - if (ConstantInt *C = dyn_cast<ConstantInt>(U->getOperand(1))) { + } + case Instruction::Shl: { + const APInt *ShAmt; + if (match(U->getOperand(1), m_APInt(ShAmt))) { // shl destroys sign bits. Tmp = ComputeNumSignBits(U->getOperand(0), TD, Depth+1); - if (C->getZExtValue() >= TyBits || // Bad shift. - C->getZExtValue() >= Tmp) break; // Shifted all sign bits out. - return Tmp - C->getZExtValue(); + Tmp2 = ShAmt->getZExtValue(); + if (Tmp2 >= TyBits || // Bad shift. + Tmp2 >= Tmp) break; // Shifted all sign bits out. + return Tmp - Tmp2; } break; + } case Instruction::And: case Instruction::Or: case Instruction::Xor: // NOT is handled here. |