diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -122,6 +122,8 @@ "into) when deducing if a value is fully avaliable or not in GVN " "(default = 600)")); +extern cl::opt AllowJumpyDebugTables; + struct llvm::GVN::Expression { uint32_t opcode; bool commutative = false; @@ -1312,10 +1314,12 @@ // Assign value numbers to the new instructions. for (Instruction *I : NewInsts) { // Instructions that have been inserted in predecessor(s) to materialize - // the load address do not retain their original debug locations. Doing - // so could lead to confusing (but correct) source attributions. + // the load address can retain their original debug locations. Doing + // so leads to confusing source attributions. However as locations are + // correct, they can be useful. if (const DebugLoc &DL = I->getDebugLoc()) - I->setDebugLoc(DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt())); + if (!AllowJumpyDebugTables) + I->setDebugLoc(DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt())); // FIXME: We really _ought_ to insert these value numbers into their // parent's availability map. However, in doing so, we risk getting into diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -134,6 +134,10 @@ "number of accesses allowed to be present in a loop in order to " "enable memory promotion.")); +cl::opt AllowJumpyDebugTables( + "allow-jumpy-debug-lines-tables", cl::Hidden, cl::init(false), + cl::desc("Retain debug locations of instructions moved by eg. LICM.")); + static bool inSubLoop(BasicBlock *BB, Loop *CurLoop, LoopInfo *LI); static bool isNotUsedOrFreeInLoop(const Instruction &I, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo, @@ -1659,9 +1663,10 @@ moveInstructionBefore(I, *Dest->getTerminator(), *SafetyInfo, MSSAU, SE); // Apply line 0 debug locations when we are moving instructions to different - // basic blocks because we want to avoid jumpy line tables. + // basic blocks if we want to avoid jumpy line tables. if (const DebugLoc &DL = I.getDebugLoc()) - I.setDebugLoc(DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt())); + if (!AllowJumpyDebugTables) + I.setDebugLoc(DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt())); if (isa(I)) ++NumMovedLoads;