summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2007-11-17 03:58:34 +0000
committerNate Begeman <natebegeman@mac.com>2007-11-17 03:58:34 +0000
commitd4d45c268c407405aa3367eacd2412b43e144b87 (patch)
treec919e61bead63fe51b739b55006ca4e9b74b8a45 /llvm/lib/VMCore/ConstantFold.cpp
parentb6c40f3f1b580fc85f1ffb38fff40acc383bb6df (diff)
downloadbcm5719-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.cpp18
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)) {
OpenPOWER on IntegriCloud