Index: lib/IR/ConstantFold.cpp =================================================================== --- lib/IR/ConstantFold.cpp +++ lib/IR/ConstantFold.cpp @@ -2040,11 +2040,13 @@ return C; if (isa(C)) { - PointerType *PtrTy = cast(C->getType()); - Type *Ty = GetElementPtrInst::getIndexedType( - cast(PtrTy->getScalarType())->getElementType(), Idxs); + PointerType *PtrTy = cast(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(C->getType())) + GEPTy = VectorType::get(GEPTy, VT->getNumElements()); + return UndefValue::get(GEPTy); } if (C->isNullValue()) { @@ -2055,12 +2057,14 @@ break; } if (isNull) { - PointerType *PtrTy = cast(C->getType()); - Type *Ty = GetElementPtrInst::getIndexedType( - cast(PtrTy->getScalarType())->getElementType(), Idxs); + PointerType *PtrTy = cast(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(C->getType())) + GEPTy = VectorType::get(GEPTy, VT->getNumElements()); + return Constant::getNullValue(GEPTy); } } Index: test/Assembler/ConstantExprFold.ll =================================================================== --- test/Assembler/ConstantExprFold.ll +++ test/Assembler/ConstantExprFold.ll @@ -30,3 +30,7 @@ @cons = weak global i32 0, align 8 ; [#uses=1] global i64 and (i64 ptrtoint (i32* @cons to i64), i64 7) +global <2 x i8*> getelementptr(i8, <2 x i8*> undef, <2 x i64> ) +global <2 x i8*> getelementptr({ i8 }, <2 x { i8 }*> undef, <2 x i64> , <2 x i32> ) +global <2 x i8*> getelementptr(i8, <2 x i8*> zeroinitializer, <2 x i64> ) +global <2 x i8*> getelementptr({ i8 }, <2 x { i8 }*> zeroinitializer, <2 x i64> , <2 x i32> )