Skip to content

Commit 8287d2e

Browse files
committed
[SemanticARC] NFC: Extracted opt from visit.
In preparation to attempt two variations of the optimization, added performLoadCopyToLoadBorrowOptimization and call it from visitLoadInst.
1 parent b686e81 commit 8287d2e

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/SILOptimizer/SemanticARC/LoadCopyToLoadBorrowOpt.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ static bool isWrittenTo(Context &ctx, LoadInst *load,
319319
// Top Level Entrypoint
320320
//===----------------------------------------------------------------------===//
321321

322-
// Convert a load [copy] from unique storage [read] that has all uses that can
323-
// accept a guaranteed parameter to a load_borrow.
324322
bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
325323
// This optimization can use more complex analysis. We should do some
326324
// experiments before enabling this by default as a guaranteed optimization.
@@ -334,9 +332,19 @@ bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
334332
if (li->getOwnershipQualifier() != LoadOwnershipQualifier::Copy)
335333
return false;
336334

337-
// Ok, we have our load [copy]. Make sure its value is truly a dead live range
338-
// implying it is only ever consumed by destroy_value instructions. If it is
339-
// consumed, we need to pass off a +1 value, so bail.
335+
// Ok, we have our load [copy]. Try to optimize.
336+
return performLoadCopyToLoadBorrowOptimization(li);
337+
}
338+
339+
// Convert a load [copy] from unique storage [read] that has all uses that can
340+
// accept a guaranteed parameter to a load_borrow.
341+
bool SemanticARCOptVisitor::performLoadCopyToLoadBorrowOptimization(
342+
LoadInst *li) {
343+
assert(li->getOwnershipQualifier() == LoadOwnershipQualifier::Copy);
344+
345+
// Make sure its value is truly a dead live range implying it is only ever
346+
// consumed by destroy_value instructions. If it is consumed, we need to pass
347+
// off a +1 value, so bail.
340348
//
341349
// FIXME: We should consider if it is worth promoting a load [copy]
342350
// -> load_borrow if we can put a copy_value on a cold path and thus
@@ -355,8 +363,8 @@ bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
355363
// load_borrow.
356364
auto *lbi =
357365
SILBuilderWithScope(li).createLoadBorrow(li->getLoc(), li->getOperand());
358-
359366
lr.insertEndBorrowsAtDestroys(lbi, getDeadEndBlocks(), ctx.lifetimeFrontier);
360-
std::move(lr).convertToGuaranteedAndRAUW(lbi, getCallbacks());
367+
SILValue replacement = lbi;
368+
std::move(lr).convertToGuaranteedAndRAUW(replacement, getCallbacks());
361369
return true;
362370
}

lib/SILOptimizer/SemanticARC/SemanticARCOptVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor
202202
bool optimize();
203203
bool optimizeWithoutFixedPoint();
204204

205+
bool performLoadCopyToLoadBorrowOptimization(LoadInst *li);
205206
bool performGuaranteedCopyValueOptimization(CopyValueInst *cvi);
206207
bool eliminateDeadLiveRangeCopyValue(CopyValueInst *cvi);
207208
bool tryJoiningCopyValueLiveRangeWithOperand(CopyValueInst *cvi);

0 commit comments

Comments
 (0)