[DSE] Improve handling of strncpy in Dead Store Elimination
Fixes PR#52062 and one of the remaining cases of PR#47644. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D114035
This commit is contained in:
committed by
Florian Hahn
parent
d5de568cc7
commit
7eec832def
@@ -1059,8 +1059,13 @@ struct DSEState {
|
||||
LibFunc LF;
|
||||
if (TLI.getLibFunc(*CB, LF) && TLI.has(LF)) {
|
||||
switch (LF) {
|
||||
case LibFunc_strcpy:
|
||||
case LibFunc_strncpy:
|
||||
if (const auto *Len = dyn_cast<ConstantInt>(CB->getArgOperand(2)))
|
||||
return MemoryLocation(CB->getArgOperand(0),
|
||||
LocationSize::precise(Len->getZExtValue()),
|
||||
CB->getAAMetadata());
|
||||
LLVM_FALLTHROUGH;
|
||||
case LibFunc_strcpy:
|
||||
case LibFunc_strcat:
|
||||
case LibFunc_strncat:
|
||||
return {MemoryLocation::getAfter(CB->getArgOperand(0))};
|
||||
|
||||
@@ -435,8 +435,7 @@ declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
|
||||
; strncpy -> memset, full overwrite
|
||||
define void @dse_strncpy_test1(i8* noalias %out, i8* noalias %in) {
|
||||
; CHECK-LABEL: @dse_strncpy_test1(
|
||||
; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @strncpy(i8* [[OUT:%.*]], i8* [[IN:%.*]], i64 100)
|
||||
; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* [[OUT]], i8 42, i64 100, i1 false)
|
||||
; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* [[OUT:%.*]], i8 42, i64 100, i1 false)
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
%call = tail call i8* @strncpy(i8* %out, i8* %in, i64 100)
|
||||
@@ -472,8 +471,7 @@ define void @dse_strncpy_test3(i8* noalias %out1, i8* noalias %out2, i8* noalias
|
||||
; memset -> strncpy, full overwrite
|
||||
define void @dse_strncpy_test4(i8* noalias %out, i8* noalias %in) {
|
||||
; CHECK-LABEL: @dse_strncpy_test4(
|
||||
; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* [[OUT:%.*]], i8 42, i64 100, i1 false)
|
||||
; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @strncpy(i8* [[OUT]], i8* [[IN:%.*]], i64 100)
|
||||
; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @strncpy(i8* [[OUT:%.*]], i8* [[IN:%.*]], i64 100)
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
tail call void @llvm.memset.p0i8.i64(i8* %out, i8 42, i64 100, i1 false)
|
||||
@@ -484,7 +482,8 @@ define void @dse_strncpy_test4(i8* noalias %out, i8* noalias %in) {
|
||||
; memset -> strncpy, partial overwrite
|
||||
define void @dse_strncpy_test5(i8* noalias %out, i8* noalias %in) {
|
||||
; CHECK-LABEL: @dse_strncpy_test5(
|
||||
; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* [[OUT:%.*]], i8 42, i64 100, i1 false)
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[OUT:%.*]], i64 99
|
||||
; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* align 1 [[TMP1]], i8 42, i64 1, i1 false)
|
||||
; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @strncpy(i8* [[OUT]], i8* [[IN:%.*]], i64 99)
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user