[llvm] [Transforms] Speed up SSAUpdater::FindExistingPHI (PR #100281)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 24 03:13:07 PDT 2024


================
@@ -418,21 +418,28 @@ class SSAUpdaterImpl {
         RecordMatchingPHIs(BlockList);
         break;
       }
-      // Match failed: clear all the PHITag values.
-      for (typename BlockListTy::iterator I = BlockList->begin(),
-             E = BlockList->end(); I != E; ++I)
-        (*I)->PHITag = nullptr;
     }
   }
 
   /// CheckIfPHIMatches - Check if a PHI node matches the placement and values
   /// in the BBMap.
   bool CheckIfPHIMatches(PhiT *PHI) {
     SmallVector<PhiT *, 20> WorkList;
+    SmallVector<BBInfo *, 20> TaggedBlocks;
     WorkList.push_back(PHI);
 
+    // Match failed: clear all the PHITag values. Only need to clear visited
+    // blocks.
+    auto OnFalseCleanup = [&]() {
+      for (BBInfo *TaggedBlock : TaggedBlocks) {
+        TaggedBlock->PHITag = nullptr;
+      }
+    };
----------------
nikic wrote:

I think it would be better to use make_scope_exit here and do a TaggedBlocks.clear() on the success path.

https://github.com/llvm/llvm-project/pull/100281


More information about the llvm-commits mailing list