[llvm] [KeyInstr] Fix DILocation AtomGroup/Rank bitfield packing for MSVC (PR #138292)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 08:20:25 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Orlando Cazalet-Hyams (OCHyams)

<details>
<summary>Changes</summary>

Follow up to #<!-- -->133477.

As @<!-- -->nikic pointed out: We need to use uint64_t for both fields to get actual bit packing with msvc (https://c.godbolt.org/z/1f556c1zb).

The cast to u8 in hash_combine prevents an increase in compile time (+0.16% for stage1-O0-g on compile-time-tracker).

---
Full diff: https://github.com/llvm/llvm-project/pull/138292.diff


2 Files Affected:

- (modified) llvm/include/llvm/IR/DebugInfoMetadata.h (+1-1) 
- (modified) llvm/lib/IR/LLVMContextImpl.h (+2-2) 


``````````diff
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 91cda271f498b..0f6a206cab75f 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2237,7 +2237,7 @@ class DILocation : public MDNode {
   friend class MDNode;
 #ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
   uint64_t AtomGroup : 61;
-  uint8_t AtomRank : 3;
+  uint64_t AtomRank : 3;
 #endif
 
   DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index ad5fb802029fe..7b2ff6cf80972 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -316,7 +316,7 @@ template <> struct MDNodeKeyImpl<DILocation> {
   Metadata *InlinedAt;
   bool ImplicitCode;
   uint64_t AtomGroup : 61;
-  uint8_t AtomRank : 3;
+  uint64_t AtomRank : 3;
 
   MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
                 Metadata *InlinedAt, bool ImplicitCode, uint64_t AtomGroup,
@@ -338,7 +338,7 @@ template <> struct MDNodeKeyImpl<DILocation> {
 
   unsigned getHashValue() const {
     return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
-                        AtomRank);
+                        (uint8_t)AtomRank);
   }
 };
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/138292


More information about the llvm-commits mailing list