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 | b348d18caf834bc26a80e60aa7a2c9b1748734e8 (patch) | |
tree | a2c805de94c3e8f5ffbbeae56cee332a2a5a5695 /lib/VMCore/ConstantFold.cpp | |
parent | 247fdca789b10543848e110ab0860f99724b6788 (diff) |
Add support for vectors to int <-> float casts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44204 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 257e4813d1..95140f3fe1 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/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)) { |