aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-02-06 21:56:39 +0000
committerChris Lattner <sabre@nondot.org>2012-02-06 21:56:39 +0000
commit7302d80490feabfc8a01bee0fa698aab55169544 (patch)
treea2e302de0cd9bbed2d37ef67132f6f43ba8587e0 /lib/Analysis/ConstantFolding.cpp
parent705f4813afb13ed850386cbb4b56688abb6412ab (diff)
Remove some dead code and tidy things up now that vectors use ConstantDataVector
instead of always using ConstantVector. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149912 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
-rw-r--r--lib/Analysis/ConstantFolding.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 48e75a1d5d..6e2a8d4756 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -54,37 +54,35 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
// Handle a vector->integer cast.
if (IntegerType *IT = dyn_cast<IntegerType>(DestTy)) {
- // FIXME: Remove ConstantVector support.
- if ((!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C)) ||
- // TODO: Handle big endian someday.
- !TD.isLittleEndian())
+ ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
+ if (CDV == 0)
return ConstantExpr::getBitCast(C, DestTy);
- unsigned NumSrcElts = C->getType()->getVectorNumElements();
+ unsigned NumSrcElts = CDV->getType()->getNumElements();
+
+ Type *SrcEltTy = CDV->getType()->getElementType();
// If the vector is a vector of floating point, convert it to vector of int
// to simplify things.
- if (C->getType()->getVectorElementType()->isFloatingPointTy()) {
- unsigned FPWidth =
- C->getType()->getVectorElementType()->getPrimitiveSizeInBits();
+ if (SrcEltTy->isFloatingPointTy()) {
+ unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits();
Type *SrcIVTy =
VectorType::get(IntegerType::get(C->getContext(), FPWidth), NumSrcElts);
// Ask VMCore to do the conversion now that #elts line up.
C = ConstantExpr::getBitCast(C, SrcIVTy);
+ CDV = cast<ConstantDataVector>(C);
}
// Now that we know that the input value is a vector of integers, just shift
// and insert them into our result.
- unsigned BitShift =
- TD.getTypeAllocSizeInBits(C->getType()->getVectorElementType());
+ unsigned BitShift = TD.getTypeAllocSizeInBits(SrcEltTy);
APInt Result(IT->getBitWidth(), 0);
for (unsigned i = 0; i != NumSrcElts; ++i) {
- // FIXME: Rework when we have ConstantDataVector.
- ConstantInt *Elt=dyn_cast_or_null<ConstantInt>(C->getAggregateElement(i));
- if (Elt == 0) // Elt must be a constant expr or something.
- return ConstantExpr::getBitCast(C, DestTy);
-
- Result |= Elt->getValue().zextOrSelf(IT->getBitWidth()) << i*BitShift;
+ Result <<= BitShift;
+ if (TD.isLittleEndian())
+ Result |= CDV->getElementAsInteger(NumSrcElts-i-1);
+ else
+ Result |= CDV->getElementAsInteger(i);
}
return ConstantInt::get(IT, Result);
@@ -103,7 +101,6 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
}
// If this is a bitcast from constant vector -> vector, fold it.
- // FIXME: Remove ConstantVector support.
if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
return ConstantExpr::getBitCast(C, DestTy);
@@ -350,7 +347,6 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
// not reached.
}
- // FIXME: Remove ConstantVector
if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
isa<ConstantDataSequential>(C)) {
Type *EltTy = cast<SequentialType>(C->getType())->getElementType();