From 8213c8af290f42bcdac070f0131d2fdabe76c93f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 6 Feb 2012 21:56:39 +0000 Subject: Remove some dead code and tidy things up now that vectors use ConstantDataVector instead of always using ConstantVector. llvm-svn: 149912 --- llvm/lib/Analysis/ConstantFolding.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'llvm/lib/Analysis/ConstantFolding.cpp') diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 48e75a1d5d7..6e2a8d47563 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/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(DestTy)) { - // FIXME: Remove ConstantVector support. - if ((!isa(C) && !isa(C)) || - // TODO: Handle big endian someday. - !TD.isLittleEndian()) + ConstantDataVector *CDV = dyn_cast(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(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(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(C) && !isa(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(C) || isa(C) || isa(C)) { Type *EltTy = cast(C->getType())->getElementType(); -- cgit v1.2.3