diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2010-01-21 07:03:21 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2010-01-21 07:03:21 +0000 |
commit | 9e26c1cc0c48bf9fed270ec9d6abdb46fbc8114c (patch) | |
tree | da8235bf04c810efecc694dc15761ffc347a9d94 /llvm/lib/VMCore/Constants.cpp | |
parent | f2f73bf214a0b4ce7b3dc62de98144b6b00e2e05 (diff) | |
download | bcm5719-llvm-9e26c1cc0c48bf9fed270ec9d6abdb46fbc8114c.tar.gz bcm5719-llvm-9e26c1cc0c48bf9fed270ec9d6abdb46fbc8114c.zip |
Fix a crasher trying to fold each element in a comparison between two vectors
if one of the vectors didn't have elements (such as undef). Fixes PR 6096.
Fix an issue in the constant folder where fcmp (<2 x %ty>, <2 x %ty>) would
have <2 x i1> type if constant folding was successful and i1 type if it wasn't.
This exposed a related issue in the bitcode reader.
llvm-svn: 94069
Diffstat (limited to 'llvm/lib/VMCore/Constants.cpp')
-rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index cc8961fb5f5..916aac695fe 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -1630,7 +1630,7 @@ Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C, } Constant * -ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) { +ConstantExpr::getICmp(unsigned short pred, Constant *LHS, Constant *RHS) { assert(LHS->getType() == RHS->getType()); assert(pred >= ICmpInst::FIRST_ICMP_PREDICATE && pred <= ICmpInst::LAST_ICMP_PREDICATE && "Invalid ICmp Predicate"); @@ -1646,13 +1646,16 @@ ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) { // Get the key type with both the opcode and predicate const ExprMapKeyType Key(Instruction::ICmp, ArgVec, pred); + const Type *ResultTy = Type::getInt1Ty(LHS->getContext()); + if (const VectorType *VT = dyn_cast<VectorType>(LHS->getType())) + ResultTy = VectorType::get(ResultTy, VT->getNumElements()); + LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl; - return - pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key); + return pImpl->ExprConstants.getOrCreate(ResultTy, Key); } Constant * -ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) { +ConstantExpr::getFCmp(unsigned short pred, Constant *LHS, Constant *RHS) { assert(LHS->getType() == RHS->getType()); assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && "Invalid FCmp Predicate"); @@ -1666,10 +1669,13 @@ ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) { ArgVec.push_back(RHS); // Get the key type with both the opcode and predicate const ExprMapKeyType Key(Instruction::FCmp, ArgVec, pred); - + + const Type *ResultTy = Type::getInt1Ty(LHS->getContext()); + if (const VectorType *VT = dyn_cast<VectorType>(LHS->getType())) + ResultTy = VectorType::get(ResultTy, VT->getNumElements()); + LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl; - return - pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key); + return pImpl->ExprConstants.getOrCreate(ResultTy, Key); } Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val, |