Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -726,9 +726,11 @@ SmallVector NewIdxs; for (unsigned i = 1, e = Ops.size(); i != e; ++i) { if ((i == 1 || - !isa(GetElementPtrInst::getIndexedType(SrcElemTy, - Ops.slice(1, i - 1)))) && - Ops[i]->getType() != IntPtrTy) { + !isa(GetElementPtrInst::getIndexedType( + SrcElemTy, Ops.slice(1, i - 1)))) && + Ops[i]->getType() != IntPtrTy && + Ops[i]->getType()->getPrimitiveSizeInBits() == + IntPtrTy->getPrimitiveSizeInBits()) { Any = true; NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i], true, Index: test/Transforms/InstCombine/gep-vector.ll =================================================================== --- test/Transforms/InstCombine/gep-vector.ll +++ test/Transforms/InstCombine/gep-vector.ll @@ -13,3 +13,13 @@ %el = getelementptr inbounds i64, i64* undef, <8 x i64> undef ret <8 x i64*> %el } + +%struct.foo = type { [0 x i64] } + +; CHECK-LABEL: patatino3 +; CHECK-NEXT: ret <8 x i64*> undef +define <8 x i64*> @patatino3(%struct.foo*) { + %2 = getelementptr inbounds %struct.foo, %struct.foo* undef, i64 0, + i32 0, <8 x i64> undef + ret <8 x i64*> %2 +}