[llvm] [CodeGen] Increase offset when calculating MBB hash (PR #196536)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 06:51:34 PDT 2026


https://github.com/e-kud created https://github.com/llvm/llvm-project/pull/196536

Initially I was refactoring the test to not constantly update the hash values for new GlobalISel nodes but I noticed that Offset is always zero and assumed it should've been increased after each MBB. Fixing the constant offset during MBB hash calculation.

>From 1ad4b3d7cf52fe1514985355fe26379953f56971 Mon Sep 17 00:00:00 2001
From: Evgenii Kudriashov <evgenii.kudriashov at intel.com>
Date: Fri, 8 May 2026 04:40:16 -0700
Subject: [PATCH] [CodeGen] Increase offset when calculating hash in
 MachineBlockHashInfoAnalysis

Initially I was refactoring the test to not constantly update the hash
values for new GlobalISel nodes but I noticed that Offset is always zero
and assumed it should've been increased after each MBB. Fixing the
constant offset during MBB hash calculation.
---
 llvm/lib/CodeGen/MachineBlockHashInfo.cpp    |  3 ++-
 llvm/test/CodeGen/X86/machine-block-hash.mir | 19 +++++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineBlockHashInfo.cpp b/llvm/lib/CodeGen/MachineBlockHashInfo.cpp
index 27110b014d2ec..626a45277ff03 100644
--- a/llvm/lib/CodeGen/MachineBlockHashInfo.cpp
+++ b/llvm/lib/CodeGen/MachineBlockHashInfo.cpp
@@ -82,8 +82,9 @@ MachineBlockHashInfoResult::MachineBlockHashInfoResult(
   // Initialize hash components
   for (const MachineBasicBlock &MBB : F) {
     auto &HashInfo = HashInfos[&MBB];
+    Offset += MBB.size();
     // offset of the machine basic block
-    HashInfo.Offset = Offset + MBB.size();
+    HashInfo.Offset = Offset;
     // Hashing opcodes
     HashInfo.OpcodeHash = hashBlock(MBB, /*HashOperands=*/false);
     // Hash complete instructions
diff --git a/llvm/test/CodeGen/X86/machine-block-hash.mir b/llvm/test/CodeGen/X86/machine-block-hash.mir
index 0b39e072728be..281548654933e 100644
--- a/llvm/test/CodeGen/X86/machine-block-hash.mir
+++ b/llvm/test/CodeGen/X86/machine-block-hash.mir
@@ -3,8 +3,10 @@
 name:            foo
 body:             |
   ; HASH-LABEL: Machine Block Hash Info for function: foo
-  ; HASH-NEXT:  BB#0: 0xf33ebf30f33e0002
-  ; HASH-NEXT:  BB#1: 0xf33ee99ef33e0002
+  ; HASH-NEXT:  BB#0: [[#%#.4x,NB0:]][[#%.4x,INS:]][[#%.4x,OP0:]][[#%.4x,OFF0:]]
+  ; HASH-NOT:   [[#INS]]
+  ; HASH-NOT:   [[#OFF0]]
+  ; HASH-NEXT:  BB#1: [[#NB0]][[#%.4x,]][[#OP0]][[#%.4x,]]
   bb.0:
     $eax = MOV32ri 1
     RET 0
@@ -17,8 +19,10 @@ body:             |
 name:            func_mbb
 body:             |
   ; HASH-LABEL: Machine Block Hash Info for function: func_mbb
-  ; HASH-NEXT:  BB#0: 0xf60abf30f33e0002
-  ; HASH-NEXT:  BB#1: 0xf60ae99ef33e0002
+  ; HASH-NEXT:  BB#0: [[#%#.4x,NB1:]][[#%.4x,INS:]][[#OP0]][[#%.4x,OFF1:]]
+  ; HASH-NOT:   [[#INS]]
+  ; HASH-NOT:   [[#OFF1]]
+  ; HASH-NEXT:  BB#1: [[#NB1]][[#%.4x,]][[#OP0]][[#%.4x,]]
   bb.0:
     successors: %bb.1
     $eax = MOV32ri 1
@@ -32,7 +36,8 @@ body:             |
 name:            func_global
 body:             |
   ; HASH-LABEL: Machine Block Hash Info for function: func_global
-  ; HASH-NEXT:  BB#0: 0x7e32df2f7e320002
+  ; HASH-NOT:   [[#OP0]]
+  ; HASH-NEXT:  BB#0: [[#%#.8x,]][[#%.4x,OP1:]][[#%.4x,]]
   bb.0:
     $rax = MOV64rm $rip, 1, $noreg, @foo, $noreg
     RET 0
@@ -41,7 +46,9 @@ body:             |
 name:            func_fp
 body:             |
   ; HASH-LABEL: Machine Block Hash Info for function: func_fp
-  ; HASH-NEXT:  BB#0: 0x3e6b0e5c3e6b0002
+  ; HASH-NOT:   [[#OP0]]
+  ; HASH-NOT:   [[#OP1]]
+  ; HASH-NEXT:  BB#0: [[#%#.16x,]]
   bb.0:
     $xmm0 = MOVSSrm $rip, 1, $noreg, %const.0, $noreg
     RET 0



More information about the llvm-commits mailing list