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 @@ -42,6 +42,7 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" +#include "llvm/IR/InstIterator.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" @@ -61,8 +62,8 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" -#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" +#include "llvm/Transforms/Utils/Local.h" #include #include #include @@ -75,6 +76,7 @@ #define DEBUG_TYPE "dse" +STATISTIC(NumRemainingStores, "Number of stores remaining after DSE"); STATISTIC(NumRedundantStores, "Number of redundant stores deleted"); STATISTIC(NumFastStores, "Number of stores deleted"); STATISTIC(NumFastOther, "Number of other instrs removed"); @@ -1965,19 +1967,26 @@ const TargetLibraryInfo &TLI = AM.getResult(F); DominatorTree &DT = AM.getResult(F); + bool Changed = false; if (EnableMemorySSA) { MemorySSA &MSSA = AM.getResult(F).getMSSA(); PostDominatorTree &PDT = AM.getResult(F); - if (!eliminateDeadStoresMemorySSA(F, AA, MSSA, DT, PDT, TLI)) - return PreservedAnalyses::all(); + Changed = eliminateDeadStoresMemorySSA(F, AA, MSSA, DT, PDT, TLI); } else { MemoryDependenceResults &MD = AM.getResult(F); - if (!eliminateDeadStores(F, &AA, &MD, &DT, &TLI)) - return PreservedAnalyses::all(); + Changed = eliminateDeadStores(F, &AA, &MD, &DT, &TLI); } +#ifdef LLVM_ENABLE_STATS + for (auto &I : instructions(F)) + NumRemainingStores += isa(&I); +#endif + + if (!Changed) + return PreservedAnalyses::all(); + PreservedAnalyses PA; PA.preserveSet(); PA.preserve(); @@ -2008,18 +2017,26 @@ const TargetLibraryInfo &TLI = getAnalysis().getTLI(F); + bool Changed = false; if (EnableMemorySSA) { MemorySSA &MSSA = getAnalysis().getMSSA(); PostDominatorTree &PDT = getAnalysis().getPostDomTree(); - return eliminateDeadStoresMemorySSA(F, AA, MSSA, DT, PDT, TLI); + eliminateDeadStoresMemorySSA(F, AA, MSSA, DT, PDT, TLI); } else { MemoryDependenceResults &MD = getAnalysis().getMemDep(); - return eliminateDeadStores(F, &AA, &MD, &DT, &TLI); + Changed = eliminateDeadStores(F, &AA, &MD, &DT, &TLI); } + +#ifdef LLVM_ENABLE_STATS + for (auto &I : instructions(F)) + NumRemainingStores += isa(&I); +#endif + + return Changed; } void getAnalysisUsage(AnalysisUsage &AU) const override {