[llvm] [MemCpyOpt] Continue merging memset with unrelated clobber (PR #89550)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 17:55:51 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;
----------------
nikic wrote:
Wouldn't we want to skip non-aliasing reads as well?
https://github.com/llvm/llvm-project/pull/89550
More information about the llvm-commits
mailing list