[llvm] r243866 - ValueMapper: Only check for cycles if operands change

Duncan P. N. Exon Smith dexonsmith at apple.com
Sun Aug 2 20:45:32 PDT 2015


Author: dexonsmith
Date: Sun Aug  2 22:45:32 2015
New Revision: 243866

URL: http://llvm.org/viewvc/llvm-project?rev=243866&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=243866&r1=243865&r2=243866&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Sun Aug  2 22:45:32 2015
@@ -227,13 +227,14 @@ static Metadata *mapDistinctNode(const M
   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;
 }





More information about the llvm-commits mailing list