Skip to content

Commit e84bc08

Browse files
committed
Check for aliasing destroy_addr before hoisting load_borrow - end_borrow pair.
1 parent 0b75a81 commit e84bc08

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LoopInvariantCodeMotion.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,17 @@ private extension ScopedInstruction {
11001100
switch self {
11011101
case is BeginApplyInst:
11021102
return true // Has already been checked with other full applies.
1103-
case is LoadBorrowInst:
1103+
case let loadBorrowInst as LoadBorrowInst:
1104+
for case let destroyAddrInst as DestroyAddrInst in analyzedInstructions.loopSideEffects {
1105+
if context.aliasAnalysis.mayAlias(loadBorrowInst.address, destroyAddrInst.destroyedAddress) {
1106+
if !scope.contains(destroyAddrInst) {
1107+
return false
1108+
}
1109+
}
1110+
}
1111+
11041112
for storeInst in analyzedInstructions.stores {
1105-
if storeInst.mayWrite(toAddress: operands.first!.value, context.aliasAnalysis) {
1113+
if storeInst.mayWrite(toAddress: loadBorrowInst.address, context.aliasAnalysis) {
11061114
if !scope.contains(storeInst) {
11071115
return false
11081116
}

0 commit comments

Comments
 (0)