Skip to content

Commit e24ef9d

Browse files
authored
Merge pull request swiftlang#84055 from MAJKFL/fix-read-apply-hoisted-with-conflicting-write-apply-bug
Fix read only apply hoisting with conflicting write apply in the new LICM
2 parents 77f7f42 + e905df4 commit e24ef9d

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LoopInvariantCodeMotion.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,8 @@ private extension ApplyInst {
10301030
mayRead(fromAddress: copyAddrInst.destination, aliasAnalysis) {
10311031
return false
10321032
}
1033-
case is ApplyInst, is BeginApplyInst, is TryApplyInst:
1034-
if calleeAnalysis.getSideEffects(ofApply: self).memory.write {
1033+
case let fullApplySite as FullApplySite:
1034+
if calleeAnalysis.getSideEffects(ofApply: fullApplySite).memory.write {
10351035
return false
10361036
}
10371037
case is CondFailInst, is StrongRetainInst, is UnmanagedRetainValueInst,

test/SILOptimizer/licm.sil

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,41 @@ bb3:
11501150
return %val1 : $(Int64, Int64, Int64)
11511151
}
11521152

1153+
sil @$foo_read_write : $@convention(method) (Int) -> () {
1154+
[global: read,write]
1155+
}
1156+
1157+
sil @$foo_read : $@convention(method) (Int) -> () {
1158+
[global: read]
1159+
}
1160+
1161+
// Read only apply can't be hoisted because of a conflicting write apply in the loop.
1162+
//
1163+
// CHECK-LABEL: sil @test_conflicting_write_apply : $@convention(thin) (Int) -> () {
1164+
// CHECK: bb2:
1165+
// CHECK-NEXT: apply
1166+
// CHECK-NEXT: apply
1167+
// CHECK: bb3:
1168+
// CHECK-LABEL: } // end sil function 'test_conflicting_write_apply'
1169+
sil @test_conflicting_write_apply : $@convention(thin) (Int) -> () {
1170+
bb0(%0 : $Int):
1171+
%4 = function_ref @$foo_read_write : $@convention(method) (Int) -> ()
1172+
%5 = function_ref @$foo_read : $@convention(method) (Int) -> ()
1173+
br bb2
1174+
1175+
bb1:
1176+
br bb2
1177+
1178+
bb2:
1179+
%8 = apply %5(%0) : $@convention(method) (Int) -> ()
1180+
%9 = apply %4(%0) : $@convention(method) (Int) -> ()
1181+
cond_br undef, bb3, bb1
1182+
1183+
bb3:
1184+
%11 = tuple ()
1185+
return %11
1186+
}
1187+
11531188
// Two stores, one to the outer tuple and one to the inner tuple. This
11541189
// results in two access paths that are only loaded/stored to. First
11551190
// split the outer tuple when processing the outer access path, then

0 commit comments

Comments
 (0)