LetPropertyLowering: remove redundant phis after ssa-update

This is needed after running the SSAUpdater, because the updater can insert unnecessary phis in the middle of the original liverange of a value.

Fixes an ownership error.
rdar://153229472
This commit is contained in:
Erik Eckstein
2025-07-04 11:08:45 +02:00
parent 1a6ad0c512
commit 81a4f7a84e
2 changed files with 33 additions and 0 deletions

View File

@@ -122,6 +122,8 @@ private func insertEndInitInstructions(
use.set(to: ssaUpdater.getValue(atEndOf: use.instruction.parentBlock), context)
}
}
// This peephole optimization is required to avoid ownership errors.
replacePhisWithIncomingValues(phis: ssaUpdater.insertedPhis, context)
}
private func constructLetInitRegion(

View File

@@ -311,3 +311,34 @@ bb1(%3a : @reborrow $C):
return %2 : $C
}
// CHECK-LABEL: sil [ossa] @test_no_phis :
// CHECK: %3 = end_init_let_ref %2
// CHECK: return %3
// CHECK: } // end sil function 'test_no_phis'
sil [ossa] @test_no_phis : $@convention(thin) (Int, @owned C) -> @owned C {
bb0(%0 : $Int, %1 : @owned $C):
%2 = mark_uninitialized [rootself] %1
%3 = begin_borrow %2
cond_br undef, bb1, bb2
bb1:
br bb7
bb2:
cond_br undef, bb3, bb8
bb3:
cond_br undef, bb4, bb5
bb4:
br bb7
bb5:
br bb6
bb6:
end_borrow %3
return %2
bb7:
br bb6
bb8:
end_borrow %3
destroy_value [dead_end] %2
unreachable
}