[llvm] [LLVM][Intrinsics] Allow IIT fixed encoding table to be 32-bit (PR #178531)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 09:00:45 PST 2026
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/178531
>From 472ad3bc583478a352c9e7f8aba32d1d7819c5e9 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Wed, 28 Jan 2026 15:13:16 -0800
Subject: [PATCH] [LLVM][Intrinsics] Allow IIT fixed encoding table to be
32-bit
---
llvm/lib/IR/Intrinsics.cpp | 17 +++++++++++------
llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp | 11 ++++++-----
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index 48abead0929dd..039e9f47cb7f4 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -438,21 +438,26 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
void Intrinsic::getIntrinsicInfoTableEntries(
ID id, SmallVectorImpl<IITDescriptor> &T) {
- static_assert(sizeof(IIT_Table[0]) == 2,
- "Expect 16-bit entries in IIT_Table");
- // Check to see if the intrinsic's type was expressible by the table.
- uint16_t TableVal = IIT_Table[id - 1];
+ // Note that `FixedEncodingTy` is defined in IntrinsicImpl.inc.
+ constexpr unsigned FixedEncodingBits = sizeof(FixedEncodingTy) * CHAR_BIT;
+ constexpr unsigned MSBPosition = FixedEncodingBits - 1;
+ // Mask with all bits 1 except the most significant bit.
+ constexpr unsigned Mask = (1U << MSBPosition) - 1;
+
+ FixedEncodingTy TableVal = IIT_Table[id - 1];
// Decode the TableVal into an array of IITValues.
SmallVector<unsigned char> IITValues;
ArrayRef<unsigned char> IITEntries;
unsigned NextElt = 0;
- if (TableVal >> 15) {
+ // Check to see if the intrinsic's type was inlined in the fixed encoding
+ // table.
+ if (TableVal >> MSBPosition) {
// This is an offset into the IIT_LongEncodingTable.
IITEntries = IIT_LongEncodingTable;
// Strip sentinel bit.
- NextElt = TableVal & 0x7fff;
+ NextElt = TableVal & Mask;
} else {
// If the entry was encoded into a single word in the table itself, decode
// it from an array of nibbles to an array of bytes.
diff --git a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
index 9fed5920a019f..051bfa05b52a3 100644
--- a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
@@ -354,9 +354,9 @@ void IntrinsicEmitter::EmitGenerator(const CodeGenIntrinsicTable &Ints,
using FixedEncodingTy =
std::conditional_t<Use16BitFixedEncoding, uint16_t, uint32_t>;
constexpr unsigned FixedEncodingBits = sizeof(FixedEncodingTy) * CHAR_BIT;
+ constexpr unsigned MSBPosition = FixedEncodingBits - 1;
// Mask with all bits 1 except the most significant bit.
- const unsigned Mask = (1U << (FixedEncodingBits - 1)) - 1;
- const unsigned MSBPostion = FixedEncodingBits - 1;
+ constexpr unsigned Mask = (1U << MSBPosition) - 1;
StringRef FixedEncodingTypeName =
Use16BitFixedEncoding ? "uint16_t" : "uint32_t";
@@ -374,7 +374,7 @@ void IntrinsicEmitter::EmitGenerator(const CodeGenIntrinsicTable &Ints,
// Check to see if we can encode it into a 16/32 bit word.
std::optional<uint32_t> Result = encodePacked(TypeSig);
- if (Result && (*Result & Mask) == Result) {
+ if (Result && (*Result & Mask) == *Result) {
FixedEncodings.push_back(static_cast<FixedEncodingTy>(*Result));
continue;
}
@@ -389,7 +389,8 @@ void IntrinsicEmitter::EmitGenerator(const CodeGenIntrinsicTable &Ints,
OS << formatv(R"(// Global intrinsic function declaration type table.
#ifdef GET_INTRINSIC_GENERATOR_GLOBAL
-static constexpr {} IIT_Table[] = {{
+using FixedEncodingTy = {};
+static constexpr FixedEncodingTy IIT_Table[] = {{
)",
FixedEncodingTypeName);
@@ -410,7 +411,7 @@ static constexpr {} IIT_Table[] = {{
// Otherwise, emit the offset into the long encoding table. We emit it this
// way so that it is easier to read the offset in the .def file.
- OS << formatv("(1U<<{}) | {}, ", MSBPostion, Offset);
+ OS << formatv("(1U<<{}) | {}, ", MSBPosition, Offset);
}
OS << "0\n};\n\n";
More information about the llvm-commits
mailing list