Skip to content

Commit 47a478d

Browse files
committed
[AddressLowering] Rewrite newly created uses.
When rewriting uses, it is possible for new uses of a value to be created, as when a debug_value instruction is created when a store instruction is deleted. Ensure that all uses are rewritten by adding all uses to the worklist of uses after rewriting each use.
1 parent 31ab259 commit 47a478d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,8 +3362,19 @@ static void rewriteFunction(AddressLoweringState &pass) {
33623362
if (valueDef->getType().isAddress())
33633363
continue;
33643364

3365+
SmallPtrSet<Operand *, 8> originalUses;
33653366
SmallVector<Operand *, 8> uses(valueDef->getUses());
3366-
for (Operand *oper : uses) {
3367+
for (auto *oper : uses) {
3368+
originalUses.insert(oper);
3369+
UseRewriter::rewriteUse(oper, pass);
3370+
}
3371+
uses.clear();
3372+
for (auto *use : valueDef->getUses()) {
3373+
uses.push_back(use);
3374+
}
3375+
for (auto *oper : uses) {
3376+
if (originalUses.contains(oper))
3377+
continue;
33673378
UseRewriter::rewriteUse(oper, pass);
33683379
}
33693380
}

test/SILOptimizer/address_lowering_phi.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,33 @@ bb2:
470470
bb3(%phi : @owned $T):
471471
return %phi : $T
472472
}
473+
474+
// Check that the debug_value instruction that is created when deleting a load
475+
// gets rewritten and doesn't obstruct the deletion of the phi.
476+
// CHECK-LABEL: sil [ossa] @f100_store_phi : {{.*}} {
477+
// CHECK: {{bb[0-9]+}}({{%[^,]+}} : $*Value):
478+
// CHECK: [[TEMP:%[^,]+]] = alloc_stack $Value
479+
// CHECK: [[VAR:%[^,]+]] = alloc_stack [lexical] $Value, var, name "value"
480+
// CHECK: cond_br undef, bb2, bb1
481+
// CHECK: bb3:
482+
// CHECK: copy_addr [take] [[TEMP]] to [init] [[VAR]]
483+
// CHECK: debug_value [[TEMP]] : $*Value, var, name "value"
484+
// CHECK-LABEL: } // end sil function 'f100_store_phi'
485+
sil [ossa] @f100_store_phi : $@convention(thin) <Value> (@in Value) -> () {
486+
entry(%instance : @owned $Value):
487+
%14 = alloc_stack [lexical] $Value, var, name "value"
488+
cond_br undef, left, right
489+
490+
left:
491+
br merge(%instance : $Value)
492+
493+
right:
494+
br merge(%instance : $Value)
495+
496+
merge(%34 : @owned $Value):
497+
store %34 to [init] %14 : $*Value
498+
destroy_addr %14 : $*Value
499+
dealloc_stack %14 : $*Value
500+
%43 = tuple ()
501+
return %43 : $()
502+
}

0 commit comments

Comments
 (0)