Skip to content

Commit 5d63fcf

Browse files
committed
[MOWTE] Visit undef values.
Such values' types may also also be move-only wrapped.
1 parent 69fa1ae commit 5d63fcf

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ bool SILMoveOnlyWrappedTypeEliminator::process() {
306306
for (auto *use : value->getNonTypeDependentUses())
307307
touchedInsts.insert(use->getUser());
308308

309-
value->unsafelyEliminateMoveOnlyWrapper(fn);
309+
if (isa<SILUndef>(value))
310+
value->replaceAllUsesWith(
311+
SILUndef::get(fn, value->getType().removingAnyMoveOnlyWrapping(fn)));
312+
else
313+
value->unsafelyEliminateMoveOnlyWrapper(fn);
310314

311315
return true;
312316
};
@@ -341,6 +345,16 @@ bool SILMoveOnlyWrappedTypeEliminator::process() {
341345
madeChange = true;
342346
}
343347
}
348+
// SILFunction::undefValues may grow during the loop.
349+
SmallVector<std::pair<SILType, SILUndef *>, 4> originalUndefs(
350+
fn->getUndefValues());
351+
for (auto pair : originalUndefs) {
352+
bool relevant = visitValue(pair.second);
353+
if (!relevant)
354+
continue;
355+
356+
madeChange = true;
357+
}
344358

345359
SILMoveOnlyWrappedTypeEliminatorVisitor visitor;
346360
while (!touchedInsts.empty()) {

test/SILOptimizer/moveonly_type_eliminator.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,19 @@ bb3(%result : @owned $@moveOnly FakeOptional<Klass>):
562562
%result2 = moveonlywrapper_to_copyable [owned] %result : $@moveOnly FakeOptional<Klass>
563563
return %result2 : $FakeOptional<Klass>
564564
}
565+
566+
// CHECK-LABEL: sil [ossa] @debug_value_undef : {{.*}} {
567+
// CHECK: debug_value [moveable_value_debuginfo] undef : $*Klass, var, name "s"
568+
// CHECK-LABEL: } // end sil function 'debug_value_undef'
569+
sil [ossa] @debug_value_undef : $@convention(thin) (@owned Klass) -> () {
570+
bb0(%x : @owned $Klass):
571+
%addr = alloc_stack $@moveOnly Klass
572+
%unwrapped_addr = moveonlywrapper_to_copyable_addr %addr : $*@moveOnly Klass
573+
store %x to [init] %unwrapped_addr : $*Klass
574+
debug_value %addr : $*@moveOnly Klass, var, name "s", argno 1, expr op_deref
575+
destroy_addr %addr : $*@moveOnly Klass
576+
debug_value undef : $*@moveOnly Klass, var, name "s", argno 1, expr op_deref
577+
dealloc_stack %addr : $*@moveOnly Klass
578+
%retval = tuple ()
579+
return %retval : $()
580+
}

0 commit comments

Comments
 (0)