Skip to content

Commit 63961e9

Browse files
committed
RedundantLoadElimination: ignore memory effects of begin_access
Memory effects of begin_access are only defined to prevent the optimizer moving loads and stores across a begin_access. But those memory effects are not relevant for RedundantLoadElimination
1 parent e6965e6 commit 63961e9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/RedundantLoadElimination.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ private struct InstructionScanner {
500500

501501
private mutating func visit(instruction: Instruction) -> ScanResult {
502502
switch instruction {
503-
case is FixLifetimeInst, is EndAccessInst, is EndBorrowInst:
503+
case is FixLifetimeInst, is BeginAccessInst, is EndAccessInst, is EndBorrowInst:
504504
// Those scope-ending instructions are only irrelevant if the preceding load is not changed.
505505
// If it is changed from `load [copy]` -> `load [take]` the memory effects of those scope-ending
506506
// instructions prevent that the `load [take]` will illegally mutate memory which is protected

test/SILOptimizer/redundant_load_elim_ossa.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,24 @@ bb0:
14031403
return %5 : $Int32
14041404
}
14051405

1406+
// CHECK-LABEL: sil [ossa] @ignore_begin_access :
1407+
// CHECK: return %0
1408+
// CHECK-LABEL: } // end sil function 'ignore_begin_access'
1409+
sil [ossa] @ignore_begin_access : $@convention(thin) (Int, Int, @inout TwoField) -> Int {
1410+
bb0(%0 : $Int, %1 : $Int, %2 : $*TwoField):
1411+
%3 = begin_access [modify] [static] %2
1412+
%4 = struct_element_addr %3, #TwoField.a
1413+
store %0 to [trivial] %4
1414+
end_access %3
1415+
%7 = begin_access [modify] [static] %2
1416+
%8 = struct_element_addr %7, #TwoField.b
1417+
store %0 to [trivial] %8
1418+
end_access %7
1419+
%11 = struct_element_addr %2, #TwoField.a
1420+
%12 = load [trivial] %11
1421+
return %12
1422+
}
1423+
14061424
// CHECK: sil @tbaa_class_alias_nonclass
14071425
// CHECK: strong_retain [[RET:%[0-9]+]]
14081426
// CHECK: strong_retain [[RET]]

0 commit comments

Comments
 (0)