[llvm] [CodeGenTypes] Use lookup table for MVT::getVectorVT (NFC) (PR #220309)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 2 01:53:10 PDT 2026


================
@@ -546,15 +534,41 @@ namespace llvm {
     }
 
     static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable) {
-      if (IsScalable)
-        return getScalableVectorVT(VT, NumElements);
-      return getVectorVT(VT, NumElements);
+      constexpr unsigned MaxNumElements = 4096;
+      constexpr unsigned NumSlots = 32;
+      struct VecVTTable {
+        // Maps number of elements to a compact slot index. Only element counts
+        // used by any vector type get a slot; others stay 0. There are only a
+        // small number (< 32) of distinct element counts for vector types.
+        uint8_t Slots[MaxNumElements + 1] = {};
+        // The vector MVTs, indexed by [IsScalable][ElementType][Slot]. Element
+        // types are scalar MVTs, so only those need an entry. Other entries
+        // stay INVALID_SIMPLE_VALUE_TYPE.
+        SimpleValueType Tys[2][FIRST_VECTOR_VALUETYPE][NumSlots] = {};
+      };
+      static constexpr VecVTTable VecVTs = [] {
+        VecVTTable T{};
+        uint8_t NextSlot = 1;
+#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy)    \
+    if (Vec && !Tup && !T.Slots[NElem])                                        \
+      T.Slots[NElem] = NextSlot++;
+#include "llvm/CodeGen/GenVT.inc"
+#undef GET_VT_ATTR
+#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy)    \
+    if (Vec && !Tup)                                                           \
+      T.Tys[Sc][EltTy][T.Slots[NElem]] = Ty;
+#include "llvm/CodeGen/GenVT.inc"
+#undef GET_VT_ATTR
+        return T;
+      }();
----------------
fhahn wrote:

It should be fairly easy I think. I am not sure where the best place for it would be. For now I just added a new `llvm/lib/CodeGenTypes/MachineValueType.cpp` file. Not sure if there would be a better place.

This slightly helps with stage2-clang builds https://llvm-compile-time-tracker.com/compare.php?from=d102568559c145b9775d4bc99f05cb3acb3454e9&to=d467df045aa4198073b709312b46c43e1be38f82&stat=instructions:u

WDYT?


With PCH disabled, the original version clang stage2 build was ~ 0.2% (https://llvm-compile-time-tracker.com/compare.php?from=3ae7356a55ae9faef51d32a5b09f243ed671bee7&to=e7c2e4fb3b84758f4f21db8c0ae6e5fc62520898&stat=instructions:u) . The current version is 0.35% faster (https://llvm-compile-time-tracker.com/compare.php?from=3ae7356a55ae9faef51d32a5b09f243ed671bee7&to=0a5c1689d26bd7abaac87538fa2b0a1682618af8&stat=instructions%3Au)

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


More information about the llvm-commits mailing list