@@ -560,14 +560,6 @@ bool HoistDestroys::rewriteDestroys(const AccessStorage &storage,
560
560
bool HoistDestroys::foldBarrier (SILInstruction *barrier,
561
561
const AccessStorage &storage,
562
562
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
-
571
563
// The load [copy]s which will be folded into load [take]s if folding is
572
564
// possible.
573
565
llvm::SmallVector<LoadInst *, 4 > loads;
@@ -599,13 +591,19 @@ bool HoistDestroys::foldBarrier(SILInstruction *barrier,
599
591
// it.
600
592
SmallPtrSet<AccessPath::PathNode, 16 > trivialLeaves;
601
593
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
+ }
609
607
610
608
for (auto *instruction = barrier; instruction != nullptr ;
611
609
instruction = instruction->getPreviousInstruction ()) {
@@ -752,16 +750,10 @@ bool HoistDestroys::checkFoldingBarrier(
752
750
// of the root storage which would be folded if folding were possible.
753
751
// Find its nontrivial product leaves and remove them from the set of
754
752
// 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
-
761
753
bool alreadySawLeaf = false ;
762
754
bool alreadySawTrivialSubleaf = false ;
763
- visitProductLeafAccessPathNodes (
764
- rootPath, address, typeExpansionContext, module ,
755
+ auto succeeded = visitProductLeafAccessPathNodes (
756
+ address, typeExpansionContext, module ,
765
757
[&](AccessPath::PathNode node, SILType ty) {
766
758
if (ty.isTrivial (*function)) {
767
759
bool inserted = !trivialLeaves.insert (node).second ;
@@ -771,6 +763,11 @@ bool HoistDestroys::checkFoldingBarrier(
771
763
bool erased = leaves.erase (node);
772
764
alreadySawLeaf = alreadySawLeaf || !erased;
773
765
});
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);
774
771
if (alreadySawLeaf) {
775
772
// We saw this non-trivial product leaf already. That means there are
776
773
// multiple load [copy]s or copy_addrs of at least one product leaf
0 commit comments