File tree Expand file tree Collapse file tree 2 files changed +40
-14
lines changed
SwiftCompilerSources/Sources/Optimizer/FunctionPasses Expand file tree Collapse file tree 2 files changed +40
-14
lines changed Original file line number Diff line number Diff line change @@ -1206,23 +1206,21 @@ private extension ScopedInstruction {
12061206 case is BeginApplyInst :
12071207 return true // Has already been checked with other full applies.
12081208 case let loadBorrowInst as LoadBorrowInst :
1209- for case let destroyAddrInst as DestroyAddrInst in analyzedInstructions. loopSideEffects {
1210- if context. aliasAnalysis. mayAlias ( loadBorrowInst. address, destroyAddrInst. destroyedAddress) {
1211- if !scope. contains ( destroyAddrInst) {
1212- return false
1213- }
1209+ for sideEffectInst in analyzedInstructions. loopSideEffects {
1210+ if let endBorrow = sideEffectInst as? EndBorrowInst ,
1211+ let begin = endBorrow. borrow as? LoadBorrowInst ,
1212+ begin == self
1213+ {
1214+ continue
12141215 }
1215- }
1216-
1217- for storeInst in analyzedInstructions. stores {
1218- if storeInst. mayWrite ( toAddress: loadBorrowInst. address, context. aliasAnalysis) {
1219- if !scope. contains ( storeInst) {
1220- return false
1221- }
1216+ if sideEffectInst. mayWrite ( toAddress: loadBorrowInst. address, context. aliasAnalysis) ,
1217+ !scope. contains ( sideEffectInst)
1218+ {
1219+ return false
12221220 }
12231221 }
1224-
1225- fallthrough
1222+ return true
1223+
12261224 case is BeginAccessInst :
12271225 for fullApplyInst in analyzedInstructions. fullApplies {
12281226 guard mayWriteToMemory && fullApplyInst. mayReadOrWrite ( address: operands. first!. value, context. aliasAnalysis) ||
Original file line number Diff line number Diff line change @@ -1771,6 +1771,34 @@ bb3:
17711771 return %r : $()
17721772}
17731773
1774+ // CHECK-LABEL: sil [ossa] @dont_hoist_load_borrow :
1775+ // CHECK: bb1:
1776+ // CHECK-NEXT: copy_addr
1777+ // CHECK-NEXT: load_borrow
1778+ // CHECK: } // end sil function 'dont_hoist_load_borrow'
1779+ sil [ossa] @dont_hoist_load_borrow : $@convention(thin) (@in_guaranteed String) -> () {
1780+ bb0(%0 : $*String):
1781+ %1 = alloc_stack $String
1782+ br bb1
1783+
1784+ bb1:
1785+ copy_addr %0 to [init] %1
1786+ %3 = load_borrow %1
1787+ fix_lifetime %3
1788+ end_borrow %3
1789+ %6 = load [take] %1
1790+ destroy_value %6
1791+ cond_br undef, bb2, bb3
1792+
1793+ bb2:
1794+ br bb1
1795+
1796+ bb3:
1797+ dealloc_stack %1
1798+ %r = tuple()
1799+ return %r : $()
1800+ }
1801+
17741802// CHECK-LABEL: sil [ossa] @dont_hoist_struct :
17751803// CHECK: bb1:
17761804// CHECK-NEXT: struct $NonCopyable
You can’t perform that action at this time.
0 commit comments