Skip to content

Commit 5e63574

Browse files
committed
Merge pull request #2303 from eeckstein/deadobj-fix
DeadObjectElimination: use the debug location of the array store instead of the (unknown) instruction of the lifetime frontier.
2 parents 5d315ae + 3945539 commit 5e63574

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ static void insertReleases(ArrayRef<StoreInst*> Stores,
549549
for (auto *Store : Stores)
550550
SSAUp.AddAvailableValue(Store->getParent(), Store->getSrc());
551551

552+
SILLocation Loc = Stores[0]->getLoc();
552553
for (auto *RelPoint : ReleasePoints) {
553554
SILBuilder B(RelPoint);
554555
// This does not use the SSAUpdater::RewriteUse API because it does not do
@@ -557,9 +558,9 @@ static void insertReleases(ArrayRef<StoreInst*> Stores,
557558
// can simply ask SSAUpdater for the reaching store.
558559
SILValue RelVal = SSAUp.GetValueAtEndOfBlock(RelPoint->getParent());
559560
if (StVal->getType().isReferenceCounted(RelPoint->getModule()))
560-
B.createStrongRelease(RelPoint->getLoc(), RelVal, Atomicity::Atomic);
561+
B.createStrongRelease(Loc, RelVal, Atomicity::Atomic);
561562
else
562-
B.createReleaseValue(RelPoint->getLoc(), RelVal, Atomicity::Atomic);
563+
B.createReleaseValue(Loc, RelVal, Atomicity::Atomic);
563564
}
564565
}
565566

test/SILOptimizer/dead_array_elim.sil

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ sil [_semantics "array.uninitialized"] @allocArray : $@convention(thin) <τ_0_0>
2525
// CHECK-LABEL: sil @deadarray
2626
// CHECK-NOT: apply
2727
// CHECK-NOT: store
28-
// CHECK: strong_retain
29-
// CHECK-NEXT: strong_release
30-
// CHECK-NEXT: strong_release
31-
// CHECK-NEXT: tuple ()
32-
// CHECK-NEXT: return
3328
sil @deadarray : $@convention(thin) (@owned TrivialDestructor) -> () {
3429
bb0(%0 : $TrivialDestructor):
30+
// CHECK: strong_retain %0 : $TrivialDestructor
3531
%2 = integer_literal $Builtin.Word, 2
3632
// function_ref Swift._allocateUninitializedArray <A> (Builtin.Word) -> (Swift.Array<A>, Builtin.RawPointer)
3733
%3 = function_ref @allocArray : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
3834
%4 = apply %3<TrivialDestructor>(%2) : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
3935
%5 = tuple_extract %4 : $(Array<TrivialDestructor>, Builtin.RawPointer), 0
4036
%6 = tuple_extract %4 : $(Array<TrivialDestructor>, Builtin.RawPointer), 1
4137
%7 = pointer_to_address %6 : $Builtin.RawPointer to $*TrivialDestructor
38+
// CHECK-NEXT: strong_release %0 : $TrivialDestructor, loc "{{.*}}":[[@LINE+1]]:3
4239
store %0 to %7 : $*TrivialDestructor
4340
%9 = integer_literal $Builtin.Word, 1
4441
%10 = index_addr %7 : $*TrivialDestructor, %9 : $Builtin.Word
42+
// CHECK-NEXT: strong_release %0 : $TrivialDestructor, loc "{{.*}}":[[@LINE+1]]:3
4543
store %0 to %10 : $*TrivialDestructor
4644
%13 = struct_extract %5 : $Array<TrivialDestructor>, #Array._buffer
4745
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
4846
%15 = struct_extract %14 : $_BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCore>, #_BridgeStorage.rawValue
4947
strong_retain %0 : $TrivialDestructor
5048
strong_release %15 : $Builtin.BridgeObject
49+
// CHECK-NEXT: tuple ()
5150
%18 = tuple ()
51+
// CHECK-NEXT: return
5252
return %18 : $()
5353
}
5454

0 commit comments

Comments
 (0)