Skip to content

Commit 1e5f3bd

Browse files
committed
TempRValueOpt: only do the check for "unusual" temp object destruction in non-OSSA mode.
In OSSA, memory locations are always destroyed in a "visible" way, e.g. with destroy_addr or load [take].
1 parent 262c7b2 commit 1e5f3bd

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/SILOptimizer/Transforms/TempRValueElimination.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ class TempRValueOptPass : public SILFunctionTransform {
8585
CopyAddrInst *copyInst, const SmallPtrSetImpl<SILInstruction *> &useInsts);
8686

8787
bool
88-
checkTempObjectDestroy(AllocStackInst *tempObj, CopyAddrInst *copyInst,
89-
ValueLifetimeAnalysis::Frontier &tempAddressFrontier);
88+
checkTempObjectDestroy(AllocStackInst *tempObj, CopyAddrInst *copyInst);
9089

9190
bool tryOptimizeCopyIntoTemp(CopyAddrInst *copyInst);
9291
std::pair<SILBasicBlock::iterator, bool>
@@ -357,8 +356,7 @@ SILInstruction *TempRValueOptPass::getLastUseWhileSourceIsNotModified(
357356
/// releasing it. Rather than detecting unbalanced load releases, simply check
358357
/// that tempObj is destroyed directly on all paths.
359358
bool TempRValueOptPass::checkTempObjectDestroy(
360-
AllocStackInst *tempObj, CopyAddrInst *copyInst,
361-
ValueLifetimeAnalysis::Frontier &tempAddressFrontier) {
359+
AllocStackInst *tempObj, CopyAddrInst *copyInst) {
362360
// ValueLifetimeAnalysis is not normally used for address types. It does not
363361
// reason about the lifetime of the in-memory object. However the utility can
364362
// be abused here to check that the address is directly destroyed on all
@@ -377,6 +375,7 @@ bool TempRValueOptPass::checkTempObjectDestroy(
377375
}
378376
// Find the boundary of tempObj's address lifetime, starting at copyInst.
379377
ValueLifetimeAnalysis vla(copyInst, users);
378+
ValueLifetimeAnalysis::Frontier tempAddressFrontier;
380379
if (!vla.computeFrontier(tempAddressFrontier,
381380
ValueLifetimeAnalysis::DontModifyCFG)) {
382381
return false;
@@ -483,8 +482,7 @@ bool TempRValueOptPass::tryOptimizeCopyIntoTemp(CopyAddrInst *copyInst) {
483482
aa->mayWriteToMemory(lastLoadInst, copySrc))
484483
return false;
485484

486-
ValueLifetimeAnalysis::Frontier tempAddressFrontier;
487-
if (!checkTempObjectDestroy(tempObj, copyInst, tempAddressFrontier))
485+
if (!isOSSA && !checkTempObjectDestroy(tempObj, copyInst))
488486
return false;
489487

490488
LLVM_DEBUG(llvm::dbgs() << " Success: replace temp" << *tempObj);

0 commit comments

Comments
 (0)