[llvm] [CodeGen] Compact cost table entries (PR #202836)

David Zbarsky via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 5 18:02:32 PDT 2026


https://github.com/dzbarsky updated https://github.com/llvm/llvm-project/pull/202836

>From 2cf5c41ae9549e817800ec71242d7e373f12c3ab Mon Sep 17 00:00:00 2001
From: David Zbarsky <dzbarsky at gmail.com>
Date: Tue, 9 Jun 2026 22:59:44 -0400
Subject: [PATCH] [CodeGen] Compact cost table entries

Store cost table operation numbers and common cost values in uint16_t fields while retaining MVT::SimpleValueType for MVT fields. Cost tables use aggregate initialization, so out-of-range operation and cost values are rejected as narrowing conversions. Keep the lookups as direct scalar comparisons.

Across the X86, AArch64, ARM, RISCV, and WebAssembly target transform objects, this removes 14,072 bytes, including 13,920 bytes from __TEXT,__const. A Darwin AArch64 Release opt configured with those five targets shrinks by 16,624 bytes, with __TEXT down 16,384 bytes, __TEXT,__const down 13,936 bytes, __DATA_CONST unchanged, and chained fixups unchanged.

All five direct consumers compile, all 354 AArch64, ARM, RISCV, WebAssembly, and X86 cost-model tests pass, a valid MVT::LAST_VALUETYPE initializer compiles, and explicit oversized operation and cost initializers fail compilation.
---
 llvm/include/llvm/CodeGen/CostTable.h | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/CostTable.h b/llvm/include/llvm/CodeGen/CostTable.h
index 490de79d18997..65790244f8986 100644
--- a/llvm/include/llvm/CodeGen/CostTable.h
+++ b/llvm/include/llvm/CodeGen/CostTable.h
@@ -17,17 +17,19 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/CodeGenTypes/MachineValueType.h"
+#include <cstdint>
 
 namespace llvm {
 
 /// Cost Table Entry
-template <typename CostType>
-struct CostTblEntryT {
-  int ISD;
+template <typename CostType> struct CostTblEntryT {
+  // Cost tables use aggregate initialization, so values that do not fit in
+  // these fields are rejected as narrowing conversions at compile time.
+  uint16_t ISD;
   MVT::SimpleValueType Type;
   CostType Cost;
 };
-using CostTblEntry = CostTblEntryT<unsigned>;
+using CostTblEntry = CostTblEntryT<uint16_t>;
 
 /// Find in cost table.
 template <class CostType>
@@ -51,14 +53,13 @@ CostTableLookup(const CostTblEntryT<CostType> (&Table)[N], int ISD, MVT Ty) {
 }
 
 /// Type Conversion Cost Table
-template <typename CostType>
-struct TypeConversionCostTblEntryT {
-  int ISD;
+template <typename CostType> struct TypeConversionCostTblEntryT {
+  uint16_t ISD;
   MVT::SimpleValueType Dst;
   MVT::SimpleValueType Src;
   CostType Cost;
 };
-using TypeConversionCostTblEntry = TypeConversionCostTblEntryT<unsigned>;
+using TypeConversionCostTblEntry = TypeConversionCostTblEntryT<uint16_t>;
 
 /// Find in type conversion cost table.
 template <class CostType>



More information about the llvm-commits mailing list