diff options
author | Manuel Jacob <me@manueljacob.de> | 2016-01-19 16:34:31 +0000 |
---|---|---|
committer | Manuel Jacob <me@manueljacob.de> | 2016-01-19 16:34:31 +0000 |
commit | c784e6acd91e62eac7bea374ff5eec62a32a511f (patch) | |
tree | befe0befcf90caed5cd7c276ed309ad3be4bccc8 /llvm/lib/IR/ConstantFold.cpp | |
parent | e04dd2525c43330e6b7348cb65d4d033d3eaf6db (diff) | |
download | bcm5719-llvm-c784e6acd91e62eac7bea374ff5eec62a32a511f.tar.gz bcm5719-llvm-c784e6acd91e62eac7bea374ff5eec62a32a511f.zip |
Fix constant folding of constant vector GEPs with undef or null as pointer argument.
Reviewers: eddyb
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D16321
llvm-svn: 258134
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 35855860129..7e73be124c3 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -2040,11 +2040,13 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, return C; if (isa<UndefValue>(C)) { - PointerType *PtrTy = cast<PointerType>(C->getType()); - Type *Ty = GetElementPtrInst::getIndexedType( - cast<PointerType>(PtrTy->getScalarType())->getElementType(), Idxs); + PointerType *PtrTy = cast<PointerType>(C->getType()->getScalarType()); + Type *Ty = GetElementPtrInst::getIndexedType(PtrTy->getElementType(), Idxs); assert(Ty && "Invalid indices for GEP!"); - return UndefValue::get(PointerType::get(Ty, PtrTy->getAddressSpace())); + Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace()); + if (VectorType *VT = dyn_cast<VectorType>(C->getType())) + GEPTy = VectorType::get(GEPTy, VT->getNumElements()); + return UndefValue::get(GEPTy); } if (C->isNullValue()) { @@ -2055,12 +2057,14 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, break; } if (isNull) { - PointerType *PtrTy = cast<PointerType>(C->getType()); - Type *Ty = GetElementPtrInst::getIndexedType( - cast<PointerType>(PtrTy->getScalarType())->getElementType(), Idxs); + PointerType *PtrTy = cast<PointerType>(C->getType()->getScalarType()); + Type *Ty = + GetElementPtrInst::getIndexedType(PtrTy->getElementType(), Idxs); assert(Ty && "Invalid indices for GEP!"); - return ConstantPointerNull::get(PointerType::get(Ty, - PtrTy->getAddressSpace())); + Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace()); + if (VectorType *VT = dyn_cast<VectorType>(C->getType())) + GEPTy = VectorType::get(GEPTy, VT->getNumElements()); + return Constant::getNullValue(GEPTy); } } |