[PATCH] D51716: [MemorySSA] Add API to reset optimized for uses of a replaced instruction.

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 5 23:00:46 PDT 2018


asbirlea created this revision.
asbirlea added a reviewer: george.burgess.iv.
Herald added subscribers: Prazek, jlebar, sanjoy.

If an instruction is optimized and replaced with another value, all the uses (instructions) of the replaced instruction, now point to said value.
This means that if these uses (instructions) have MemoryAccesses attached, they need to be un-optimized, as they may not longer have teh same clobbering access.
The use case that triggered this is in EarlyCSE w/ MemorySSA, where the replacement value is "undef".


Repository:
  rL LLVM

https://reviews.llvm.org/D51716

Files:
  include/llvm/Analysis/MemorySSAUpdater.h
  lib/Analysis/MemorySSAUpdater.cpp


Index: lib/Analysis/MemorySSAUpdater.cpp
===================================================================
--- lib/Analysis/MemorySSAUpdater.cpp
+++ lib/Analysis/MemorySSAUpdater.cpp
@@ -607,6 +607,19 @@
   }
 }
 
+void MemorySSAUpdater::resetOptimizeUses(const Instruction *I) {
+  for (auto &U : I->uses()) {
+    auto *UsrI = dyn_cast<Instruction>(U.getUser());
+    if (!UsrI)
+      continue;
+    if (auto *MA = MSSA->getMemoryAccess(UsrI)) {
+      auto *MUD = cast<MemoryUseOrDef>(MA);
+      if (MUD->isOptimized())
+        MUD->resetOptimized();
+    }
+  }
+}
+
 MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
     Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
     MemorySSA::InsertionPlace Point) {
Index: include/llvm/Analysis/MemorySSAUpdater.h
===================================================================
--- include/llvm/Analysis/MemorySSAUpdater.h
+++ include/llvm/Analysis/MemorySSAUpdater.h
@@ -198,6 +198,12 @@
   /// deleted after this call.
   void removeBlocks(const SmallPtrSetImpl<BasicBlock *> &DeadBlocks);
 
+  /// Reset optimized for uses of a given instruction, if those uses have
+  /// MemoryAccesses. This should be called when the instruction is about to be
+  /// replaced, since its replacement may change the clobber (e.g., simplify to
+  /// undef).
+  void resetOptimizeUses(const Instruction *I);
+
   /// Get handle on MemorySSA.
   MemorySSA* getMemorySSA() const { return MSSA; }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51716.164148.patch
Type: text/x-patch
Size: 1463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180906/4b7ee5d6/attachment.bin>


More information about the llvm-commits mailing list