diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-11-14 19:12:20 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-11-14 19:12:20 +0000 |
| commit | 42d098e1b4d2aabe72fcba1406f89fd6a401d392 (patch) | |
| tree | 0b9e8bca5c83086c78891cff48c33b7a5fbcd950 /llvm/lib | |
| parent | f93b3f46f89f94c283f07fa005d5c81134108b1e (diff) | |
| download | bcm5719-llvm-42d098e1b4d2aabe72fcba1406f89fd6a401d392.tar.gz bcm5719-llvm-42d098e1b4d2aabe72fcba1406f89fd6a401d392.zip | |
Fold ConstantVector::isAllOnesValue into Constant::isAllOnesValue and simplify it.
llvm-svn: 144555
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index a84a046bb99..cd94da13534 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -71,12 +71,14 @@ bool Constant::isAllOnesValue() const { if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this)) return CFP->getValueAPF().bitcastToAPInt().isAllOnesValue(); - // Check for constant vectors + // Check for constant vectors which are splats of -1 values. if (const ConstantVector *CV = dyn_cast<ConstantVector>(this)) - return CV->isAllOnesValue(); + if (Constant *Splat = CV->getSplatValue()) + return Splat->isAllOnesValue(); return false; } + // Constructor to create a '0' constant of arbitrary type... Constant *Constant::getNullValue(Type *Ty) { switch (Ty->getTypeID()) { @@ -1071,26 +1073,6 @@ void ConstantVector::destroyConstant() { destroyConstantImpl(); } -/// This function will return true iff every element in this vector constant -/// is set to all ones. -/// @returns true iff this constant's elements are all set to all ones. -/// @brief Determine if the value is all ones. -bool ConstantVector::isAllOnesValue() const { - // Check out first element. - const Constant *Elt = getOperand(0); - const ConstantInt *CI = dyn_cast<ConstantInt>(Elt); - const ConstantFP *CF = dyn_cast<ConstantFP>(Elt); - - // Then make sure all remaining elements point to the same value. - for (unsigned I = 1, E = getNumOperands(); I < E; ++I) - if (getOperand(I) != Elt) - return false; - - // First value is all-ones. - return (CI && CI->isAllOnesValue()) || - (CF && CF->isAllOnesValue()); -} - /// getSplatValue - If this is a splat constant, where all of the /// elements have the same value, return that value. Otherwise return null. Constant *ConstantVector::getSplatValue() const { |

