Skip to content

Commit 0aa17db

Browse files
committed
[MOWTE] Visit undef values.
Such values' types may also also be move-only wrapped.
1 parent 1e78ed2 commit 0aa17db

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
@@ -307,7 +307,11 @@ bool SILMoveOnlyWrappedTypeEliminator::process() {
307307
for (auto *use : value->getNonTypeDependentUses())
308308
touchedInsts.insert(use->getUser());
309309

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

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

346360
SILMoveOnlyWrappedTypeEliminatorVisitor visitor;
347361
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)