[llvm] [MemCpyOpt] Continue merging memset with unrelated clobber (PR #89550)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 21:53:58 PDT 2024


================
@@ -386,19 +389,26 @@ Instruction *MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst,
         continue;
     }
 
-    if (!isa<StoreInst>(BI) && !isa<MemSetInst>(BI)) {
-      // If the instruction is readnone, ignore it, otherwise bail out.  We
-      // don't even allow readonly here because we don't want something like:
-      // A[1] = 2; strlen(A); A[2] = 2; -> memcpy(A, ...); strlen(A).
-      if (BI->mayWriteToMemory() || BI->mayReadFromMemory())
+    if (BI->isVolatile() || BI->isAtomic())
+      break;
+
+    // If the instruction reads something, bail out.  We
+    // don't even allow readonly here because we don't want something like:
+    // A[1] = 2; strlen(A); A[2] = 2; -> memcpy(A, ...); strlen(A).
+    if (BI->mayReadFromMemory())
+      break;
----------------
XChy wrote:

I somehow thought that skipping non-aliasing reads would impact the value being read. I'll add test coverage for it.

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


More information about the llvm-commits mailing list