Skip to content

Commit be72ad7

Browse files
committed
Fix licm not projecting load path before load splitting.
1 parent 6e56c24 commit be72ad7

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LoopInvariantCodeMotion.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ private extension AnalyzedInstructions {
587587
continue
588588
}
589589

590-
guard let splitLoads = loadInst.trySplit(alongPath: accessPath.projectionPath, context) else {
590+
guard let projectionPath = loadInst.operand.value.accessPath.getProjection(to: accessPath),
591+
let splitLoads = loadInst.trySplit(alongPath: projectionPath, context) else {
591592
newLoads.push(loadInst)
592593
return false
593594
}

test/SILOptimizer/licm.sil

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,47 @@ bb2:
15141514
return %r1 : $()
15151515
}
15161516

1517+
struct Outer {
1518+
var interactions: Inner
1519+
}
1520+
1521+
public struct Inner {
1522+
public let x: Int
1523+
var storage: ContiguousArray<Double>
1524+
}
1525+
1526+
sil @$get_array_from_inner : $@convention(method) (Inner) -> (ContiguousArray<Double>)
1527+
1528+
// Make sure we project load access path to matching store access path.
1529+
// Otherwise the pass could crash.
1530+
//
1531+
// CHECK-LABEL: sil @project_load_path_before_splitting_crash :
1532+
// CHECK: load
1533+
// CHECK: bb1(%8 : $ContiguousArray<Double>):
1534+
// CHECK: bb3:
1535+
// CHECK: store
1536+
// CHECK: } // end sil function 'project_load_path_before_splitting_crash'
1537+
sil @project_load_path_before_splitting_crash : $@convention(thin) (@inout Outer) -> () {
1538+
bb0(%0 : $*Outer):
1539+
%1 = struct_element_addr %0, #Outer.interactions
1540+
%2 = struct_element_addr %1, #Inner.storage
1541+
br bb1
1542+
1543+
bb1:
1544+
%4 = load %1
1545+
%5 = function_ref @$get_array_from_inner : $@convention(method) (Inner) -> ContiguousArray<Double>
1546+
%6 = apply %5(%4) : $@convention(method) (Inner) -> ContiguousArray<Double>
1547+
store %6 to %2
1548+
cond_br undef, bb2, bb3
1549+
1550+
bb2:
1551+
br bb1
1552+
1553+
bb3:
1554+
%10 = tuple ()
1555+
return %10
1556+
}
1557+
15171558
// CHECK-LABEL: sil @dont_hoist_builtin_once_memory_conflict :
15181559
// CHECK: function_ref
15191560
// CHECK: br bb1

0 commit comments

Comments
 (0)