[PATCH] D88778: [MemCpyOpt] Fix MemorySSA preservation
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 13:54:37 PDT 2020
nikic updated this revision to Diff 296288.
nikic added a comment.
Be more conservative when fetching the MemoryDef for P.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88778/new/
https://reviews.llvm.org/D88778
Files:
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
Index: llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
===================================================================
--- llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
+++ llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
@@ -148,6 +148,21 @@
ret void
}
+define void @test8(%t* noalias %src, %t* %dst) {
+; CHECK-LABEL: @test8(
+; CHECK-NEXT: [[TMP1:%.*]] = bitcast %t* [[SRC:%.*]] to i8*
+; CHECK-NEXT: [[TMP2:%.*]] = bitcast %t* [[DST:%.*]] to i8*
+; CHECK-NEXT: [[TMP3:%.*]] = bitcast %t* [[SRC]] to i8*
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[TMP2]], i8* align 1 [[TMP3]], i64 8224, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[TMP1]], i8 0, i64 8224, i1 false)
+; CHECK-NEXT: ret void
+;
+ %1 = load %t, %t* %src
+ store %t zeroinitializer, %t* %src
+ store %t %1, %t* %dst
+ ret void
+}
+
declare void @clobber()
; Function Attrs: argmemonly nounwind willreturn
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -476,7 +476,7 @@
Args.insert(Ptr);
// Instruction to lift before P.
- SmallVector<Instruction*, 8> ToLift;
+ SmallVector<Instruction *, 8> ToLift{SI};
// Memory locations of lifted instructions.
SmallVector<MemoryLocation, 8> MemLocs{StoreLoc};
@@ -542,10 +542,18 @@
}
}
- // We made it, we need to lift
+ // We made it, we need to lift.
+ MemoryDef *PDef =
+ MSSAU ? dyn_cast_or_null<MemoryDef>(
+ MSSAU->getMemorySSA()->getMemoryAccess(P))
+ : nullptr;
for (auto *I : llvm::reverse(ToLift)) {
LLVM_DEBUG(dbgs() << "Lifting " << *I << " before " << *P << "\n");
I->moveBefore(P);
+ if (PDef) {
+ if (MemoryUseOrDef *MA = MSSAU->getMemorySSA()->getMemoryAccess(I))
+ MSSAU->moveBefore(MA, PDef);
+ }
}
return true;
@@ -629,9 +637,8 @@
<< *M << "\n");
if (MSSAU) {
- assert(isa<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(P)));
auto *LastDef =
- cast<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(P));
+ cast<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(SI));
auto *NewAccess =
MSSAU->createMemoryAccessAfter(M, LastDef, LastDef);
MSSAU->insertDef(cast<MemoryDef>(NewAccess), /*RenameUses=*/true);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88778.296288.patch
Type: text/x-patch
Size: 2550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201005/9acc95cc/attachment.bin>
More information about the llvm-commits
mailing list