Index: llvm/trunk/lib/Analysis/ConstantFolding.cpp =================================================================== --- llvm/trunk/lib/Analysis/ConstantFolding.cpp +++ llvm/trunk/lib/Analysis/ConstantFolding.cpp @@ -742,13 +742,16 @@ if ((i == 1 || !isa(GetElementPtrInst::getIndexedType( SrcElemTy, Ops.slice(1, i - 1)))) && - Ops[i]->getType() != (i == 1 ? IntPtrTy : IntPtrScalarTy)) { + Ops[i]->getType()->getScalarType() != IntPtrScalarTy) { Any = true; + Type *NewType = Ops[i]->getType()->isVectorTy() + ? IntPtrTy + : IntPtrTy->getScalarType(); NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i], true, - IntPtrTy, + NewType, true), - Ops[i], IntPtrTy)); + Ops[i], NewType)); } else NewIdxs.push_back(Ops[i]); } Index: llvm/trunk/test/Analysis/ConstantFolding/vectorgep-crash.ll =================================================================== --- llvm/trunk/test/Analysis/ConstantFolding/vectorgep-crash.ll +++ llvm/trunk/test/Analysis/ConstantFolding/vectorgep-crash.ll @@ -17,3 +17,24 @@ %0 = bitcast <8 x double*> %VectorGep14 to <8 x i64*> ret <8 x i64*> %0 } + +%struct.A = type { i32, %struct.B* } +%struct.B = type { i64, %struct.C* } +%struct.C = type { i64 } + +@G = internal global [65 x %struct.A] zeroinitializer, align 16 +; CHECK-LABEL: @test +; CHECK: ret <16 x i32*> getelementptr ([65 x %struct.A], [65 x %struct.A]* @G, <16 x i64> zeroinitializer, <16 x i64> , <16 x i32> zeroinitializer) +define <16 x i32*> @test() { +vector.body: + %VectorGep = getelementptr [65 x %struct.A], [65 x %struct.A]* @G, <16 x i64> zeroinitializer, <16 x i64> , <16 x i32> zeroinitializer + ret <16 x i32*> %VectorGep +} + +; CHECK-LABEL: @test2 +; CHECK: ret <16 x i32*> getelementptr ([65 x %struct.A], [65 x %struct.A]* @G, <16 x i64> zeroinitializer, <16 x i64> @test2() { +vector.body: + %VectorGep = getelementptr [65 x %struct.A], [65 x %struct.A]* @G, <16 x i32> zeroinitializer, <16 x i64> , <16 x i32> zeroinitializer + ret <16 x i32*> %VectorGep +}