Skip to content

Commit 1cbed39

Browse files
committed
Optimizer: support the new array literal initialization pattern in the COWOpts pass
1 parent de557ca commit 1cbed39

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/SILOptimizer/Transforms/COWOpts.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ bool COWOptsPass::optimizeBeginCOW(BeginCOWMutationInst *BCM) {
146146
} else if (auto *ECM = dyn_cast<EndCOWMutationInst>(v)) {
147147
if (endCOWMutationsFound.insert(ECM))
148148
endCOWMutationInsts.push_back(ECM);
149+
} else if (auto *urc = dyn_cast<UncheckedRefCastInst>(v)) {
150+
workList.push_back(urc->getOperand());
149151
} else {
150152
return false;
151153
}

test/SILOptimizer/cow_opts.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ bb0(%0 : $Buffer):
3939
return %t : $(Int, Builtin.Int1, Buffer)
4040
}
4141

42+
// CHECK-LABEL: sil @test_cast
43+
// CHECK: [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1
44+
// CHECK: ({{.*}}, [[B:%[0-9]+]]) = begin_cow_mutation
45+
// CHECK: [[T:%[0-9]+]] = tuple ({{.*}}, [[I]] : $Builtin.Int1, [[B]] : $Buffer)
46+
// CHECK: return [[T]]
47+
// CHECK: } // end sil function 'test_cast'
48+
sil @test_cast : $@convention(thin) (@owned Builtin.BridgeObject) -> (Int, Builtin.Int1, @owned Buffer) {
49+
bb0(%0 : $Builtin.BridgeObject):
50+
%1 = end_cow_mutation %0
51+
%e = unchecked_ref_cast %1 to $Buffer
52+
%addr = ref_element_addr [immutable] %e : $Buffer, #Buffer.i
53+
debug_value %e : $Buffer, var, name "x"
54+
%i = load %addr : $*Int
55+
(%u, %b) = begin_cow_mutation %e : $Buffer
56+
%t = tuple (%i : $Int, %u : $Builtin.Int1, %b : $Buffer)
57+
return %t : $(Int, Builtin.Int1, Buffer)
58+
}
59+
4260
// CHECK-LABEL: sil @test_store
4361
// CHECK: end_cow_mutation
4462
// CHECK: [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1

0 commit comments

Comments
 (0)