[llvm] 263e4f2 - [NFC][LLVM] Simplify IIT encoding for scalable vectors (#191737)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 05:04:36 PDT 2026


Author: Rahul Joshi
Date: 2026-04-23T05:04:31-07:00
New Revision: 263e4f22fd1417c3ab6de7f16e39ba30c20340be

URL: https://github.com/llvm/llvm-project/commit/263e4f22fd1417c3ab6de7f16e39ba30c20340be
DIFF: https://github.com/llvm/llvm-project/commit/263e4f22fd1417c3ab6de7f16e39ba30c20340be.diff

LOG: [NFC][LLVM] Simplify IIT encoding for scalable vectors (#191737)

Currently, scalable vectors are represented as an `IIT_SCALABLE_VEC`
token in the IIT info table, followed by a IIT encoding for the vector.
This requires remembering the last token seen when decoding the IIT
table and passing that into the recursive call to decode the vector.
Instead, change the representation to use:

```
IIT_V<Size>, IIT_SCALABLE_VEC (optional), Element Type
```

This allows decoding the scalable vector type without having to pass the
last token seen in `DecodeIITType` calls.

Added: 
    

Modified: 
    llvm/include/llvm/IR/Intrinsics.td
    llvm/lib/IR/Intrinsics.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index b958057104050..afcf21af115a5 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -394,8 +394,8 @@ class LLVMType<ValueType vt> {
          "Invalid IIT encoding for vector type v" # vt.nElem # vt.ElementType;
 
   list<int> Sig = !listconcat(
-    !if(vt.isScalable, [IIT_SCALABLE_VEC.Number], []),
     !foreach(iit, IIT_Vecs, iit.Number),
+    !if(vt.isScalable, [IIT_SCALABLE_VEC.Number], []),
     !foreach(iit, IITs,     iit.Number));
 }
 

diff  --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index d04c9e02234a1..06fe799a205db 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -206,11 +206,17 @@ static_assert(IIT_Done == 0, "IIT_Done expected to be 0");
 
 static void
 DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
-              IIT_Info LastInfo,
               SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) {
   using namespace Intrinsic;
 
-  bool IsScalableVector = LastInfo == IIT_SCALABLE_VEC;
+  auto IsScalableVector = [&]() {
+    IIT_Info NextInfo = IIT_Info(Infos[NextElt]);
+    if (NextInfo != IIT_SCALABLE_VEC)
+      return false;
+    // Eat the IIT_SCALABLE_VEC token.
+    ++NextElt;
+    return true;
+  };
 
   IIT_Info Info = IIT_Info(Infos[NextElt++]);
 
@@ -279,68 +285,68 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
     OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
     return;
   case IIT_V1:
-    OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V2:
-    OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V3:
-    OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V4:
-    OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V6:
-    OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V8:
-    OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V10:
-    OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V16:
-    OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V32:
-    OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V64:
-    OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V128:
-    OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V256:
-    OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V512:
-    OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V1024:
-    OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V2048:
-    OutputTable.push_back(IITDescriptor::getVector(2048, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(2048, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_V4096:
-    OutputTable.push_back(IITDescriptor::getVector(4096, IsScalableVector));
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
+    OutputTable.push_back(IITDescriptor::getVector(4096, IsScalableVector()));
+    DecodeIITType(NextElt, Infos, OutputTable);
     return;
   case IIT_EXTERNREF:
     OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
@@ -404,7 +410,7 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
         IITDescriptor::get(IITDescriptor::Struct, StructElts));
 
     for (unsigned i = 0; i != StructElts; ++i)
-      DecodeIITType(NextElt, Infos, Info, OutputTable);
+      DecodeIITType(NextElt, Infos, OutputTable);
     return;
   }
   case IIT_SUBDIVIDE2_ARG: {
@@ -425,16 +431,14 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
         IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
     return;
   }
-  case IIT_SCALABLE_VEC: {
-    DecodeIITType(NextElt, Infos, Info, OutputTable);
-    return;
-  }
   case IIT_VEC_OF_BITCASTS_TO_INT: {
     unsigned OverloadIndex = Infos[NextElt++];
     OutputTable.push_back(
         IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
     return;
   }
+  case IIT_SCALABLE_VEC:
+    break;
   }
   llvm_unreachable("unhandled");
 }
@@ -487,9 +491,9 @@ void Intrinsic::getIntrinsicInfoTableEntries(
   }
 
   // Okay, decode the table into the output vector of IITDescriptors.
-  DecodeIITType(NextElt, IITEntries, IIT_Done, T);
+  DecodeIITType(NextElt, IITEntries, T);
   while (IITEntries[NextElt] != IIT_Done)
-    DecodeIITType(NextElt, IITEntries, IIT_Done, T);
+    DecodeIITType(NextElt, IITEntries, T);
 }
 
 static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,


        


More information about the llvm-commits mailing list