File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -559,6 +559,9 @@ void CopyPropagation::run() {
559
559
while (!defWorklist.ownedValues .empty ()) {
560
560
SILValue def = defWorklist.ownedValues .pop_back_val ();
561
561
canonicalizer.canonicalizeValueLifetime (def);
562
+ // Copies of borrowed values may be dead.
563
+ if (auto *inst = def->getDefiningInstruction ())
564
+ deleter.trackIfDead (inst);
562
565
}
563
566
// Recursively cleanup dead defs after removing uses.
564
567
deleter.cleanupDeadInstructions ();
Original file line number Diff line number Diff line change @@ -701,6 +701,10 @@ bb1:
701
701
destroy_value %copy : $AnyObject
702
702
%obj = load [copy] %access : $*AnyObject
703
703
end_access %access : $*AnyObject
704
+ // Use %obj so it doesn't get deleted because it's unused a trigger a cascade
705
+ // of deletions.
706
+ %f2 = function_ref @takeGuaranteedAnyObject : $@convention(thin) (@guaranteed AnyObject) -> ()
707
+ apply %f2(%obj) : $@convention(thin) (@guaranteed AnyObject) -> ()
704
708
destroy_value %obj : $AnyObject
705
709
destroy_value %box : ${ var AnyObject }
706
710
%v = tuple ()
@@ -876,3 +880,24 @@ entry(%instance : @owned $C):
876
880
%retval = tuple ()
877
881
return %retval : $()
878
882
}
883
+
884
+ // Verify that a dead copy_value is deleted.
885
+ // CHECK-LABEL: sil [ossa] @delete_dead_reborrow_copy : {{.*}} {
886
+ // CHECK-NOT: copy_value
887
+ // CHECK-LABEL: } // end sil function 'delete_dead_reborrow_copy'
888
+ sil [ossa] @delete_dead_reborrow_copy : $@convention(thin) (@owned X) -> () {
889
+ bb0(%instance : @owned $X):
890
+ %lifetime = begin_borrow %instance : $X
891
+ br bb1(%lifetime : $X)
892
+
893
+ bb1(%reborrow : @guaranteed $X):
894
+ %dead_copy = copy_value %reborrow : $X
895
+ end_borrow %reborrow : $X
896
+ destroy_value %dead_copy : $X
897
+ br exit
898
+
899
+ exit:
900
+ destroy_value %instance : $X
901
+ %retval = tuple ()
902
+ return %retval : $()
903
+ }
You can’t perform that action at this time.
0 commit comments