Skip to content

Commit 7bfb145

Browse files
committed
PhiUpdater: fix a problem when incrementally updating borrowed-from instructions
When replacing all uses, ignore existing borrowed-from instructions. Fixes a SIL verifier error.
1 parent 55189ba commit 7bfb145

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/PhiUpdater.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private func createBorrowedFrom(for phi: Phi, _ context: some MutatingContext) {
126126
if !phi.value.uses.contains(where: { $0.forwardingBorrowedFromUser != nil }) {
127127
let builder = Builder(atBeginOf: phi.value.parentBlock, context)
128128
let bfi = builder.createBorrowedFrom(borrowedValue: phi.value, enclosingValues: [])
129-
phi.value.uses.ignore(user: bfi).replaceAll(with: bfi, context)
129+
phi.value.uses.ignoreUsers(ofType: BorrowedFromInst.self).replaceAll(with: bfi, context)
130130
}
131131
}
132132

test/SILOptimizer/simplify_cfg_dom_jumpthread.sil

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,39 @@ bb6:
558558
fix_lifetime %6 : $E2
559559
unreachable
560560
}
561+
562+
// CHECK-LABEL: sil [ossa] @test_update_borrowed_from :
563+
// CHECK: bb3([[A1:%.*]] : @guaranteed $C, [[A2:%.*]] : @reborrow $C):
564+
// CHECK-DAG: = borrowed [[A2]] : $C from ()
565+
// CHECK-DAG: = borrowed [[A1]] : $C from ([[A2]] : $C)
566+
// CHECK: } // end sil function 'test_update_borrowed_from'
567+
sil [ossa] @test_update_borrowed_from : $@convention(thin) (Builtin.Int1, @inout C) -> () {
568+
bb0(%0 : $Builtin.Int1, %1 : $*C):
569+
cond_br %0, bb2, bb1
570+
571+
bb1:
572+
br bb3
573+
574+
bb2:
575+
%4 = load [take] %1
576+
store %4 to [init] %1
577+
br bb3
578+
579+
bb3:
580+
%7 = load_borrow %1
581+
cond_br %0, bb5, bb4
582+
583+
bb4:
584+
br bb6(%7)
585+
586+
bb5:
587+
%10 = unchecked_ref_cast %7 to $C
588+
br bb6(%10)
589+
590+
bb6(%12 : @guaranteed $C):
591+
%13 = borrowed %12 from (%7)
592+
end_borrow %7
593+
%15 = tuple ()
594+
return %15
595+
}
596+

0 commit comments

Comments
 (0)