[llvm] [llubi] explain Byte.TagValue encoding trick (PR #201863)

Ralf Jung via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 08:58:32 PDT 2026


https://github.com/RalfJung updated https://github.com/llvm/llvm-project/pull/201863

>From eea7673fd798b7f2007e01201162b7b265f0f40d Mon Sep 17 00:00:00 2001
From: Ralf Jung <post at ralfj.de>
Date: Fri, 5 Jun 2026 17:20:59 +0200
Subject: [PATCH] [llubi] explain Byte.TagValue encoding trick

---
 llvm/tools/llubi/lib/Value.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/llvm/tools/llubi/lib/Value.h b/llvm/tools/llubi/lib/Value.h
index 71ee212b4299e..7d58fbba07b61 100644
--- a/llvm/tools/llubi/lib/Value.h
+++ b/llvm/tools/llubi/lib/Value.h
@@ -30,11 +30,21 @@ class AnyValue;
 /// stores the concrete bit value. The tag mask bit indicates whether it is a
 /// pointer bit, and the tag value bit is used for provenance tracking of
 /// pointers.
+///
+/// Note that the idealized interpreter would store a full pointer tag for every
+/// single pointer bit, as well as the position of that bit in the pointer. The
+/// provenance is preserved as the bit is copied around, and when a sequence of
+/// bytes is eventually converted back to a pointer, all bits must be in the
+/// original order and have the same provenance. However, that would be
+/// prohibiticely expensive. So instead, we rely on randimized ptr-sized tags.
+/// This means that if bits get reordered, or if bits from different pointers
+/// get mixed, then the result is unlikely to be a valid tag.
 struct Byte {
   uint8_t ConcreteMask;
   uint8_t Value;
   uint8_t TagMask;  // A mask to indicate which bits are pointer bits.
-  uint8_t TagValue; // Part of the tag for provenance tracking of pointers.
+  uint8_t TagValue; // For each pointer bit, the corresponding bit of the tag
+                    // for provenance tracking.
 
   static Byte poison() { return Byte{0, 0, 0, 0}; }
   static Byte undef() { return Byte{0, 255, 0, 0}; }



More information about the llvm-commits mailing list