Skip to content

Commit b115e24

Browse files
committed
Revert "Generalize alloc_stack hoisting. Remove speculative scoped instruction hoisting."
This reverts commit b777b07.
1 parent 64e202e commit b115e24

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LoopInvariantCodeMotion.swift

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private func collectMovableInstructions(
310310

311311
movableInstructions.loadsAndStores.append(loadInst)
312312
case is UncheckedOwnershipConversionInst:
313-
break
313+
break // TODO: Add support
314314
case let storeInst as StoreInst:
315315
switch storeInst.storeOwnership {
316316
case .assign:
@@ -647,10 +647,24 @@ private extension MovableInstructions {
647647
return false
648648
}
649649

650-
let dominatingBlocks = loop.getBlocksThatDominateAllExitingAndLatchBlocks(context)
651650
var changed = false
652651

653-
for scopedInst in scopedInsts where dominatingBlocks.contains(scopedInst.parentBlock) {
652+
for scopedInst in scopedInsts {
653+
if let storeBorrowInst = scopedInst as? StoreBorrowInst {
654+
_ = storeBorrowInst.allocStack.hoist(outOf: loop, context)
655+
656+
var sankFirst = false
657+
for deallocStack in storeBorrowInst.allocStack.deallocations {
658+
if sankFirst {
659+
context.erase(instruction: deallocStack)
660+
} else {
661+
sankFirst = deallocStack.sink(outOf: loop, context)
662+
}
663+
}
664+
665+
context.notifyInvalidatedStackNesting()
666+
}
667+
654668
guard scopedInst.hoist(outOf: loop, context) else {
655669
continue
656670
}
@@ -821,8 +835,6 @@ private extension Instruction {
821835
/// is not a terminator, allocation or deallocation and either a hoistable array semantics call or doesn't have memory effects.
822836
func canBeHoisted(outOf loop: Loop, _ context: FunctionPassContext) -> Bool {
823837
switch self {
824-
case let allocStackInst as AllocStackInst:
825-
return allocStackInst.deallocations.allSatisfy({ loop.contains(block: $0.parentBlock) })
826838
case is TermInst, is Allocation, is Deallocation:
827839
return false
828840
case is ApplyInst:
@@ -862,19 +874,6 @@ private extension Instruction {
862874
return true
863875
} else {
864876
move(before: terminator, context)
865-
866-
if let allocStack = self as? AllocStackInst {
867-
var sankFirst = false
868-
for deallocStack in allocStack.deallocations {
869-
if sankFirst {
870-
context.erase(instruction: deallocStack)
871-
} else {
872-
sankFirst = deallocStack.sink(outOf: loop, context)
873-
}
874-
}
875-
876-
context.notifyInvalidatedStackNesting()
877-
}
878877
}
879878
}
880879

0 commit comments

Comments
 (0)