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 @@ -882,7 +882,7 @@ 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)) { // Use the precise location size specified by the 3rd argument during // for determining KillingI overwrites DeadLoc if it is a memset_chk // instruction. memset_chk will write either the amount specified as 3rd @@ -891,8 +891,16 @@ // is larger than the allocation size due to that being UB. To avoid // returning potentially invalid NoAlias results by AA, limit the use of // the precise location size to isOverwrite. - if (const auto *Len = dyn_cast(CB->getArgOperand(2))) - return LocationSize::precise(Len->getZExtValue()); + + switch (F) { + default: + break; + case LibFunc_memset_chk: + case LibFunc_memcpy_chk: + if (const auto *Len = dyn_cast(CB->getArgOperand(2))) + return LocationSize::precise(Len->getZExtValue()); + break; + } } } return Size; 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