aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2011-08-23 20:11:10 +0000
committerEric Christopher <echristo@apple.com>2011-08-23 20:11:10 +0000
commitacc8f2d938dbf00c79c34f4541a5a05662964797 (patch)
treeb2c75a5d7c7876041f936f31effdc3943d005050 /lib
parent99e84e07ff94f24fdbd05f21d4cf5afb822542fe (diff)
downloadexternal_llvm-acc8f2d938dbf00c79c34f4541a5a05662964797.zip
external_llvm-acc8f2d938dbf00c79c34f4541a5a05662964797.tar.gz
external_llvm-acc8f2d938dbf00c79c34f4541a5a05662964797.tar.bz2
Revert "Address Duncan's CR request:"
This reverts commit 20a05be15ea5271ab6185b83200fa88263362400. (svn rev 138340) Conflicts: test/Transforms/InstCombine/bitcast.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/ConstantFolding.cpp13
-rw-r--r--lib/VMCore/Constants.cpp24
2 files changed, 12 insertions, 25 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 0eacaf8..7a8c703 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -45,9 +45,15 @@ using namespace llvm;
/// ConstantExpr if unfoldable.
static Constant *FoldBitCast(Constant *C, Type *DestTy,
const TargetData &TD) {
- // Catch the obvious splat cases.
- if (C->isNullValue()) return Constant::getNullValue(DestTy);
- if (C->isAllOnesValue()) return Constant::getAllOnesValue(DestTy);
+
+ ConstantVector *CV = dyn_cast<ConstantVector>(C);
+ IntegerType *IntVTy = dyn_cast<IntegerType>(DestTy);
+ // When casting vectors to scalar integers, catch the
+ // obvious splat cases.
+ if (IntVTy && CV) {
+ if (CV->isNullValue()) return ConstantInt::getNullValue(IntVTy);
+ if (CV->isAllOnesValue()) return ConstantInt::getAllOnesValue(IntVTy);
+ }
// The code below only handles casts to vectors currently.
VectorType *DestVTy = dyn_cast<VectorType>(DestTy);
@@ -62,7 +68,6 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
}
// If this is a bitcast from constant vector -> vector, fold it.
- ConstantVector *CV = dyn_cast<ConstantVector>(C);
if (CV == 0)
return ConstantExpr::getBitCast(C, DestTy);
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 8b41ab7..2f22cda 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -62,21 +62,6 @@ 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->isAllOnesValue();
-
- // +0.0 is null.
- 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()) {
@@ -141,7 +126,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] && "Invalid AllOnes value!");
+ assert(Elts[0] && "Not a vector integer type!");
return cast<ConstantVector>(ConstantVector::get(Elts));
}
@@ -1079,16 +1064,13 @@ 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);
-
+ if (!CI || !CI->isAllOnesValue()) return false;
// 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());
+ return true;
}
/// getSplatValue - If this is a splat constant, where all of the