From 8373d38afddec4ade17f72088cb5eeb229e87238 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Wed, 3 Sep 2008 06:48:55 +0000 Subject: [PATCH] Try to fold each element of a vector. This is needed to maintain structural equivalence. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55694 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 25c756ab6e5..93cfccf1f5e 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -238,12 +238,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, std::vector res; const VectorType *DestVecTy = cast(DestTy); const Type *DstEltTy = DestVecTy->getElementType(); - for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) { - Constant *C = ConstantFoldCastInstruction(opc, CV->getOperand(i), - DstEltTy); - if (!C) return 0; // Can't fold operand. - res.push_back(C); - } + for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) + res.push_back(ConstantExpr::getCast(opc, CV->getOperand(i), DstEltTy)); return ConstantVector::get(DestVecTy, res); } return 0; // Can't fold. @@ -271,12 +267,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, std::vector res; const VectorType *DestVecTy = cast(DestTy); const Type *DstEltTy = DestVecTy->getElementType(); - for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) { - Constant *C = ConstantFoldCastInstruction(opc, CV->getOperand(i), - DstEltTy); - if (!C) return 0; // Can't fold operand. - res.push_back(C); - } + for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) + res.push_back(ConstantExpr::getCast(opc, CV->getOperand(i), DstEltTy)); return ConstantVector::get(DestVecTy, res); } return 0; -- 2.34.1