Skip to content

Commit ab2202c

Browse files
committed
AliasAnalysis: look through begin_cow_mutation and end_cow_mutation when getting the root of a reference
1 parent 8739bef commit ab2202c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ SILValue swift::getUnderlyingObject(SILValue v) {
8181
v2 = stripAddressProjections(v2);
8282
v2 = stripIndexingInsts(v2);
8383
v2 = lookThroughOwnershipInsts(v2);
84+
if (auto *ecm = dyn_cast<EndCOWMutationInst>(v2)) {
85+
v2 = ecm->getOperand();
86+
} else if (auto *mvr = dyn_cast<MultipleValueInstructionResult>(v2)) {
87+
if (auto *bci = dyn_cast<BeginCOWMutationInst>(mvr->getParent()))
88+
v2 = bci->getOperand();
89+
}
8490
if (v2 == v)
8591
return v2;
8692
v = v2;

lib/SIL/Utils/Projection.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,15 @@ llvm::Optional<ProjectionPath> ProjectionPath::getProjectionPath(SILValue Start,
380380

381381
auto Iter = End;
382382
while (Start != Iter) {
383+
384+
if (auto *mvr = dyn_cast<MultipleValueInstructionResult>(Iter)) {
385+
if (auto *bci = dyn_cast<BeginCOWMutationInst>(mvr->getParent())) {
386+
Iter = bci->getOperand();
387+
continue;
388+
}
389+
break;
390+
}
391+
383392
// end_cow_mutation and begin_access are not projections, but we need to be
384393
// able to form valid ProjectionPaths across them, otherwise optimization
385394
// passes like RLE/DSE cannot recognize their locations.

test/SILOptimizer/basic-aa.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,21 @@ bb0(%0 : $P):
628628
return %6 : $()
629629
}
630630

631+
// CHECK-LABEL: @testCowMutation
632+
// CHECK: PAIR #23.
633+
// CHECK-NEXT: %4 = ref_tail_addr %0 : $X, $Int32
634+
// CHECK-NEXT: %5 = ref_tail_addr %3 : $X, $Int32
635+
// CHECK-NEXT: MustAlias
636+
sil @testCowMutation : $@convention(thin) () -> () {
637+
bb0:
638+
%0 = alloc_ref $X
639+
(%1, %2) = begin_cow_mutation %0 : $X
640+
%3 = end_cow_mutation %2 : $X
641+
%4 = ref_tail_addr %0 : $X, $Int32
642+
%5 = ref_tail_addr %3 : $X, $Int32
643+
fix_lifetime %4 : $*Int32
644+
fix_lifetime %5 : $*Int32
645+
%99 = tuple ()
646+
return %99 : $()
647+
}
648+

0 commit comments

Comments
 (0)