diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1786,14 +1786,11 @@ auto *CB = cast(DefUO); auto *InitC = getInitialValueOfAllocation(CB, &TLI, StoredConstant->getType()); - if (InitC && InitC == StoredConstant) { - auto *UnderlyingDef = cast(MSSA.getMemoryAccess(CB)); - // If UnderlyingDef is the clobbering access of Def, no instructions - // between them can modify the memory location. - auto *ClobberDef = - MSSA.getSkipSelfWalker()->getClobberingMemoryAccess(Def); - return UnderlyingDef == ClobberDef; - } + // If the clobbering access is LiveOnEntry, no instructions between them + // can modify the memory location. + if (InitC && InitC == StoredConstant) + return MSSA.isLiveOnEntryDef( + MSSA.getSkipSelfWalker()->getClobberingMemoryAccess(Def)); } if (!Store) diff --git a/llvm/test/Transforms/DeadStoreElimination/calloc-store.ll b/llvm/test/Transforms/DeadStoreElimination/calloc-store.ll --- a/llvm/test/Transforms/DeadStoreElimination/calloc-store.ll +++ b/llvm/test/Transforms/DeadStoreElimination/calloc-store.ll @@ -1,6 +1,6 @@ ; RUN: opt < %s -basic-aa -dse -S | FileCheck %s -declare noalias i8* @calloc(i64, i64) +declare noalias i8* @calloc(i64, i64) inaccessiblememonly define i32* @test1() { ; CHECK-LABEL: test1 diff --git a/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll b/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll --- a/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll +++ b/llvm/test/Transforms/DeadStoreElimination/noop-stores.ll @@ -378,7 +378,7 @@ } ; This should not create recursive call to calloc. -define i8* @calloc(i64 %nmemb, i64 %size) { +define i8* @calloc(i64 %nmemb, i64 %size) inaccessiblememonly { ; CHECK-LABEL: @calloc( ; CHECK: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul i64 [[SIZE:%.*]], [[NMEMB:%.*]] @@ -488,7 +488,6 @@ define i8* @store_zero_after_calloc_inaccessiblememonly() { ; CHECK-LABEL: @store_zero_after_calloc_inaccessiblememonly( ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 1, i64 10) #[[ATTR6:[0-9]+]] -; CHECK-NEXT: store i8 0, i8* [[CALL]], align 1 ; CHECK-NEXT: ret i8* [[CALL]] ; %call = tail call i8* @calloc(i64 1, i64 10) inaccessiblememonly @@ -582,7 +581,6 @@ define i8* @zero_memset_after_calloc_inaccessiblememonly() { ; CHECK-LABEL: @zero_memset_after_calloc_inaccessiblememonly( ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4) #[[ATTR6]] -; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 40000, i1 false) ; CHECK-NEXT: ret i8* [[CALL]] ; %call = tail call i8* @calloc(i64 10000, i64 4) inaccessiblememonly diff --git a/llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll b/llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll --- a/llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll +++ b/llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll @@ -42,7 +42,7 @@ ret void } -declare noalias i8* @calloc(i64, i64) +declare noalias i8* @calloc(i64, i64) inaccessiblememonly define void @test4() { ; CHECK-LABEL: @test4