diff --git a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp index 7c6927c59c513..1cd0c7a0b40fc 100644 --- a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp +++ b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp @@ -93,13 +93,8 @@ static unsigned getElementCountRec(TypeExpansionContext context, } static std::pair -computeMemorySILType(MarkUninitializedInst *MemoryInst) { +computeMemorySILType(MarkUninitializedInst *MUI, SILValue Address) { // Compute the type of the memory object. - auto *MUI = MemoryInst; - SILValue Address = MUI; - if (auto *PBI = Address->getSingleUserOfType()) { - Address = PBI; - } SILType MemorySILType = Address->getType().getObjectType(); // If this is a let variable we're initializing, remember this so we don't @@ -118,7 +113,13 @@ DIMemoryObjectInfo::DIMemoryObjectInfo(MarkUninitializedInst *MI) : MemoryInst(MI) { auto &Module = MI->getModule(); - std::tie(MemorySILType, IsLet) = computeMemorySILType(MemoryInst); + SILValue Address = MemoryInst; + if (auto PBI = MemoryInst->getSingleUserOfType()) { + IsBox = true; + Address = PBI; + } + + std::tie(MemorySILType, IsLet) = computeMemorySILType(MI, Address); // Compute the number of elements to track in this memory object. // If this is a 'self' in a delegating initializer, we only track one bit: diff --git a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h index cbb3759e36866..21887b601ce66 100644 --- a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h +++ b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h @@ -72,6 +72,9 @@ class DIMemoryObjectInfo { /// non-empty. bool HasDummyElement = false; + /// True if this object has a single user of type ProjectBoxInst. + bool IsBox = false; + public: DIMemoryObjectInfo(MarkUninitializedInst *MemoryInst); @@ -98,10 +101,11 @@ class DIMemoryObjectInfo { /// instruction. For alloc_box though it returns the project_box associated /// with the memory info. SingleValueInstruction *getUninitializedValue() const { - if (auto *mui = dyn_cast(MemoryInst)) { - if (auto *pbi = mui->getSingleUserOfType()) { - return pbi; - } + if (IsBox) { + // TODO: consider just storing the ProjectBoxInst in this case. + auto *pbi = MemoryInst->getSingleUserOfType(); + assert(pbi); + return pbi; } return MemoryInst; }