[llvm] llvm-reduce: Avoid double map lookup (PR #133447)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 28 07:17:19 PDT 2025


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/133447

Check if insert succeeded or not. This would change behavior
if there are recursive MDNodes, but I'm not sure those are a thing.

>From b1a59017800aea0ba0e383a6e59f65790e5a0928 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 28 Mar 2025 21:15:59 +0700
Subject: [PATCH] llvm-reduce: Avoid double map lookup

Check if insert succeeded or not. This would change behavior
if there are recursive MDNodes, but I'm not sure those are a thing.
---
 llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
index 38352d6342d4f..9dcf722fd1d90 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
@@ -39,7 +39,7 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
     MDNode *MD = ToLook.back();
     ToLook.pop_back();
 
-    if (Visited.count(MD))
+    if (!Visited.insert(MD))
       continue;
 
     // Determine if the current MDNode is DebugInfo
@@ -55,8 +55,6 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
     for (Metadata *Op : MD->operands())
       if (MDNode *OMD = dyn_cast_or_null<MDNode>(Op))
         ToLook.push_back(OMD);
-
-    Visited.insert(MD);
   }
 
   for (auto &T : Tuples) {



More information about the llvm-commits mailing list