Skip to content

Commit b50d466

Browse files
committed
Fix aliasing DestroyAddrInst with load borrow. Enable speculative scoped instruction hoisting.
1 parent b777b07 commit b50d466

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LoopInvariantCodeMotion.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,9 @@ 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 {
654653
guard scopedInst.hoist(outOf: loop, context) else {
655654
continue
656655
}
@@ -1107,9 +1106,9 @@ private extension ScopedInstruction {
11071106
case is BeginApplyInst:
11081107
return true // Has already been checked with other full applies.
11091108
case is LoadBorrowInst:
1110-
for storeInst in analyzedInstructions.stores {
1111-
if storeInst.mayWrite(toAddress: operands.first!.value, context.aliasAnalysis) {
1112-
if !scope.contains(storeInst) {
1109+
for inst in loop.loopBlocks.lazy.flatMap(\.instructions) {
1110+
if (inst is DestroyAddrInst || inst is StoreInst) && inst.operands.contains(where: { context.aliasAnalysis.mayAlias(operands.first!.value, $0.value) }) {
1111+
if !scope.contains(inst) {
11131112
return false
11141113
}
11151114
}

0 commit comments

Comments
 (0)