[llvm-branch-commits] [llvm] 46dac42 - Revert "[llvm-diff] Compare TBAA and alias scope metadata (#238976)"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 16 13:55:43 PST 2026


Author: Jon Roelofs
Date: 2026-11-16T13:55:38-08:00
New Revision: 46dac4208fbed3a8a00f815c30aa5547cf93a34d

URL: https://github.com/llvm/llvm-project/commit/46dac4208fbed3a8a00f815c30aa5547cf93a34d
DIFF: https://github.com/llvm/llvm-project/commit/46dac4208fbed3a8a00f815c30aa5547cf93a34d.diff

LOG: Revert "[llvm-diff] Compare TBAA and alias scope metadata (#238976)"

This reverts commit e5b070e81126cf4aefa9965e54199a42211c2e5e.

Added: 
    

Modified: 
    llvm/tools/llvm-diff/lib/DiffConsumer.cpp
    llvm/tools/llvm-diff/lib/DiffConsumer.h
    llvm/tools/llvm-diff/lib/DifferenceEngine.cpp

Removed: 
    llvm/test/tools/llvm-diff/compare-aliasing-metadata.ll


################################################################################
diff  --git a/llvm/test/tools/llvm-
diff /compare-aliasing-metadata.ll b/llvm/test/tools/llvm-
diff /compare-aliasing-metadata.ll
deleted file mode 100644
index a6fb3557189509..00000000000000
--- a/llvm/test/tools/llvm-
diff /compare-aliasing-metadata.ll
+++ /dev/null
@@ -1,200 +0,0 @@
-; RUN: split-file %s %t
-; RUN: llvm-
diff  %t/a.ll %t/a.ll
-; RUN: not llvm-
diff  %t/a.ll %t/b.ll 2>&1 | FileCheck %s --strict-whitespace --implicit-check-not=same
-
-; CHECK-LABEL: in function changed_tag:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !tbaa !{!{"float", {{.*}}i64 0}{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 %v{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !tbaa !{!{"int", {{.*}}i64 0}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-; CHECK-LABEL: in function missing_tag:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   %v = load i32, ptr %p, align 4{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 %v{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !tbaa !{!{"int", {{.*}}i64 0}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-; CHECK-LABEL: in function changed_offset:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !tbaa !{!{"S", {{.*}}i64 4}{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 %v{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !tbaa !{!{"S", {{.*}}i64 0}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-; CHECK-LABEL: in function changed_scope:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   %v = load i32, ptr %p, align 4, !alias.scope !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !alias.scope !{!{..., !{..., "domain"}, "
diff erent"}}{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 %v{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !alias.scope !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !alias.scope !{!{..., !{..., "domain"}, "scope"}}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-; CHECK-LABEL: in function changed_noalias:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   %v = load i32, ptr %p, align 4, !noalias !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !noalias !{!{..., !{..., "domain"}, "scope"}}{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 %v{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !noalias !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !noalias !{!{..., !{..., "domain"}, "other"}}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-; CHECK-LABEL: in function same_tag_other_
diff erence:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   %v = load i32, ptr %q, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 %v{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-; CHECK-LABEL: in function 
diff erent_opcode:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   store i32 0, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 0{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-; CHECK-LABEL: in function same_tag_changed_noalias:
-; CHECK-NEXT: {{^}}  in block %0 / %0:
-; CHECK-NEXT: {{^}}    >   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}, !noalias !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !noalias !{!{..., !{..., "domain"}, "scope"}}{{$}}
-; CHECK-NEXT: {{^}}    >   ret i32 %v{{$}}
-; CHECK-NEXT: {{^}}    <   %v = load i32, ptr %p, align 4, !tbaa !{{[0-9]+}}, !noalias !{{[0-9]+}}{{$}}
-; CHECK-NEXT: {{^}}        !noalias !{!{..., !{..., "domain"}, "other"}}{{$}}
-; CHECK-NEXT: {{^}}    <   ret i32 %v{{$}}
-
-;--- a.ll
-define i32 @same_tag(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !0
-  ret i32 %v
-}
-
-define i32 @same_scope(ptr %p) {
-  %v = load i32, ptr %p, !alias.scope !10, !noalias !20
-  ret i32 %v
-}
-
-define i32 @changed_tag(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !0
-  ret i32 %v
-}
-
-define i32 @missing_tag(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !0
-  ret i32 %v
-}
-
-define i32 @changed_offset(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !4
-  ret i32 %v
-}
-
-define i32 @changed_scope(ptr %p) {
-  %v = load i32, ptr %p, !alias.scope !10
-  ret i32 %v
-}
-
-define i32 @changed_noalias(ptr %p) {
-  %v = load i32, ptr %p, !noalias !20
-  ret i32 %v
-}
-
-define i32 @same_tag_other_
diff erence(ptr %p, ptr %q) {
-  %v = load i32, ptr %p, !tbaa !0
-  ret i32 %v
-}
-
-define i32 @
diff erent_opcode(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !0
-  ret i32 %v
-}
-
-define i32 @same_tag_changed_noalias(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !0, !noalias !20
-  ret i32 %v
-}
-
-!0 = !{!1, !1, i64 0}
-!1 = !{!"int", !2, i64 0}
-!2 = !{!"omnipotent char", !3, i64 0}
-!3 = !{!"Simple C/C++ TBAA"}
-!4 = !{!5, !1, i64 0}
-!5 = !{!"S", !1, i64 0, !1, i64 4}
-!10 = !{!11}
-!11 = distinct !{!11, !12, !"scope"}
-!12 = distinct !{!12, !"domain"}
-!20 = !{!21}
-!21 = distinct !{!21, !12, !"other"}
-
-;--- b.ll
-define i32 @same_tag(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !0
-  ret i32 %v
-}
-
-define i32 @same_scope(ptr %p) {
-  %v = load i32, ptr %p, !alias.scope !10, !noalias !20
-  ret i32 %v
-}
-
-define i32 @changed_tag(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !6
-  ret i32 %v
-}
-
-define i32 @missing_tag(ptr %p) {
-  %v = load i32, ptr %p
-  ret i32 %v
-}
-
-define i32 @changed_offset(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !4
-  ret i32 %v
-}
-
-define i32 @changed_scope(ptr %p) {
-  %v = load i32, ptr %p, !alias.scope !30
-  ret i32 %v
-}
-
-define i32 @changed_noalias(ptr %p) {
-  %v = load i32, ptr %p, !noalias !10
-  ret i32 %v
-}
-
-define i32 @same_tag_other_
diff erence(ptr %p, ptr %q) {
-  %v = load i32, ptr %q, !tbaa !0
-  ret i32 %v
-}
-
-define i32 @
diff erent_opcode(ptr %p) {
-  store i32 0, ptr %p, !tbaa !6
-  ret i32 0
-}
-
-define i32 @same_tag_changed_noalias(ptr %p) {
-  %v = load i32, ptr %p, !tbaa !0, !noalias !10
-  ret i32 %v
-}
-
-!0 = !{!1, !1, i64 0}
-!1 = !{!"int", !2, i64 0}
-!2 = !{!"omnipotent char", !3, i64 0}
-!3 = !{!"Simple C/C++ TBAA"}
-!4 = !{!5, !1, i64 4}
-!5 = !{!"S", !1, i64 0, !1, i64 4}
-!6 = !{!7, !7, i64 0}
-!7 = !{!"float", !2, i64 0}
-!10 = !{!11}
-!11 = distinct !{!11, !12, !"scope"}
-!12 = distinct !{!12, !"domain"}
-!20 = !{!21}
-!21 = distinct !{!21, !12, !"other"}
-!30 = !{!31}
-!31 = distinct !{!31, !12, !"
diff erent"}

diff  --git a/llvm/tools/llvm-
diff /lib/DiffConsumer.cpp b/llvm/tools/llvm-
diff /lib/DiffConsumer.cpp
index 926b8e15718ff7..5ff9b3d76ac989 100644
--- a/llvm/tools/llvm-
diff /lib/DiffConsumer.cpp
+++ b/llvm/tools/llvm-
diff /lib/DiffConsumer.cpp
@@ -11,12 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "DiffConsumer.h"
-#include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Instructions.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Metadata.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/WithColor.h"
@@ -198,114 +193,10 @@ void DiffConsumer::logf(const LogBuilder &Log) {
   out << '\n';
 }
 
-/// The metadata kinds that are compared and displayed: TBAA and alias scopes.
-static constexpr unsigned AliasingMetadataKinds[] = {
-    LLVMContext::MD_tbaa, LLVMContext::MD_tbaa_struct,
-    LLVMContext::MD_alias_scope, LLVMContext::MD_noalias};
-
-/// Returns true if \p L and \p R have the same structure. Distinct nodes, such
-/// as alias scopes, are never equal by pointer, so they are matched pairwise.
-static bool
-isEquivalentMetadata(const Metadata *L, const Metadata *R,
-                     DenseMap<const MDNode *, const MDNode *> &Matched) {
-  if (L == R)
-    return true;
-  const auto *LN = dyn_cast_or_null<MDNode>(L);
-  const auto *RN = dyn_cast_or_null<MDNode>(R);
-  if (!LN || !RN || LN->getNumOperands() != RN->getNumOperands())
-    return false;
-  auto [It, Inserted] = Matched.try_emplace(LN, RN);
-  if (!Inserted)
-    return It->second == RN;
-  for (unsigned I = 0, E = LN->getNumOperands(); I != E; ++I)
-    if (!isEquivalentMetadata(LN->getOperand(I).get(), RN->getOperand(I).get(),
-                              Matched))
-      return false;
-  return true;
-}
-
-static bool hasSameMetadata(const Instruction *L, const Instruction *R,
-                            unsigned Kind) {
-  DenseMap<const MDNode *, const MDNode *> Matched;
-  return isEquivalentMetadata(L->getMetadata(Kind), R->getMetadata(Kind),
-                              Matched);
-}
-
-bool llvm::hasSameAliasingMetadata(const Instruction *L, const Instruction *R) {
-  return all_of(AliasingMetadataKinds,
-                [&](unsigned Kind) { return hasSameMetadata(L, R, Kind); });
-}
-
-/// Prints \p MD with its nested nodes expanded. A node that is already being
-/// printed is shown as "...".
-static void printMetadata(raw_ostream &OS, const Metadata *MD,
-                          SmallPtrSetImpl<const MDNode *> &Active) {
-  if (const auto *Node = dyn_cast<MDNode>(MD)) {
-    if (!Active.insert(Node).second) {
-      OS << "...";
-      return;
-    }
-    OS << "!{";
-    ListSeparator LS;
-    for (const MDOperand &Op : Node->operands()) {
-      OS << LS;
-      if (Op)
-        printMetadata(OS, Op.get(), Active);
-      else
-        OS << "null";
-    }
-    OS << '}';
-    Active.erase(Node);
-  } else if (const auto *Str = dyn_cast<MDString>(MD)) {
-    OS << '"' << Str->getString() << '"';
-  } else if (const auto *Const = dyn_cast<ConstantAsMetadata>(MD)) {
-    Const->getValue()->printAsOperand(OS);
-  }
-}
-
-/// Prints the aliasing metadata of \p I, one line for each kind that
-/// \p ShouldPrint accepts.
-static void printAliasingMetadata(raw_ostream &OS, unsigned Indent,
-                                  const Instruction *I,
-                                  function_ref<bool(unsigned)> ShouldPrint) {
-  SmallVector<StringRef> Names;
-  I->getContext().getMDKindNames(Names);
-  for (unsigned Kind : AliasingMetadataKinds) {
-    const MDNode *MD = I->getMetadata(Kind);
-    if (!MD || !ShouldPrint(Kind))
-      continue;
-    SmallPtrSet<const MDNode *, 8> Active;
-    OS.indent(Indent + 4) << '!' << Names[Kind] << ' ';
-    printMetadata(OS, MD, Active);
-    OS << '\n';
-  }
-}
-
 void DiffConsumer::logd(const DiffLogBuilder &Log) {
   header();
 
-  // Expand a kind of aliasing metadata of an instruction only if a 
diff ering
-  // instruction with the same opcode on the other side has 
diff erent metadata
-  // of that kind, and none has the same metadata.
-  unsigned NumLines = Log.getNumLines();
-  auto ShouldExpandMetadata = [&](const Instruction *X, unsigned Kind,
-                                  bool OtherIsLeft) {
-    DiffChange OtherKind = OtherIsLeft ? DC_left : DC_right;
-    bool HasCandidate = false;
-    for (unsigned J = 0; J != NumLines; ++J) {
-      if (Log.getLineKind(J) != OtherKind)
-        continue;
-      const Instruction *Y = OtherIsLeft ? Log.getLeft(J) : Log.getRight(J);
-      if (Y->getOpcode() != X->getOpcode())
-        continue;
-      if (hasSameMetadata(X, Y, Kind))
-        return false;
-      HasCandidate = true;
-    }
-    return HasCandidate;
-  };
-
-  for (unsigned I = 0, E = NumLines; I != E; ++I) {
+  for (unsigned I = 0, E = Log.getNumLines(); I != E; ++I) {
     indent();
     switch (Log.getLineKind(I)) {
     case DC_match:
@@ -318,11 +209,6 @@ void DiffConsumer::logd(const DiffLogBuilder &Log) {
       LeftColor << "< ";
       Log.getLeft(I)->print(LeftColor);
       LeftColor << '\n';
-      printAliasingMetadata(LeftColor, Indent, Log.getLeft(I),
-                            [&](unsigned Kind) {
-                              return ShouldExpandMetadata(
-                                  Log.getLeft(I), Kind, /*OtherIsLeft=*/false);
-                            });
       break;
     }
     case DC_right: {
@@ -330,11 +216,6 @@ void DiffConsumer::logd(const DiffLogBuilder &Log) {
       RightColor << "> ";
       Log.getRight(I)->print(RightColor);
       RightColor << '\n';
-      printAliasingMetadata(RightColor, Indent, Log.getRight(I),
-                            [&](unsigned Kind) {
-                              return ShouldExpandMetadata(Log.getRight(I), Kind,
-                                                          /*OtherIsLeft=*/true);
-                            });
       break;
     }
     }

diff  --git a/llvm/tools/llvm-
diff /lib/DiffConsumer.h b/llvm/tools/llvm-
diff /lib/DiffConsumer.h
index 181ef0a1b3e1b6..d4f339bd560f47 100644
--- a/llvm/tools/llvm-
diff /lib/DiffConsumer.h
+++ b/llvm/tools/llvm-
diff /lib/DiffConsumer.h
@@ -26,9 +26,6 @@ class StringRef;
   class Value;
   class Function;
 
-  /// Returns true if \p L and \p R have the same TBAA and alias scope metadata.
-  bool hasSameAliasingMetadata(const Instruction *L, const Instruction *R);
-
   /// The interface for consumers of 
diff erence data.
   class Consumer {
     virtual void anchor();

diff  --git a/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp b/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp
index e3cc4a35b7f3f7..5959a316383199 100644
--- a/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp
+++ b/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp
@@ -416,7 +416,7 @@ class FunctionDifferenceEngine {
   // assumption to be checked later in BlockDiffCandidates.
   bool 
diff (const Instruction *L, const Instruction *R, bool Complain,
             bool TryUnify, bool AllowAssumptions) {
-    // FIXME: metadata other than TBAA and alias scopes (if Complain is set)
+    // FIXME: metadata (if Complain is set)
     AssumptionContext ACValue = {L->getParent(), R->getParent()};
     // nullptr AssumptionContext disables assumption generation.
     const AssumptionContext *AC = AllowAssumptions ? &ACValue : nullptr;
@@ -433,12 +433,6 @@ class FunctionDifferenceEngine {
       return true;
     }
 
-    if (!hasSameAliasingMetadata(L, R)) {
-      if (Complain)
-        Engine.log("
diff erent aliasing metadata");
-      return true;
-    }
-
     if (isa<CmpInst>(L)) {
       if (cast<CmpInst>(L)->getPredicate()
             != cast<CmpInst>(R)->getPredicate()) {


        


More information about the llvm-branch-commits mailing list