Skip to content

Commit bd2bb2e

Browse files
committed
EscapeAnalysis: Invert defer edges for array semantics.
Defer edges should always point to the more specific SSA value. For example, the contents of a memory location point to the values stored in that locations. Tuples point to their elements. BBArgs point to their source operands. Likewise, array objects should point to their exposed unsafe pointer (which is effectively a value stored in the array object). I'm not sure why the defer edges were reversed in the first place, but it was always confusing me.
1 parent 78a8cac commit bd2bb2e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
18911891
if (LoadedElement) {
18921892
if (CGNode *arrayElementStorage =
18931893
ConGraph->getFieldContent(ArrayObjNode)) {
1894-
ConGraph->defer(LoadedElement, arrayElementStorage);
1894+
ConGraph->defer(arrayElementStorage, LoadedElement);
18951895
return;
18961896
}
18971897
}
@@ -1902,7 +1902,7 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
19021902
// returned address point to the same element storage.
19031903
if (CGNode *ArrayObjNode = ConGraph->getValueContent(ASC.getSelf())) {
19041904
CGNode *arrayElementAddress = ConGraph->getNode(ASC.getCallResult());
1905-
ConGraph->defer(arrayElementAddress, ArrayObjNode);
1905+
ConGraph->defer(ArrayObjNode, arrayElementAddress);
19061906
return;
19071907
}
19081908
break;

test/SILOptimizer/escape_analysis.sil

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,10 +1212,10 @@ bb0(%0 : $Array<X>):
12121212

12131213
// CHECK-LABEL: CG of arraysemantics_get_element
12141214
// CHECK-NEXT: Arg %0 Esc: A, Succ: (%0.1)
1215-
// CHECK-NEXT: Con [ref] %0.1 Esc: A, Succ: %1.2
1215+
// CHECK-NEXT: Con [ref] %0.1 Esc: A, Succ:
12161216
// CHECK-NEXT: Arg [ref] %1 Esc: A, Succ: (%1.1)
12171217
// CHECK-NEXT: Con [int] %1.1 Esc: A, Succ: (%1.2)
1218-
// CHECK-NEXT: Con %1.2 Esc: A, Succ:
1218+
// CHECK-NEXT: Con %1.2 Esc: A, Succ: %0.1
12191219
// CHECK-NEXT: End
12201220
sil @arraysemantics_get_element : $@convention(thin) (Array<X>) -> @out X {
12211221
bb0(%io : $*X, %1 : $Array<X>):
@@ -1246,9 +1246,9 @@ bb0(%0 : $*Array<X>):
12461246

12471247
// CHECK-LABEL: CG of arraysemantics_get_element_address
12481248
// CHECK-NEXT: Arg [ref] %0 Esc: A, Succ: (%0.1)
1249-
// CHECK-NEXT: Con [int] %0.1 Esc: A, Succ:
1249+
// CHECK-NEXT: Con [int] %0.1 Esc: A, Succ: (%0.2), %4
12501250
// CHECK-NEXT: Con %0.2 Esc: A, Succ:
1251-
// CHECK-NEXT: Val %4 Esc: , Succ: %0.1
1251+
// CHECK-NEXT: Val %4 Esc: A, Succ: (%0.2)
12521252
// CHECK-NEXT: End
12531253
sil @arraysemantics_get_element_address : $@convention(thin) (Array<X>) -> () {
12541254
bb0(%0 : $Array<X>):

0 commit comments

Comments
 (0)