Skip to content

Commit 2277de0

Browse files
committed
Update comments and unit tests
1 parent 11a9cd9 commit 2277de0

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,11 +2279,11 @@ DSEState::getInitializesArgMemLoc(const Instruction *I) {
22792279

22802280
Value *CurArg = CB->getArgOperand(Idx);
22812281
// We don't perform incorrect DSE on unwind edges in the current function,
2282-
// and use the "initialize" attribute to kill dead stores if :
2282+
// and use the "initializes" attribute to kill dead stores if:
22832283
// - The call does not throw exceptions, "CB->doesNotThrow()".
2284-
// - Or the argument has "dead_on_unwind" attribute.
2285-
// - Or the argument is invisble to caller on unwind, and CB isa<CallInst>
2286-
// which means no unwind edges.
2284+
// - Or the callee parameter has "dead_on_unwind" attribute.
2285+
// - Or the argument is invisible to caller on unwind, and CB isa<CallInst>
2286+
// which means no unwind edges from this call in the current function.
22872287
bool IsDeadOnUnwind =
22882288
CB->paramHasAttr(Idx, Attribute::DeadOnUnwind) ||
22892289
(isInvisibleToCallerOnUnwind(CurArg) && isa<CallInst>(CB));
@@ -2389,6 +2389,10 @@ DSEState::eliminateDeadDefs(const MemoryLocationWrapper &KillingLocWrapper) {
23892389
cast<MemoryDef>(DeadAccess),
23902390
getLocForInst(cast<MemoryDef>(DeadAccess)->getMemoryInst(),
23912391
/*ConsiderInitializesAttr=*/false));
2392+
// Note that we don't consider the initializes attribute for DeadAccess.
2393+
// The dead access would be just a regular write access, like Store
2394+
// instruction, and its MemoryDefWrapper would only contain one
2395+
// MemoryLocationWrapper.
23922396
assert(DeadDefWrapper.DefinedLocations.size() == 1);
23932397
MemoryLocationWrapper &DeadLocWrapper =
23942398
DeadDefWrapper.DefinedLocations.front();

llvm/test/Transforms/DeadStoreElimination/inter-procedural.ll

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ define i16 @p1_write_then_read_caller_with_clobber() {
5757
ret i16 %l
5858
}
5959

60+
declare void @p1_write_then_read_raw(ptr nocapture noundef initializes((0, 2)))
61+
define i16 @p1_initializes_invoke() personality ptr undef {
62+
; CHECK-LABEL: @p1_initializes_invoke(
63+
; CHECK-NEXT: entry:
64+
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
65+
; CHECK-NEXT: store i16 0, ptr [[PTR]], align 2
66+
; CHECK-NEXT: invoke void @p1_write_then_read_raw(ptr [[PTR]])
67+
; CHECK-NEXT: to label [[BB1:%.*]] unwind label [[BB2:%.*]]
68+
; CHECK: bb1:
69+
; CHECK-NEXT: ret i16 0
70+
; CHECK: bb2:
71+
; CHECK-NEXT: [[TMP:%.*]] = landingpad { ptr, i32 }
72+
; CHECK-NEXT: cleanup
73+
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
74+
; CHECK-NEXT: ret i16 [[L]]
75+
;
76+
entry:
77+
%ptr = alloca i16
78+
store i16 0, ptr %ptr
79+
invoke void @p1_write_then_read_raw(ptr %ptr) to label %bb1 unwind label %bb2
80+
bb1:
81+
ret i16 0
82+
bb2:
83+
%tmp = landingpad { ptr, i32 }
84+
cleanup
85+
%l = load i16, ptr %ptr
86+
ret i16 %l
87+
}
88+
6089
; Function Attrs: mustprogress nounwind uwtable
6190
define i16 @p2_same_range_noalias_caller() {
6291
; CHECK-LABEL: @p2_same_range_noalias_caller(
@@ -142,8 +171,8 @@ define i16 @p2_no_init_alias_caller() {
142171
; the 'dead_on_unwind' attribute, it's invisble to caller on unwind.
143172
; DSE still uses the 'initializes' attribute and kill the dead store.
144173
; Function Attrs: mustprogress nounwind uwtable
145-
define i16 @p2_no_dead_on_unwind_but_invisble_to_caller_alias_caller() {
146-
; CHECK-LABEL: @p2_no_dead_on_unwind_but_invisble_to_caller_alias_caller(
174+
define i16 @p2_no_dead_on_unwind_but_invisible_to_caller_alias_caller() {
175+
; CHECK-LABEL: @p2_no_dead_on_unwind_but_invisible_to_caller_alias_caller(
147176
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
148177
; CHECK-NEXT: call void @p2_no_dead_on_unwind(ptr [[PTR]], ptr [[PTR]])
149178
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2

0 commit comments

Comments
 (0)