@@ -560,14 +560,6 @@ bool HoistDestroys::rewriteDestroys(const AccessStorage &storage,
560560bool HoistDestroys::foldBarrier (SILInstruction *barrier,
561561 const AccessStorage &storage,
562562 const DeinitBarriers &deinitBarriers) {
563- auto rootPath = AccessPath::compute (storageRoot);
564- if (!rootPath.isValid ()) {
565- // [invalid_access_path] The access path to storageRoot isn't understood.
566- // It can't be determined whether all of its leaves have been visited, so
567- // foldability can't be determined. Bail.
568- return false ;
569- }
570-
571563 // The load [copy]s which will be folded into load [take]s if folding is
572564 // possible.
573565 llvm::SmallVector<LoadInst *, 4 > loads;
@@ -599,13 +591,19 @@ bool HoistDestroys::foldBarrier(SILInstruction *barrier,
599591 // it.
600592 SmallPtrSet<AccessPath::PathNode, 16 > trivialLeaves;
601593
602- visitProductLeafAccessPathNodes (rootPath, storageRoot, typeExpansionContext,
603- module ,
604- [&](AccessPath::PathNode node, SILType ty) {
605- if (ty.isTrivial (*function))
606- return ;
607- leaves.insert (node);
608- });
594+ bool succeeded = visitProductLeafAccessPathNodes (
595+ storageRoot, typeExpansionContext, module ,
596+ [&](AccessPath::PathNode node, SILType ty) {
597+ if (ty.isTrivial (*function))
598+ return ;
599+ leaves.insert (node);
600+ });
601+ if (!succeeded) {
602+ // [invalid_access_path] The access path to storageRoot isn't understood.
603+ // It can't be determined whether all of its leaves have been visited, so
604+ // foldability can't be determined. Bail.
605+ return false ;
606+ }
609607
610608 for (auto *instruction = barrier; instruction != nullptr ;
611609 instruction = instruction->getPreviousInstruction ()) {
@@ -752,16 +750,10 @@ bool HoistDestroys::checkFoldingBarrier(
752750 // of the root storage which would be folded if folding were possible.
753751 // Find its nontrivial product leaves and remove them from the set of
754752 // leaves of the root storage which we're wating to see.
755- auto rootPath = AccessPath::compute (address);
756- // [invalid_access_path] The access path to storageRoot was understood, and
757- // address has identical storage to its storage. The access path to address
758- // must be valid.
759- assert (rootPath.isValid ());
760-
761753 bool alreadySawLeaf = false ;
762754 bool alreadySawTrivialSubleaf = false ;
763- visitProductLeafAccessPathNodes (
764- rootPath, address, typeExpansionContext, module ,
755+ auto succeeded = visitProductLeafAccessPathNodes (
756+ address, typeExpansionContext, module ,
765757 [&](AccessPath::PathNode node, SILType ty) {
766758 if (ty.isTrivial (*function)) {
767759 bool inserted = !trivialLeaves.insert (node).second ;
@@ -771,6 +763,11 @@ bool HoistDestroys::checkFoldingBarrier(
771763 bool erased = leaves.erase (node);
772764 alreadySawLeaf = alreadySawLeaf || !erased;
773765 });
766+ (void )succeeded;
767+ // [invalid_access_path] The access path to storageRoot was understood, and
768+ // address has identical storage to its storage. The access path to address
769+ // must be valid.
770+ assert (succeeded);
774771 if (alreadySawLeaf) {
775772 // We saw this non-trivial product leaf already. That means there are
776773 // multiple load [copy]s or copy_addrs of at least one product leaf
0 commit comments