Index: llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp =================================================================== --- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -967,16 +967,19 @@ for (unsigned Ri = 0; Ri != RetCount; ++Ri) if (NewRetIdxs[Ri] != -1) { Value *V; - if (RetTypes.size() > 1) + if (RetTypes.size() > 1) { // We are still returning a struct, so extract the value from our // return value V = ExtractValueInst::Create(NewCB, NewRetIdxs[Ri], "newret", InsertPt); - else + cast(V)->setDebugLoc(InsertPt->getDebugLoc()); + } else { // We are now returning a single element, so just insert that V = NewCB; + } // Insert the value at the old position RetVal = InsertValueInst::Create(RetVal, V, Ri, "oldret", InsertPt); + cast(RetVal)->setDebugLoc(InsertPt->getDebugLoc()); } // Now, replace all uses of the old call instruction with the return // struct we built @@ -1035,12 +1038,14 @@ if (NewRetIdxs[RetI] != -1) { ExtractValueInst *EV = ExtractValueInst::Create(OldRet, RetI, "oldret", RI); + EV->setDebugLoc(RI->getDebugLoc()); if (RetTypes.size() > 1) { // We're still returning a struct, so reinsert the value into // our new return value at the new index RetVal = InsertValueInst::Create(RetVal, EV, NewRetIdxs[RetI], "newret", RI); + cast(RetVal)->setDebugLoc(RI->getDebugLoc()); } else { // We are now only returning a simple value, so just return the // extracted value. Index: llvm/test/Transforms/DeadArgElim/multdeadretval.ll =================================================================== --- llvm/test/Transforms/DeadArgElim/multdeadretval.ll +++ llvm/test/Transforms/DeadArgElim/multdeadretval.ll @@ -4,6 +4,12 @@ ; any remaining dead stuff. ; RUN: opt < %s -deadargelim -instcombine -dce -S | not grep i16 +; RUN: opt < %s -enable-debugify=synthetic -deadargelim -S 2>&1 \ +; RUN: | FileCheck %s -check-prefix=DEBUG + +; Check that every instruction inserted by -deadargelim has a debug location. +; DEBUG: CheckModuleDebugify: PASS + define internal {i16, i32} @test(i16 %DEADARG) { %A = insertvalue {i16,i32} undef, i16 1, 0 %B = insertvalue {i16,i32} %A, i32 1001, 1