summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp4
-rw-r--r--llvm/test/Linker/uniqued-distinct-cycles.ll14
2 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index d967e0a95c6..8aa546c7211 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -258,9 +258,11 @@ static Metadata *mapUniquedNode(const MDNode *Node,
// Create a temporary node upfront in case we have a metadata cycle.
auto ClonedMD = Node->clone();
- if (!remap(Node, ClonedMD.get(), Cycles, VM, Flags, TypeMapper, Materializer))
+ if (!remap(Node, ClonedMD.get(), Cycles, VM, Flags, TypeMapper, Materializer)) {
// No operands changed, so use the identity mapping.
+ ClonedMD->replaceAllUsesWith(const_cast<MDNode *>(Node));
return mapToSelf(VM, Node);
+ }
// At least one operand has changed, so uniquify the cloned node.
return mapToMetadata(VM, Node,
diff --git a/llvm/test/Linker/uniqued-distinct-cycles.ll b/llvm/test/Linker/uniqued-distinct-cycles.ll
new file mode 100644
index 00000000000..05cc80d7304
--- /dev/null
+++ b/llvm/test/Linker/uniqued-distinct-cycles.ll
@@ -0,0 +1,14 @@
+; RUN: llvm-link -o - %s | llvm-dis | FileCheck %s
+
+; CHECK: !named = !{!0, !2}
+!named = !{!0, !2}
+
+; CHECK: !0 = !{!1}
+; CHECK-NEXT: !1 = distinct !{!0}
+!0 = !{!1}
+!1 = distinct !{!0}
+
+; CHECK-NEXT: !2 = distinct !{!3}
+; CHECK-NEXT: !3 = !{!2}
+!2 = distinct !{!3}
+!3 = !{!2}
OpenPOWER on IntegriCloud