Skip to content

Commit 9733024

Browse files
authored
Merge pull request swiftlang#12947 from adrian-prantl/35459092
2 parents 71477f0 + 78e074d commit 9733024

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,10 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType LoadTy,
519519
// case.
520520
ArrayRef<SILInstruction *> InsertPts = Val.getInsertionPoints();
521521
if (InsertPts.size() == 1) {
522-
SavedInsertionPointRAII SavedInsertPt(B, InsertPts[0]);
523-
SILValue EltVal = nonDestructivelyExtractSubElement(Val, B, Loc);
522+
// Use the scope and location of the store at the insertion point.
523+
SILBuilderWithScope Builder(InsertPts[0]);
524+
SILLocation Loc = InsertPts[0]->getLoc();
525+
SILValue EltVal = nonDestructivelyExtractSubElement(Val, Builder, Loc);
524526
assert(EltVal->getType() == LoadTy && "Subelement types mismatch");
525527
return EltVal;
526528
}
@@ -530,8 +532,10 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType LoadTy,
530532
SILSSAUpdater Updater;
531533
Updater.Initialize(LoadTy);
532534
for (auto *I : Val.getInsertionPoints()) {
533-
SavedInsertionPointRAII SavedInsertPt(B, I);
534-
SILValue EltVal = nonDestructivelyExtractSubElement(Val, B, Loc);
535+
// Use the scope and location of the store at the insertion point.
536+
SILBuilderWithScope Builder(I);
537+
SILLocation Loc = I->getLoc();
538+
SILValue EltVal = nonDestructivelyExtractSubElement(Val, Builder, Loc);
535539
Updater.AddAvailableValue(I->getParent(), EltVal);
536540
}
537541

@@ -1113,7 +1117,7 @@ bool AllocOptimize::promoteLoad(SILInstruction *Inst) {
11131117
}
11141118

11151119
// Aggregate together all of the subelements into something that has the same
1116-
// type as the load did, and emit smaller) loads for any subelements that were
1120+
// type as the load did, and emit smaller loads for any subelements that were
11171121
// not available.
11181122
auto *Load = cast<LoadInst>(Inst);
11191123
AvailableValueAggregator Agg(Load, AvailableValues, Uses);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend -emit-sil -Xllvm -sil-print-debuginfo %s \
2+
// RUN: | %FileCheck %s
3+
4+
struct MyStruct {
5+
var a = 12
6+
}
7+
8+
public func use<T>(_ t : T){}
9+
10+
public func main() {
11+
var a = MyStruct() // line 11
12+
// Verify that the inserted struct_extract has the same location as the store.
13+
// CHECK: %[[A:.*]] = apply {{.*}} -> MyStruct,
14+
// CHECK-SAME: loc {{.*}}:11:10, scope [[S:[0-9]+]]
15+
// CHECK-NEXT: %[[I:.*]] = struct_extract %[[A]]
16+
// CHECK-SAME: loc {{.*}}:11:10, scope [[S]]
17+
// CHECK-NEXT: struct_extract %[[I]]
18+
// CHECK-SAME: loc {{.*}}:11:10, scope [[S]]
19+
// CHECK: store %[[A]] to %0 : $*MyStruct,
20+
// CHECK-SAME: loc {{.*}}:11:10, scope [[S]]
21+
use(a.a)
22+
}

0 commit comments

Comments
 (0)