diff options
author | Nate Begeman <natebegeman@mac.com> | 2007-11-17 03:58:34 +0000 |
---|---|---|
committer | Nate Begeman <natebegeman@mac.com> | 2007-11-17 03:58:34 +0000 |
commit | d4d45c268c407405aa3367eacd2412b43e144b87 (patch) | |
tree | c919e61bead63fe51b739b55006ca4e9b74b8a45 /llvm/lib/VMCore/ConstantFold.cpp | |
parent | b6c40f3f1b580fc85f1ffb38fff40acc383bb6df (diff) | |
download | bcm5719-llvm-d4d45c268c407405aa3367eacd2412b43e144b87.tar.gz bcm5719-llvm-d4d45c268c407405aa3367eacd2412b43e144b87.zip |
Add support for vectors to int <-> float casts.
llvm-svn: 44204
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index 257e4813d1d..95140f3fe1d 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -202,6 +202,15 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, APInt Val(DestBitWidth, 2, x); return ConstantInt::get(Val); } + if (const ConstantVector *CV = dyn_cast<ConstantVector>(V)) { + std::vector<Constant*> res; + const VectorType *DestVecTy = cast<VectorType>(DestTy); + const Type *DstEltTy = DestVecTy->getElementType(); + for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) + res.push_back(ConstantFoldCastInstruction(opc, V->getOperand(i), + DstEltTy)); + return ConstantVector::get(DestVecTy, res); + } return 0; // Can't fold. case Instruction::IntToPtr: //always treated as unsigned if (V->isNullValue()) // Is it an integral null value? @@ -224,6 +233,15 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, APFloat::rmNearestTiesToEven); return ConstantFP::get(DestTy, apf); } + if (const ConstantVector *CV = dyn_cast<ConstantVector>(V)) { + std::vector<Constant*> res; + const VectorType *DestVecTy = cast<VectorType>(DestTy); + const Type *DstEltTy = DestVecTy->getElementType(); + for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) + res.push_back(ConstantFoldCastInstruction(opc, V->getOperand(i), + DstEltTy)); + return ConstantVector::get(DestVecTy, res); + } return 0; case Instruction::ZExt: if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |