[llvm] [GVN] Drop Clobber dependency if store may overwrite only the same value (PR #68322)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 02:31:09 PDT 2023


================
@@ -360,11 +360,42 @@ MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI,
   return MemDepResult::getNonLocal();
 }
 
+// canSkipClobberingStore - check if SI that may alias with MemLoc can be safely
+// skipped. This is possible in case if SI can only must alias or no alias with
+// MemLoc (no partial overlapping possible) and it writes the same value that
+// MemLoc contains now (it was loaded before this store and was not modified in
+// between).
+static bool canSkipClobberingStore(const StoreInst *SI,
+                                   const MemoryLocation &MemLoc,
+                                   Align MemLocAlign, BatchAAResults &BatchAA) {
+  if (!MemLoc.Size.hasValue())
+    return false;
+  if (MemoryLocation::get(SI).Size != MemLoc.Size)
+    return false;
+  if (MemLocAlign.value() < MemLoc.Size.getValue())
+    return false;
+  if (SI->getAlign() < MemLocAlign)
+    return false;
----------------
nikic wrote:

I think the right check here is `std::min(MemLocAlign, SI->getAlign()) >= MemLoc.Size`? We don't care about relation between load and store align as long as both are >= the size, which ensures no partial writes.

https://github.com/llvm/llvm-project/pull/68322


More information about the llvm-commits mailing list