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 @@ -883,7 +883,8 @@ LocationSize Size) const { if (auto *CB = dyn_cast(I)) { LibFunc F; - if (TLI.getLibFunc(*CB, F) && TLI.has(F) && F == LibFunc_memset_chk) { + if (TLI.getLibFunc(*CB, F) && TLI.has(F) && + (F == LibFunc_memset_chk || F == LibFunc_memcpy_chk)) { // Use the precise location size specified by the 3rd argument // for determining KillingI overwrites DeadLoc if it is a memset_chk // instruction. memset_chk will write either the amount specified as 3rd diff --git a/llvm/test/Transforms/DeadStoreElimination/libcalls-chk.ll b/llvm/test/Transforms/DeadStoreElimination/libcalls-chk.ll --- a/llvm/test/Transforms/DeadStoreElimination/libcalls-chk.ll +++ b/llvm/test/Transforms/DeadStoreElimination/libcalls-chk.ll @@ -107,8 +107,7 @@ define void @dse_strncpy_memcpy_chk_test1(ptr noalias %out, ptr noalias %in, i64 %n) { ; CHECK-LABEL: @dse_strncpy_memcpy_chk_test1( -; CHECK-NEXT: store i32 0, ptr [[OUT:%.*]], align 4 -; CHECK-NEXT: [[CALL_1:%.*]] = tail call ptr @__memcpy_chk(ptr [[OUT]], ptr [[IN:%.*]], i64 100, i64 [[N:%.*]]) +; CHECK-NEXT: [[CALL_1:%.*]] = tail call ptr @__memcpy_chk(ptr [[OUT:%.*]], ptr [[IN:%.*]], i64 100, i64 [[N:%.*]]) ; CHECK-NEXT: ret void ; store i32 0, ptr %out