Skip to content

Commit 243ffbd

Browse files
authored
[DSE] Check write location in IsRedundantStore (llvm#93400)
Fix llvm#93298.
1 parent f31b197 commit 243ffbd

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,10 +2109,12 @@ struct DSEState {
21092109
if (auto *MemSetI = dyn_cast<MemSetInst>(UpperInst)) {
21102110
if (auto *SI = dyn_cast<StoreInst>(DefInst)) {
21112111
// MemSetInst must have a write location.
2112-
MemoryLocation UpperLoc = *getLocForWrite(UpperInst);
2112+
auto UpperLoc = getLocForWrite(UpperInst);
2113+
if (!UpperLoc)
2114+
return false;
21132115
int64_t InstWriteOffset = 0;
21142116
int64_t DepWriteOffset = 0;
2115-
auto OR = isOverwrite(UpperInst, DefInst, UpperLoc, *MaybeDefLoc,
2117+
auto OR = isOverwrite(UpperInst, DefInst, *UpperLoc, *MaybeDefLoc,
21162118
InstWriteOffset, DepWriteOffset);
21172119
Value *StoredByte = isBytewiseValue(SI->getValueOperand(), DL);
21182120
return StoredByte && StoredByte == MemSetI->getOperand(1) &&

llvm/test/Transforms/DeadStoreElimination/simple.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,16 @@ define i32 @test48(ptr %P, ptr noalias %Q, ptr %R) {
790790
%l = load i32, ptr %R
791791
ret i32 %l
792792
}
793+
794+
define void @test49() {
795+
; CHECK-LABEL: @test49(
796+
; CHECK-NEXT: bb:
797+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr readonly null, i8 0, i64 0, i1 false)
798+
; CHECK-NEXT: store ptr null, ptr null, align 8
799+
; CHECK-NEXT: ret void
800+
;
801+
bb:
802+
call void @llvm.memset.p0.i64(ptr readonly null, i8 0, i64 0, i1 false)
803+
store ptr null, ptr null, align 8
804+
ret void
805+
}

0 commit comments

Comments
 (0)