@@ -186,8 +186,10 @@ struct SemanticARCOptVisitor
186
186
bool visitCopyValueInst (CopyValueInst *cvi);
187
187
bool visitBeginBorrowInst (BeginBorrowInst *bbi);
188
188
bool visitLoadInst (LoadInst *li);
189
-
190
- bool isWrittenTo (LoadInst *li);
189
+
190
+ // / Return true if all of load insts destroy_value users are within the
191
+ // / guaranteed lifetime of the storage that is being loaded from.
192
+ bool isLoadGuaranteedByStorage (LoadInst *li);
191
193
192
194
bool processWorklist ();
193
195
@@ -713,7 +715,7 @@ class StorageGuaranteesLoadVisitor
713
715
};
714
716
} // namespace
715
717
716
- bool SemanticARCOptVisitor::isWrittenTo (LoadInst *load) {
718
+ bool SemanticARCOptVisitor::isLoadGuaranteedByStorage (LoadInst *load) {
717
719
StorageGuaranteesLoadVisitor visitor (*this , load);
718
720
return visitor.doIt ();
719
721
}
@@ -735,9 +737,10 @@ bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
735
737
if (isConsumed (li, destroyValues))
736
738
return false ;
737
739
738
- // Then check if our address is ever written to. If it is, then we
739
- // can not use the load_borrow.
740
- if (isWrittenTo (li))
740
+ // Then check if our address is guaranteed to never be written to within the
741
+ // lifetime of our loaded value. If so, we can convert the loaded value to be
742
+ // at +0 instead of +1.
743
+ if (isLoadGuaranteedByStorage (li))
741
744
return false ;
742
745
743
746
// Ok, we can perform our optimization. Convert the load [copy] into a
0 commit comments