diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 81691a5f69aa0..ada921bc2dea4 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -37,45 +37,6 @@ using namespace llvm::PatternMatch; // ConstantFold*Instruction Implementations //===----------------------------------------------------------------------===// -/// Convert the specified vector Constant node to the specified vector type. -/// At this point, we know that the elements of the input vector constant are -/// all simple integer or FP values. -static Constant *BitCastConstantVector(Constant *CV, VectorType *DstTy) { - - if (CV->isAllOnesValue()) return Constant::getAllOnesValue(DstTy); - if (CV->isNullValue()) return Constant::getNullValue(DstTy); - - // Do not iterate on scalable vector. The num of elements is unknown at - // compile-time. - if (isa(DstTy)) - return nullptr; - - // If this cast changes element count then we can't handle it here: - // doing so requires endianness information. This should be handled by - // Analysis/ConstantFolding.cpp - unsigned NumElts = cast(DstTy)->getNumElements(); - if (NumElts != cast(CV->getType())->getNumElements()) - return nullptr; - - Type *DstEltTy = DstTy->getElementType(); - // Fast path for splatted constants. - if (Constant *Splat = CV->getSplatValue()) { - return ConstantVector::getSplat(DstTy->getElementCount(), - ConstantExpr::getBitCast(Splat, DstEltTy)); - } - - SmallVector Result; - Type *Ty = IntegerType::get(CV->getContext(), 32); - for (unsigned i = 0; i != NumElts; ++i) { - Constant *C = - ConstantExpr::getExtractElement(CV, ConstantInt::get(Ty, i)); - C = ConstantExpr::getBitCast(C, DstEltTy); - Result.push_back(C); - } - - return ConstantVector::get(Result); -} - /// This function determines which opcode to use to fold two constant cast /// expressions together. It uses CastInst::isEliminableCastPair to determine /// the opcode. Consequently its just a wrapper around that function. @@ -114,24 +75,12 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) { // Handle casts from one vector constant to another. We know that the src // and dest type have the same size (otherwise its an illegal cast). if (VectorType *DestPTy = dyn_cast(DestTy)) { - if (VectorType *SrcTy = dyn_cast(V->getType())) { - assert(DestPTy->getPrimitiveSizeInBits() == - SrcTy->getPrimitiveSizeInBits() && - "Not cast between same sized vectors!"); - SrcTy = nullptr; - // First, check for null. Undef is already handled. - if (isa(V)) - return Constant::getNullValue(DestTy); - - // Handle ConstantVector and ConstantAggregateVector. - return BitCastConstantVector(V, DestPTy); - } - // Canonicalize scalar-to-vector bitcasts into vector-to-vector bitcasts // This allows for other simplifications (although some of them // can only be handled by Analysis/ConstantFolding.cpp). if (isa(V) || isa(V)) return ConstantExpr::getBitCast(ConstantVector::get(V), DestPTy); + return nullptr; } // Finally, implement bitcast folding now. The code below doesn't handle