From: Duncan P. N. Exon Smith <dexonsmith@apple.com>
Date: Mon, 3 Aug 2015 03:45:32 +0000 (+0000)
Subject: ValueMapper: Only check for cycles if operands change
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=836170e4d552e9ab6ad06f014942ebc732be9cff;p=oota-llvm.git

ValueMapper: Only check for cycles if operands change

This is a minor optimization to only check for unresolved operands
inside `mapDistinctNode()` if the operands have actually changed.  This
shouldn't really cause any change in behaviour.  I didn't actually see a
slowdown in a profile, I was just poking around nearby and saw the
opportunity.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243866 91177308-0d34-0410-b5e6-96231b3b80d8
---

diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp
index 2de19285505..8daf5468805 100644
--- a/lib/Transforms/Utils/ValueMapper.cpp
+++ b/lib/Transforms/Utils/ValueMapper.cpp
@@ -227,13 +227,14 @@ static Metadata *mapDistinctNode(const MDNode *Node,
   assert(Node->isDistinct() && "Expected distinct node");
 
   MDNode *NewMD = MDNode::replaceWithDistinct(Node->clone());
-  remap(Node, NewMD, Cycles, VM, Flags, TypeMapper, Materializer);
 
-  // Track any cycles beneath this node.
-  for (Metadata *Op : NewMD->operands())
-    if (auto *Node = dyn_cast_or_null<MDNode>(Op))
-      if (!Node->isResolved())
-        Cycles.push_back(Node);
+  // Remap the operands.  If any change, track those that could be involved in
+  // uniquing cycles.
+  if (remap(Node, NewMD, Cycles, VM, Flags, TypeMapper, Materializer))
+    for (Metadata *Op : NewMD->operands())
+      if (auto *Node = dyn_cast_or_null<MDNode>(Op))
+        if (!Node->isResolved())
+          Cycles.push_back(Node);
 
   return NewMD;
 }