[llvm] 034e66e - [DSE] Assert analyzable write in isRemovable() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 24 01:40:53 PST 2021


Author: Nikita Popov
Date: 2021-12-24T10:39:50+01:00
New Revision: 034e66e76c6f0f76aa7c67ba4edf4eba108bcf51

URL: https://github.com/llvm/llvm-project/commit/034e66e76c6f0f76aa7c67ba4edf4eba108bcf51
DIFF: https://github.com/llvm/llvm-project/commit/034e66e76c6f0f76aa7c67ba4edf4eba108bcf51.diff

LOG: [DSE] Assert analyzable write in isRemovable() (NFC)

As requested on D116210. The function is not necessarily well-defined
without this precondition.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 19770c46b68c..a5b69e863e7d 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -175,30 +175,6 @@ static cl::opt<bool>
 using OverlapIntervalsTy = std::map<int64_t, int64_t>;
 using InstOverlapIntervalsTy = DenseMap<Instruction *, OverlapIntervalsTy>;
 
-/// If the value of this instruction and the memory it writes to is unused, may
-/// we delete this instruction?
-static bool isRemovable(Instruction *I) {
-  // Don't remove volatile/atomic stores.
-  if (StoreInst *SI = dyn_cast<StoreInst>(I))
-    return SI->isUnordered();
-
-  // Note: only get here for calls with analyzable writes.
-  if (auto *CB = dyn_cast<CallBase>(I)) {
-    // Don't remove volatile memory intrinsics.
-    if (auto *MI = dyn_cast<MemIntrinsic>(CB))
-      return !MI->isVolatile();
-
-    // Never remove dead lifetime intrinsics, e.g. because they are followed by
-    // a free.
-    if (CB->isLifetimeStartOrEnd())
-      return false;
-
-    return CB->use_empty() && CB->willReturn() && CB->doesNotThrow();
-  }
-
-  return false;
-}
-
 /// Returns true if the end of this instruction can be safely shortened in
 /// length.
 static bool isShortenableAtTheEnd(Instruction *I) {
@@ -1024,6 +1000,31 @@ struct DSEState {
     return MemoryLocation::getOrNone(I);
   }
 
+  /// Assuming this instruction has a dead analyzable write, can we delete
+  /// this instruction?
+  bool isRemovable(Instruction *I) {
+    assert(getLocForWriteEx(I) && "Must have analyzable write");
+
+    // Don't remove volatile/atomic stores.
+    if (StoreInst *SI = dyn_cast<StoreInst>(I))
+      return SI->isUnordered();
+
+    if (auto *CB = dyn_cast<CallBase>(I)) {
+      // Don't remove volatile memory intrinsics.
+      if (auto *MI = dyn_cast<MemIntrinsic>(CB))
+        return !MI->isVolatile();
+
+      // Never remove dead lifetime intrinsics, e.g. because they are followed
+      // by a free.
+      if (CB->isLifetimeStartOrEnd())
+        return false;
+
+      return CB->use_empty() && CB->willReturn() && CB->doesNotThrow();
+    }
+
+    return false;
+  }
+
   /// Returns true if \p UseInst completely overwrites \p DefLoc
   /// (stored by \p DefInst).
   bool isCompleteOverwrite(const MemoryLocation &DefLoc, Instruction *DefInst,


        


More information about the llvm-commits mailing list