Skip to content

Commit 7f26004

Browse files
authored
Merge pull request #26950 from gottesmm/pr-58d8dce3519c33f66b6246c0c796e87e6e817744
2 parents 5085e45 + dbf84f3 commit 7f26004

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ struct SemanticARCOptVisitor
186186
bool visitCopyValueInst(CopyValueInst *cvi);
187187
bool visitBeginBorrowInst(BeginBorrowInst *bbi);
188188
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);
191193

192194
bool processWorklist();
193195

@@ -713,7 +715,7 @@ class StorageGuaranteesLoadVisitor
713715
};
714716
} // namespace
715717

716-
bool SemanticARCOptVisitor::isWrittenTo(LoadInst *load) {
718+
bool SemanticARCOptVisitor::isLoadGuaranteedByStorage(LoadInst *load) {
717719
StorageGuaranteesLoadVisitor visitor(*this, load);
718720
return visitor.doIt();
719721
}
@@ -735,9 +737,10 @@ bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
735737
if (isConsumed(li, destroyValues))
736738
return false;
737739

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))
741744
return false;
742745

743746
// Ok, we can perform our optimization. Convert the load [copy] into a

0 commit comments

Comments
 (0)