Index: llvm/lib/Transforms/Scalar/LICM.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LICM.cpp +++ llvm/lib/Transforms/Scalar/LICM.cpp @@ -184,6 +184,9 @@ static void moveInstructionBefore(Instruction &I, Instruction &Dest, ICFLoopSafetyInfo &SafetyInfo, MemorySSAUpdater *MSSAU, ScalarEvolution *SE); +#ifndef NDEBUG +static std::string getBlockName(const BasicBlock *BB); +#endif namespace { struct LoopInvariantCodeMotion { @@ -221,6 +224,9 @@ if (skipLoop(L)) return false; + LLVM_DEBUG(dbgs() << "Perform LICM on Loop with header at block " + << getBlockName(L->getHeader()) << "\n"); + auto *SE = getAnalysisIfAvailable(); MemorySSA *MSSA = EnableMSSALoopDependency ? (&getAnalysis().getMSSA()) @@ -698,8 +704,8 @@ // If not involved in a pending branch, hoist to preheader BasicBlock *InitialPreheader = CurLoop->getLoopPreheader(); if (It == HoistableBranches.end()) { - LLVM_DEBUG(dbgs() << "LICM using " << InitialPreheader->getName() - << " as hoist destination for " << BB->getName() + LLVM_DEBUG(dbgs() << "LICM using " << getBlockName(InitialPreheader) + << " as hoist destination for " << getBlockName(BB) << "\n"); HoistDestinationMap[BB] = InitialPreheader; return InitialPreheader; @@ -979,8 +985,8 @@ HoistPoint = Dominator->getTerminator(); } LLVM_DEBUG(dbgs() << "LICM rehoisting to " - << HoistPoint->getParent()->getName() - << ": " << *I << "\n"); + << getBlockName(HoistPoint->getParent()) << ": " << *I + << "\n"); moveInstructionBefore(*I, *HoistPoint, *SafetyInfo, MSSAU, SE); HoistPoint = I; Changed = true; @@ -1738,7 +1744,7 @@ BasicBlock *Dest, ICFLoopSafetyInfo *SafetyInfo, MemorySSAUpdater *MSSAU, ScalarEvolution *SE, OptimizationRemarkEmitter *ORE) { - LLVM_DEBUG(dbgs() << "LICM hoisting to " << Dest->getName() << ": " << I + LLVM_DEBUG(dbgs() << "LICM hoisting to " << getBlockName(Dest) << ": " << I << "\n"); ORE->emit([&]() { return OptimizationRemark(DEBUG_TYPE, "Hoisted", &I) << "hoisting " @@ -2354,3 +2360,16 @@ assert(CurLoop->contains(BB) && "Only valid if BB is IN the loop"); return LI->getLoopFor(BB) != CurLoop; } + +#ifndef NDEBUG +/// Return block name, for unnamed block, return its label. +static std::string getBlockName(const BasicBlock *BB) { + if (!BB->getName().empty()) + return std::string(BB->getName()); + + std::string BBName; + raw_string_ostream OS(BBName); + BB->printAsOperand(OS, false); + return OS.str(); +} +#endif \ No newline at end of file