[X86][SSE] Added shuffle based integer zero extension tests.
[oota-llvm.git] / lib / IR / Metadata.cpp
index d5be35a53a0b143275819a4730f7c1eb3538b702..0ad3c5c04bae97a886c8167341a0273aa5b85dd9 100644 (file)
@@ -518,9 +518,23 @@ void MDNode::resolveCycles() {
   }
 }
 
+static bool hasSelfReference(MDNode *N) {
+  for (Metadata *MD : N->operands())
+    if (MD == N)
+      return true;
+  return false;
+}
+
+MDNode *MDNode::replaceWithPermanentImpl() {
+  if (hasSelfReference(this))
+    return replaceWithDistinctImpl();
+  return replaceWithUniquedImpl();
+}
+
 MDNode *MDNode::replaceWithUniquedImpl() {
   // Try to uniquify in place.
   MDNode *UniquedNode = uniquify();
+
   if (UniquedNode == this) {
     makeUniqued();
     return this;
@@ -633,6 +647,8 @@ template <class NodeTy> struct MDNode::HasCachedHash {
 };
 
 MDNode *MDNode::uniquify() {
+  assert(!hasSelfReference(this) && "Cannot uniquify a self-referencing node");
+
   // Try to insert into uniquing store.
   switch (getMetadataID()) {
   default: