[llvm] [StructuralHashPrinter] Always print 16-digit hash (PR #101655)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 04:52:40 PDT 2024


https://github.com/s-barannikov created https://github.com/llvm/llvm-project/pull/101655

The hash may contain less than 14 significant digits, which caused the test to fail.

>From 2e26d158dc92f1008a44768f6badb7032c507f36 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Fri, 2 Aug 2024 14:49:53 +0300
Subject: [PATCH] [StructuralHashPrinter] Always print 16-digit hash

The hash may contain less than 14 significant digits,
which caused the test to fail.
---
 llvm/lib/Analysis/StructuralHash.cpp                  |  6 +++---
 .../StructuralHash/structural-hash-printer.ll         | 11 +++++------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/Analysis/StructuralHash.cpp b/llvm/lib/Analysis/StructuralHash.cpp
index 24985f0a9d314..3a2341fe59ad9 100644
--- a/llvm/lib/Analysis/StructuralHash.cpp
+++ b/llvm/lib/Analysis/StructuralHash.cpp
@@ -14,20 +14,20 @@
 #include "llvm/Analysis/StructuralHash.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/StructuralHash.h"
-#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Format.h"
 
 using namespace llvm;
 
 PreservedAnalyses StructuralHashPrinterPass::run(Module &M,
                                                  ModuleAnalysisManager &MAM) {
   OS << "Module Hash: "
-     << Twine::utohexstr(StructuralHash(M, EnableDetailedStructuralHash))
+     << format("%016" PRIx64, StructuralHash(M, EnableDetailedStructuralHash))
      << "\n";
   for (Function &F : M) {
     if (F.isDeclaration())
       continue;
     OS << "Function " << F.getName() << " Hash: "
-       << Twine::utohexstr(StructuralHash(F, EnableDetailedStructuralHash))
+       << format("%016" PRIx64, StructuralHash(F, EnableDetailedStructuralHash))
        << "\n";
   }
   return PreservedAnalyses::all();
diff --git a/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll b/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
index 569abae5567f7..5936199bf32f4 100644
--- a/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
+++ b/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
@@ -14,12 +14,11 @@ define i32 @f2(i32 %a) {
 	ret i32 %b
 }
 
-; CHECK: Module Hash: {{([a-z0-9]{14,})}}
-; CHECK-NEXT: Function f1 Hash: [[F1H:([a-z0-9]{14,})]]
+; CHECK: Module Hash: {{([a-f0-9]{16,})}}
+; CHECK-NEXT: Function f1 Hash: [[F1H:([a-f0-9]{16,})]]
 ; CHECK-NEXT: Function f2 Hash: [[F1H]]
 
-; DETAILED-HASH: Module Hash: {{([a-z0-9]{14,})}}
-; DETAILED-HASH-NEXT: Function f1 Hash: [[DF1H:([a-z0-9]{14,})]]
+; DETAILED-HASH: Module Hash: {{([a-f0-9]{16,})}}
+; DETAILED-HASH-NEXT: Function f1 Hash: [[DF1H:([a-f0-9]{16,})]]
 ; DETAILED-HASH-NOT: [[DF1H]]
-; DETAILED-HASH-NEXT: Function f2 Hash: {{([a-z0-9]{14,})}}
-
+; DETAILED-HASH-NEXT: Function f2 Hash: {{([a-f0-9]{16,})}}



More information about the llvm-commits mailing list