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

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 9 07:51:03 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: David Zbarsky (dzbarsky)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/202617.diff


2 Files Affected:

- (modified) llvm/lib/Target/AArch64/AArch64PerfectShuffle.h (+4-1) 
- (modified) llvm/utils/PerfectShuffle/PerfectShuffle.cpp (+4-1) 


``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h b/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h
index 12a53aad08aa8..37a92a028ff84 100644
--- a/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h
+++ b/llvm/lib/Target/AArch64/AArch64PerfectShuffle.h
@@ -25,7 +25,10 @@ namespace llvm {
 // 2084 entries have cost 3
 
 // This table is 6561*4 = 26244 bytes in size.
-static const unsigned PerfectShuffleTable[6561 + 1] = {
+// clang-format off
+LLVM_LIBRARY_VISIBILITY inline constexpr unsigned
+    PerfectShuffleTable[6561 + 1] = {
+    // clang-format on
     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..72bd6c005c60b 100644
--- a/llvm/utils/PerfectShuffle/PerfectShuffle.cpp
+++ b/llvm/utils/PerfectShuffle/PerfectShuffle.cpp
@@ -441,7 +441,10 @@ 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 << "// clang-format off\n"
+               "LLVM_LIBRARY_VISIBILITY inline constexpr unsigned\n"
+               "    PerfectShuffleTable[6561 + 1] = {\n"
+               "    // clang-format on\n";
 
   for (unsigned i = 0; i != 0x8889; ++i) {
     if (!isValidMask(i)) continue;

``````````

</details>


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


More information about the llvm-commits mailing list