File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,17 @@ bool ArrayAllocation::replaceGetElements() {
244
244
if (EltValueIt == ElementValueMap.end ())
245
245
continue ;
246
246
247
+ SILValue element = EltValueIt->second ;
248
+
249
+ // In OSSA we only insert a copy_value of the element at the array initialization
250
+ // point. This would result in an over-consume if the getElement is in a loop.
251
+ // Therefore require that both semantic calls are in the same block.
252
+ if (ArrayValue->getFunction ()->hasOwnership () &&
253
+ !element->getType ().isTrivial (ArrayValue->getFunction ()) &&
254
+ ArrayValue->getParentBlock () != GetElementCall->getParent ()) {
255
+ continue ;
256
+ }
257
+
247
258
Changed |= GetElement.replaceByValue (EltValueIt->second );
248
259
}
249
260
return Changed;
Original file line number Diff line number Diff line change @@ -15,7 +15,24 @@ func testit(_ arr: inout [Int]) {
15
15
var a = [ 27 ]
16
16
testit ( & a)
17
17
18
+ // Second test case:
19
+ var gg = " "
20
+
21
+ @inline ( never)
22
+ func use( _ s: String ) {
23
+ gg = s
24
+ }
25
+
26
+ func testLoop( ) {
27
+ let a = [ " " ]
28
+
29
+ for _ in 0 ..< 1000 {
30
+ use ( a [ 0 ] )
31
+ }
32
+ }
33
+
18
34
// As a bonus, also check if the code works as expected.
19
35
// CHECK: [27, 28]
20
36
print ( a)
21
37
38
+ testLoop ( )
You can’t perform that action at this time.
0 commit comments