Skip to content

Commit 76968be

Browse files
committed
[DSE] Use precise loc for memcpy_chk during overwrite checks.
Extends the logic from D115167 to memcpy_chk. Depends on D115167 Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D139096
1 parent ac12e6a commit 76968be

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,8 @@ struct DSEState {
838838
LocationSize Size) const {
839839
if (auto *CB = dyn_cast<CallBase>(I)) {
840840
LibFunc F;
841-
if (TLI.getLibFunc(*CB, F) && TLI.has(F) && F == LibFunc_memset_chk) {
841+
if (TLI.getLibFunc(*CB, F) && TLI.has(F) &&
842+
(F == LibFunc_memset_chk || F == LibFunc_memcpy_chk)) {
842843
// Use the precise location size specified by the 3rd argument
843844
// for determining KillingI overwrites DeadLoc if it is a memset_chk
844845
// instruction. memset_chk will write either the amount specified as 3rd

llvm/test/Transforms/DeadStoreElimination/libcalls-chk.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ define void @dse_strncpy_chk_test3(ptr noalias %out1, ptr noalias %out2, ptr noa
107107

108108
define void @dse_strncpy_memcpy_chk_test1(ptr noalias %out, ptr noalias %in, i64 %n) {
109109
; CHECK-LABEL: @dse_strncpy_memcpy_chk_test1(
110-
; CHECK-NEXT: store i32 0, ptr [[OUT:%.*]], align 4
111-
; CHECK-NEXT: [[CALL_1:%.*]] = tail call ptr @__memcpy_chk(ptr [[OUT]], ptr [[IN:%.*]], i64 100, i64 [[N:%.*]])
110+
; CHECK-NEXT: [[CALL_1:%.*]] = tail call ptr @__memcpy_chk(ptr [[OUT:%.*]], ptr [[IN:%.*]], i64 100, i64 [[N:%.*]])
112111
; CHECK-NEXT: ret void
113112
;
114113
store i32 0, ptr %out

0 commit comments

Comments
 (0)