Skip to content

Commit 3687ddf

Browse files
Merge pull request swiftlang#68090 from nate-chandler/rdar114323803
[CopyPropagation] Don't try to delete owned values on which canonicalization bails.
2 parents 89ef8cd + a67c22d commit 3687ddf

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ void CopyPropagation::run() {
617617
// Canonicalize all owned defs.
618618
while (!defWorklist.ownedValues.empty()) {
619619
SILValue def = defWorklist.ownedValues.pop_back_val();
620-
canonicalizer.canonicalizeValueLifetime(def);
620+
auto canonicalized = canonicalizer.canonicalizeValueLifetime(def);
621+
if (!canonicalized)
622+
continue;
621623
// Copies of borrowed values may be dead.
622624
if (auto *inst = def->getDefiningInstruction())
623625
deleter.trackIfDead(inst);

test/SILOptimizer/copy_propagation.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class C {
1616
var a: Builtin.Int64
1717
}
1818

19+
struct MOS : ~Copyable {
20+
deinit {}
21+
}
22+
1923
sil [ossa] @dummy : $@convention(thin) () -> ()
2024
sil [ossa] @barrier : $@convention(thin) () -> ()
2125
sil [ossa] @getOwnedC : $@convention(thin) () -> (@owned C)
@@ -26,6 +30,7 @@ sil [ossa] @takeOwnedCAndGuaranteedC : $@convention(thin) (@owned C, @guaranteed
2630
sil [ossa] @takeGuaranteedC : $@convention(thin) (@guaranteed C) -> ()
2731
sil [ossa] @borrowB : $@convention(thin) (@guaranteed B) -> ()
2832
sil [ossa] @takeGuaranteedAnyObject : $@convention(thin) (@guaranteed AnyObject) -> ()
33+
sil [ossa] @getMOS : $() -> (@owned MOS)
2934

3035
// -O hoists the destroy
3136
//
@@ -1047,3 +1052,23 @@ entry(%instance : @owned $C):
10471052
%retval = tuple ()
10481053
return %retval : $()
10491054
}
1055+
1056+
// CHECK-LABEL: sil [ossa] @dontShortenDeadMoveOnlyLifetime : {{.*}} {
1057+
// CHECK: [[GET:%[^,]+]] = function_ref @getMOS
1058+
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
1059+
// CHECK: [[MOS:%[^,]+]] = apply [[GET]]()
1060+
// CHECK: [[MOV:%[^,]+]] = move_value [lexical] [[MOS]]
1061+
// CHECK: apply [[BARRIER]]()
1062+
// CHECK: destroy_value [[MOV]]
1063+
// CHECK-LABEL: } // end sil function 'dontShortenDeadMoveOnlyLifetime'
1064+
sil [ossa] @dontShortenDeadMoveOnlyLifetime : $@convention(thin) () -> () {
1065+
%get = function_ref @getMOS : $@convention(thin) () -> (@owned MOS)
1066+
%barrier = function_ref @barrier : $@convention(thin) () -> ()
1067+
%mos = apply %get() : $@convention(thin) () -> (@owned MOS)
1068+
// Note: This must be lexical so that it doesn't get eliminated as redundant.
1069+
%mov = move_value [lexical] %mos : $MOS
1070+
apply %barrier() : $@convention(thin) () -> ()
1071+
destroy_value %mov : $MOS
1072+
%retval = tuple ()
1073+
return %retval : $()
1074+
}

0 commit comments

Comments
 (0)