[llvm] r223619 - IR: Revert r223618 behaviour of MDNode::concatenate()

Duncan P. N. Exon Smith dexonsmith at apple.com
Sun Dec 7 12:32:12 PST 2014


Author: dexonsmith
Date: Sun Dec  7 14:32:11 2014
New Revision: 223619

URL: http://llvm.org/viewvc/llvm-project?rev=223619&view=rev
Log:
IR: Revert r223618 behaviour of MDNode::concatenate()

r223618 including special handling of `MDNode::intersect()`: if the
first operand is a self-reference with the same operands you're trying
to return, return it instead.

Reuse that handling in `MDNode::concatenate()` in the hopes that it
fixes a polly test that seems to rely on the old behaviour [1].

[1]: http://lab.llvm.org:8011/builders/polly-amd64-linux/builds/25167

Modified:
    llvm/trunk/lib/IR/Metadata.cpp

Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=223619&r1=223618&r2=223619&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Sun Dec  7 14:32:11 2014
@@ -376,6 +376,25 @@ void MDNode::replaceOperand(MDNodeOperan
   Store.insert(N);
 }
 
+/// \brief Get a node, or a self-reference that looks like it.
+///
+/// Special handling for finding self-references, for use by \a
+/// MDNode::concatenate() and \a MDNode::intersect() to maintain behaviour from
+/// when self-referencing nodes were still uniqued.  If the first operand has
+/// the same operands as \c Ops, return the first operand instead.
+static MDNode *getOrSelfReference(LLVMContext &Context, ArrayRef<Value *> Ops) {
+  if (!Ops.empty())
+    if (MDNode *N = dyn_cast_or_null<MDNode>(Ops[0]))
+      if (N->getNumOperands() == Ops.size() && N == N->getOperand(0)) {
+        for (unsigned I = 1, E = Ops.size(); I != E; ++I)
+          if (Ops[I] != N->getOperand(I))
+            return MDNode::get(Context, Ops);
+        return N;
+      }
+
+  return MDNode::get(Context, Ops);
+}
+
 MDNode *MDNode::concatenate(MDNode *A, MDNode *B) {
   if (!A)
     return B;
@@ -391,7 +410,9 @@ MDNode *MDNode::concatenate(MDNode *A, M
   for (unsigned i = 0, ie = B->getNumOperands(); i != ie; ++i)
     Vals[j++] = B->getOperand(i);
 
-  return MDNode::get(A->getContext(), Vals);
+  // FIXME: This preserves long-standing behaviour, but is it really the right
+  // behaviour?  Or was that an unintended side-effect of node uniquing?
+  return getOrSelfReference(A->getContext(), Vals);
 }
 
 MDNode *MDNode::intersect(MDNode *A, MDNode *B) {
@@ -408,19 +429,9 @@ MDNode *MDNode::intersect(MDNode *A, MDN
       }
   }
 
-  // Handle alias scope self-references specially.
-  //
   // FIXME: This preserves long-standing behaviour, but is it really the right
   // behaviour?  Or was that an unintended side-effect of node uniquing?
-  if (!Vals.empty())
-    if (MDNode *N = dyn_cast_or_null<MDNode>(Vals[0]))
-      if (N->getNumOperands() == Vals.size() && N == N->getOperand(0)) {
-        for (unsigned I = 1, E = Vals.size(); I != E; ++I)
-          if (Vals[I] != N->getOperand(I))
-            return MDNode::get(A->getContext(), Vals);
-        return N;
-      }
-  return MDNode::get(A->getContext(), Vals);
+  return getOrSelfReference(A->getContext(), Vals);
 }
 
 MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {





More information about the llvm-commits mailing list