Skip to content

Commit 4ab27ff

Browse files
authored
Merge pull request #72721 from gottesmm/pr-fc03d3301561157a960d10550e3981d65283da3e
[sil] Teach variable name utils how to handle init_existential_addr temporaries
2 parents 3990e17 + ce27305 commit 4ab27ff

File tree

3 files changed

+779
-695
lines changed

3 files changed

+779
-695
lines changed

lib/SILOptimizer/Utils/VariableNameUtils.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ struct AddressWalkerState {
2929
static SILValue
3030
findRootValueForNonTupleTempAllocation(AllocationInst *allocInst,
3131
AddressWalkerState &state) {
32+
// These are instructions which we are ok with looking through when
33+
// identifying our allocation. It must always refer to the entire allocation.
34+
auto isAlloc = [&](SILValue value) -> bool {
35+
if (auto *ieai = dyn_cast<InitExistentialAddrInst>(value))
36+
value = ieai->getOperand();
37+
return value == SILValue(allocInst);
38+
};
39+
3240
// Walk from our allocation to one of our writes. Then make sure that the
3341
// write writes to our entire value.
3442
for (auto &inst : allocInst->getParent()->getRangeStartingAtInst(allocInst)) {
@@ -38,21 +46,21 @@ findRootValueForNonTupleTempAllocation(AllocationInst *allocInst,
3846
continue;
3947

4048
if (auto *copyAddr = dyn_cast<CopyAddrInst>(&inst)) {
41-
if (copyAddr->getDest() == allocInst &&
49+
if (isAlloc(copyAddr->getDest()) &&
4250
copyAddr->isInitializationOfDest()) {
4351
return copyAddr->getSrc();
4452
}
4553
}
4654

4755
if (auto *si = dyn_cast<StoreInst>(&inst)) {
48-
if (si->getDest() == allocInst &&
56+
if (isAlloc(si->getDest()) &&
4957
si->getOwnershipQualifier() != StoreOwnershipQualifier::Assign) {
5058
return si->getSrc();
5159
}
5260
}
5361

5462
if (auto *sbi = dyn_cast<StoreBorrowInst>(&inst)) {
55-
if (sbi->getDest() == allocInst)
63+
if (isAlloc(sbi->getDest()))
5664
return sbi->getSrc();
5765
}
5866

0 commit comments

Comments
 (0)