diff --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h --- a/llvm/include/llvm/Analysis/MemorySSA.h +++ b/llvm/include/llvm/Analysis/MemorySSA.h @@ -784,6 +784,11 @@ /// about the beginning or end of a block. enum InsertionPlace { Beginning, End, BeforeTerminator }; + /// Returns true if there are no memory defs in the function. + bool empty_defs() const { + return PerBlockDefs.empty(); + } + protected: // Used by Memory SSA dumpers and wrapper pass friend class MemorySSAPrinterLegacyPass; diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1876,6 +1876,9 @@ const LoopInfo &LI) { bool MadeChange = false; + if (MSSA.empty_defs()) + return false; + DSEState State(F, AA, MSSA, DT, TLI, LI); // For each store: for (unsigned I = 0; I < State.MemDefs.size(); I++) {