[llvm] 6bc5e86 - [MemCpyOpt] Account for case that MemInsertPoint == BI.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 06:04:22 PDT 2020
Author: Florian Hahn
Date: 2020-09-04T14:04:08+01:00
New Revision: 6bc5e866bdba03fdd2d92bd72f3fce9c2973bf1f
URL: https://github.com/llvm/llvm-project/commit/6bc5e866bdba03fdd2d92bd72f3fce9c2973bf1f
DIFF: https://github.com/llvm/llvm-project/commit/6bc5e866bdba03fdd2d92bd72f3fce9c2973bf1f.diff
LOG: [MemCpyOpt] Account for case that MemInsertPoint == BI.
In that case, the new MemoryDef needs to be inserted *before*
MemInsertPoint.
Added:
Modified:
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index aff08a2c366c..9011e36619d9 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -423,8 +423,12 @@ Instruction *MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst,
if (MSSAU) {
assert(LastMemDef && MemInsertPoint &&
"Both LastMemDef and MemInsertPoint need to be set");
- auto *NewDef = cast<MemoryDef>(
- MSSAU->createMemoryAccessAfter(AMemSet, LastMemDef, MemInsertPoint));
+ auto *NewDef =
+ cast<MemoryDef>(MemInsertPoint->getMemoryInst() == &*BI
+ ? MSSAU->createMemoryAccessBefore(
+ AMemSet, LastMemDef, MemInsertPoint)
+ : MSSAU->createMemoryAccessAfter(
+ AMemSet, LastMemDef, MemInsertPoint));
MSSAU->insertDef(NewDef, /*RenameUses=*/true);
LastMemDef = NewDef;
MemInsertPoint = NewDef;
diff --git a/llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll b/llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
index 4e449ed5ff4f..f3c54579d9d0 100644
--- a/llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
+++ b/llvm/test/Transforms/MemCpyOpt/preserve-memssa.ll
@@ -123,6 +123,33 @@ entry:
ret i8 %0
}
+define void @test7([4 x i32]* %ptr) {
+; CHECK-LABEL: @test7(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR:%.*]], i64 0, i32 0
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR]], i64 0, i32 1
+; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR]], i64 0, i32 2
+; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[PTR]], i64 0, i32 3
+; CHECK-NEXT: [[TMP4:%.*]] = bitcast i32* [[TMP0]] to i8*
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[TMP4]], i8 0, i64 16, i1 false)
+; CHECK-NEXT: call void @clobber()
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 0
+ store i32 0, i32* %0, align 1
+ %1 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 1
+ store i32 0, i32* %1, align 1
+ %2 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 2
+ store i32 0, i32* %2, align 1
+ %3 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 0, i32 3
+ store i32 0, i32* %3, align 1
+ call void @clobber()
+ ret void
+}
+
+declare void @clobber()
+
; Function Attrs: argmemonly nounwind willreturn
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
More information about the llvm-commits
mailing list