Index: include/llvm/IR/Instructions.h =================================================================== --- include/llvm/IR/Instructions.h +++ include/llvm/IR/Instructions.h @@ -845,6 +845,13 @@ return cast(Instruction::getType()); } + Type *getSourceElementType() const { + SequentialType *Ty = cast(getPointerOperandType()); + if (VectorType *VTy = dyn_cast(Ty)) + Ty = cast(VTy->getElementType()); + return Ty->getElementType(); + } + /// \brief Returns the address space of this instruction's pointer type. unsigned getAddressSpace() const { // Note that this is always the same as the pointer operand's address space Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -5364,8 +5364,18 @@ bool InBounds = EatIfPresent(lltok::kw_inbounds); + Type *Ty = nullptr; + if (ParseType(Ty)) return true; + ParseToken(lltok::comma, "expected comma after getelementptr's type"); + if (ParseTypeAndValue(Ptr, Loc, PFS)) return true; + + Type *PtrTy = Ptr->getType(); + if (VectorType *VT = dyn_cast(PtrTy)) + PtrTy = VT->getElementType(); + assert(Ty == cast(PtrTy)->getElementType()); + Type *BaseType = Ptr->getType(); PointerType *BasePointerType = dyn_cast(BaseType->getScalarType()); if (!BasePointerType) Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -2880,6 +2880,11 @@ Out << ", "; TypePrinter.print(I.getType(), Out); } else if (Operand) { // Print the normal way. + if (const GetElementPtrInst *GEP = dyn_cast(&I)) { + Out << ' '; + TypePrinter.print(GEP->getSourceElementType(), Out); + Out << ','; + } // PrintAllTypes - Instructions who have operands of all the same type // omit the type from all but the first operand. If the instruction has Index: unittests/IR/ConstantsTest.cpp =================================================================== --- unittests/IR/ConstantsTest.cpp +++ unittests/IR/ConstantsTest.cpp @@ -246,9 +246,9 @@ // FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP, // not a normal one! //CHECK(ConstantExpr::getGetElementPtr(Global, V, false), - // "getelementptr i32** @dummy, i32 1"); + // "getelementptr i32*, i32** @dummy, i32 1"); CHECK(ConstantExpr::getInBoundsGetElementPtr(Global, V), - "getelementptr inbounds i32** @dummy, i32 1"); + "getelementptr inbounds i32*, i32** @dummy, i32 1"); CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> " P6STR ", i32 1");