summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorNadav Rotem <nadav.rotem@intel.com>2011-08-24 20:18:38 +0000
committerNadav Rotem <nadav.rotem@intel.com>2011-08-24 20:18:38 +0000
commit4c7c0f23533565c7e2ddf71e01bf50f2aede5f1b (patch)
tree7712e1fd7075695dceadf424ad4a982f5e194b1e /lib/VMCore
parentdf9ce6bbc5b66c3c4d30c2f32b6f17c690cfa004 (diff)
downloadllvm-4c7c0f23533565c7e2ddf71e01bf50f2aede5f1b.tar.gz
llvm-4c7c0f23533565c7e2ddf71e01bf50f2aede5f1b.tar.bz2
llvm-4c7c0f23533565c7e2ddf71e01bf50f2aede5f1b.tar.xz
Implement Constant::isAllOnesValue(). Fix ConstantFolding to use the new api.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 2f22cda5ba..ba309d9ca0 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -62,6 +62,21 @@ bool Constant::isNullValue() const {
return isa<ConstantAggregateZero>(this) || isa<ConstantPointerNull>(this);
}
+bool Constant::isAllOnesValue() const {
+ // Check for -1 integers
+ if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
+ return CI->isMinusOne();
+
+ // Check for FP which are bitcasted from -1 integers
+ if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
+ return CFP->getValueAPF().bitcastToAPInt().isAllOnesValue();
+
+ // Check for constant vectors
+ if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
+ return CV->isAllOnesValue();
+
+ return false;
+}
// Constructor to create a '0' constant of arbitrary type...
Constant *Constant::getNullValue(Type *Ty) {
switch (Ty->getTypeID()) {
@@ -126,7 +141,7 @@ Constant *Constant::getAllOnesValue(Type *Ty) {
SmallVector<Constant*, 16> Elts;
VectorType *VTy = cast<VectorType>(Ty);
Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
- assert(Elts[0] && "Not a vector integer type!");
+ assert(Elts[0] && "Invalid AllOnes value!");
return cast<ConstantVector>(ConstantVector::get(Elts));
}
@@ -1064,13 +1079,16 @@ bool ConstantVector::isAllOnesValue() const {
// Check out first element.
const Constant *Elt = getOperand(0);
const ConstantInt *CI = dyn_cast<ConstantInt>(Elt);
- if (!CI || !CI->isAllOnesValue()) return false;
+ 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;
- return true;
+ // First value is all-ones.
+ return (CI && CI->isAllOnesValue()) ||
+ (CF && CF->isAllOnesValue());
}
/// getSplatValue - If this is a splat constant, where all of the