Skip to content

Commit 5136581

Browse files
committed
[inst-simplify] Fail simplification if we have ownership and are not passed a non-null deadEndBlocks.
I am trying to be more careful about this rather than letting someone make this mistake in the future. I also added some comments and a DeadEndBlocks instance to TempRValueElimination so that it gets full simplifications in OSSA.
1 parent 38e2a3b commit 5136581

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

include/swift/SILOptimizer/Analysis/SimplifyInstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ replaceAllSimplifiedUsesAndErase(SILInstruction *I, SILValue result,
4545
///
4646
/// NOTE: When OSSA is enabled this API assumes OSSA is properly formed and will
4747
/// insert compensating instructions.
48+
/// NOTE: When \p I is in an OSSA function, this fails to optimize if \p
49+
/// deadEndBlocks is null.
4850
SILBasicBlock::iterator simplifyAndReplaceAllSimplifiedUsesAndErase(
4951
SILInstruction *I, InstModCallbacks &callbacks,
5052
DeadEndBlocks *deadEndBlocks = nullptr);

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ SILBasicBlock::iterator swift::simplifyAndReplaceAllSimplifiedUsesAndErase(
793793
if (!svi->getFunction()->hasOwnership())
794794
return replaceAllUsesAndErase(svi, result, callbacks);
795795

796+
// If we weren't passed a dead end blocks, we can't optimize without ownership
797+
// enabled.
798+
if (!deadEndBlocks)
799+
return next;
800+
796801
JointPostDominanceSetComputer computer(*deadEndBlocks);
797802
OwnershipFixupContext ctx{callbacks, *deadEndBlocks, computer};
798803
OwnershipRAUWHelper helper(ctx, svi, result);

lib/SILOptimizer/Mandatory/OwnershipModelEliminator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ static bool stripOwnership(SILFunction &func) {
482482
InstModCallbacks callbacks([&](SILInstruction *instToErase) {
483483
visitor.eraseInstruction(instToErase);
484484
});
485+
// We are no longer in OSSA, so we don't need to pass in a deBlocks.
485486
simplifyAndReplaceAllSimplifiedUsesAndErase(*value, callbacks);
486487
madeChange |= callbacks.hadCallbackInvocation();
487488
}

lib/SILOptimizer/Transforms/TempRValueElimination.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
//===----------------------------------------------------------------------===//
1818

1919
#define DEBUG_TYPE "sil-temp-rvalue-opt"
20+
2021
#include "swift/SIL/DebugUtils.h"
22+
#include "swift/SIL/BasicBlockUtils.h"
2123
#include "swift/SIL/MemAccessUtils.h"
2224
#include "swift/SIL/SILArgument.h"
2325
#include "swift/SIL/SILBuilder.h"
@@ -749,14 +751,15 @@ void TempRValueOptPass::run() {
749751
#endif
750752
};
751753

754+
DeadEndBlocks deBlocks(getFunction());
752755
for (auto *deadCopy : deadCopies) {
753756
assert(changed);
754757
auto *srcInst = deadCopy->getSrc()->getDefiningInstruction();
755758
deadCopy->eraseFromParent();
756759
// Simplify any access scope markers that were only used by the dead
757760
// copy_addr and other potentially unused addresses.
758761
if (srcInst) {
759-
simplifyAndReplaceAllSimplifiedUsesAndErase(srcInst, callbacks);
762+
simplifyAndReplaceAllSimplifiedUsesAndErase(srcInst, callbacks, &deBlocks);
760763
}
761764
}
762765
if (changed) {

0 commit comments

Comments
 (0)