Skip to content

Commit 0597fd9

Browse files
authored
Merge pull request #83390 from atrick/fix-trackifdead
Fix assertion in InstructionDeleter::trackIfDead.
2 parents 0266913 + c1e0a1d commit 0597fd9

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

include/swift/SILOptimizer/Utils/BasicBlockOptUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class SinkAddressProjections {
164164
///
165165
/// getInBlockProjectionOperandValues() can be called before or after cloning.
166166
bool cloneProjections();
167+
168+
SWIFT_DEBUG_DUMP;
167169
};
168170

169171
/// Clone a single basic block and any required successor edges within the same

lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,16 @@ bool SinkAddressProjections::cloneProjections() {
285285
}
286286
return true;
287287
}
288+
289+
void SinkAddressProjections::dump() const {
290+
llvm::dbgs() << "Old projections: ";
291+
for (auto *proj : oldProjections) {
292+
proj->dump();
293+
}
294+
if (auto *np = newProjections) {
295+
llvm::dbgs() << "New projections: ";
296+
for (auto *proj : *np) {
297+
proj->dump();
298+
}
299+
}
300+
}

lib/SILOptimizer/Utils/InstructionDeleter.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ bool InstructionDeleter::trackIfDead(SILInstruction *inst) {
187187
bool fixLifetime = inst->getFunction()->hasOwnership();
188188
if (isInstructionTriviallyDead(inst)
189189
|| isScopeAffectingInstructionDead(inst, fixLifetime)) {
190-
assert(!isIncidentalUse(inst) &&
191-
(!isa<DestroyValueInst>(inst) ||
192-
canTriviallyDeleteOSSAEndScopeInst(inst)) &&
190+
assert(!isIncidentalUse(inst)
191+
|| canTriviallyDeleteOSSAEndScopeInst(inst) &&
193192
"Incidental uses cannot be removed in isolation. "
194193
"They would be removed iff the operand is dead");
195194
getCallbacks().notifyWillBeDeleted(inst);
@@ -356,6 +355,20 @@ static FunctionTest DeleterDeleteIfDeadTest(
356355
llvm::outs() << "deleteIfDead returned " << deleted << "\n";
357356
function.print(llvm::outs());
358357
});
358+
359+
// Arguments:
360+
// - instruction: the instruction to delete
361+
// Dumps:
362+
// - the function
363+
static FunctionTest DeleterTrackIfDeadTest(
364+
"deleter_track_if_dead", [](auto &function, auto &arguments, auto &test) {
365+
auto *inst = arguments.takeInstruction();
366+
InstructionDeleter deleter;
367+
llvm::outs() << "Tracking " << *inst;
368+
deleter.trackIfDead(inst);
369+
deleter.cleanupDeadInstructions();
370+
function.print(llvm::outs());
371+
});
359372
} // namespace swift::test
360373

361374
void InstructionDeleter::forceDeleteAndFixLifetimes(SILInstruction *inst) {

test/SILOptimizer/instruction_deleter.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@ sil [ossa] @doDeleteLoadTake : $() -> () {
5757
%retval = tuple ()
5858
return %retval : $()
5959
}
60+
61+
// CHECK-LABEL: begin running test {{.*}} on trackEndBorrow
62+
// CHECK: Tracking end_borrow undef : $C
63+
// CHECK: sil [ossa] @trackEndBorrow : $@convention(thin) () -> () {
64+
// CHECK: bb0:
65+
// CHECK-NOT: end_borrow
66+
// CHECK-LABEL: } // end sil function 'trackEndBorrow'
67+
// CHECK-LABEL: end running test {{.*}} on trackEndBorrow
68+
sil [ossa] @trackEndBorrow : $() -> () {
69+
bb0:
70+
specify_test "deleter_track_if_dead @instruction"
71+
end_borrow undef : $C
72+
%retval = tuple ()
73+
return %retval : $()
74+
}

0 commit comments

Comments
 (0)