[llvm] [AArch64] Coalesce the perfect-shuffle table (PR #202617)

David Zbarsky via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 9 06:59:38 PDT 2026


https://github.com/dzbarsky created https://github.com/llvm/llvm-project/pull/202617

Define PerfectShuffleTable as an inline constexpr hidden variable instead of a translation-unit-local static variable. AArch64ISelLowering, AArch64PostLegalizerLowering, and AArch64TargetTransformInfo then reference one linker-coalesced definition while retaining direct constant-indexed access.

The generated table contents remain byte-for-byte identical. The three duplicate definitions account for 26,248 bytes each; the linked __TEXT,__const section shrinks by 26,240 bytes and consumer __text is unchanged. A stripped AArch64-only llc shrinks from 48,207,312 to 48,190,816 bytes, saving 16,496 bytes.

Validate the seven existing perfect-shuffle RUN pipelines, five baseline/candidate llc configurations with byte-identical assembly, byte-identical consumer machine code, the generated table checksum, and all 6,561 generated entries. Update PerfectShuffle.cpp so regenerated headers retain the inline definition.

Work towards #202616

>From 07bb764ffb918f1ddb9eb1a67647110546c86a9d Mon Sep 17 00:00:00 2001
From: David Zbarsky <dzbarsky at gmail.com>
Date: Mon, 8 Jun 2026 23:37:49 -0400
Subject: [PATCH] [AArch64] Coalesce the perfect-shuffle table

Define PerfectShuffleTable as an inline constexpr hidden variable instead of a translation-unit-local static variable. AArch64ISelLowering, AArch64PostLegalizerLowering, and AArch64TargetTransformInfo then reference one linker-coalesced definition while retaining direct constant-indexed access.

The generated table contents remain byte-for-byte identical. The three duplicate definitions account for 26,248 bytes each; the linked __TEXT,__const section shrinks by 26,240 bytes and consumer __text is unchanged. A stripped AArch64-only llc shrinks from 48,207,312 to 48,190,816 bytes, saving 16,496 bytes.

Validate the seven existing perfect-shuffle RUN pipelines, five baseline/candidate llc configurations with byte-identical assembly, byte-identical consumer machine code, the generated table checksum, and all 6,561 generated entries. Update PerfectShuffle.cpp so regenerated headers retain the inline definition.
---
 llvm/lib/Target/AArch64/AArch64PerfectShuffle.h | 3 ++-
 llvm/utils/PerfectShuffle/PerfectShuffle.cpp    | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h b/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h
index 12a53aad08aa8..23374921e5d14 100644
--- a/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h
+++ b/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h
@@ -25,7 +25,8 @@ namespace llvm {
 // 2084 entries have cost 3
 
 // This table is 6561*4 = 26244 bytes in size.
-static const unsigned PerfectShuffleTable[6561 + 1] = {
+LLVM_LIBRARY_VISIBILITY inline constexpr unsigned
+    PerfectShuffleTable[6561 + 1] = {
     135053414U,  // <0,0,0,0>: Cost 1 vdup0 LHS
     2080972802U, // <0,0,0,1>: Cost 2 ins <0,0,u,1>, lane 2
     1679065190U, // <0,0,0,2>: Cost 2 vuzpl <0,2,0,2>, LHS
diff --git a/llvm/utils/PerfectShuffle/PerfectShuffle.cpp b/llvm/utils/PerfectShuffle/PerfectShuffle.cpp
index ba8292db027d1..3b9a5d8583b0c 100644
--- a/llvm/utils/PerfectShuffle/PerfectShuffle.cpp
+++ b/llvm/utils/PerfectShuffle/PerfectShuffle.cpp
@@ -441,7 +441,8 @@ int main() {
 
   // Build up the table to emit.
   std::cout << "\n// This table is 6561*4 = 26244 bytes in size.\n";
-  std::cout << "static const unsigned PerfectShuffleTable[6561+1] = {\n";
+  std::cout << "LLVM_LIBRARY_VISIBILITY inline constexpr unsigned "
+               "PerfectShuffleTable[6561+1] = {\n";
 
   for (unsigned i = 0; i != 0x8889; ++i) {
     if (!isValidMask(i)) continue;



More information about the llvm-commits mailing list