[llvm] [StaticDataLayout] Only emit JT prefixes if enabled (PR #228222)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 17:54:55 PDT 2026


https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/228222

>From 5b5e12c3fe3b38723203d4e42ec542b88ed951f6 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 1 Oct 2026 19:52:54 +0000
Subject: [PATCH] [StaticDataLayout] Only emit JT prefixes if enabled

Previously we were unconditionally emitting section prefixes for jump
tables. This meant that even with SDP disabled, we would end up with a
.rodata.unlikely section. This is somewhat confusing and also makes
ablation experiments harder.
---
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |  3 +-
 .../CodeGen/AArch64/jump-table-partition.ll   |  8 +++--
 llvm/test/CodeGen/X86/data-section-prefix.ll  |  4 +--
 .../CodeGen/X86/no-jt-prefix-sdp-disabled.ll  | 32 +++++++++++++++++++
 4 files changed, 41 insertions(+), 6 deletions(-)
 create mode 100644 llvm/test/CodeGen/X86/no-jt-prefix-sdp-disabled.ll

diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index d47b35cfa7bcf..34e275a2ad19f 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -700,7 +700,8 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
     if (Kind.isReadOnly() || Kind.isReadOnlyWithRel() || Kind.isData() ||
         Kind.isBSS()) {
       AddSectionPrefix =
-          !SectionPrefix.starts_with(".hot") || PreserveHotDataSectionPrefix;
+          TM.getEnableStaticDataPartitioning() &&
+          (!SectionPrefix.starts_with(".hot") || PreserveHotDataSectionPrefix);
     }
 
     if (AddSectionPrefix) {
diff --git a/llvm/test/CodeGen/AArch64/jump-table-partition.ll b/llvm/test/CodeGen/AArch64/jump-table-partition.ll
index e6eea5d12825d..a075f7494b2ad 100644
--- a/llvm/test/CodeGen/AArch64/jump-table-partition.ll
+++ b/llvm/test/CodeGen/AArch64/jump-table-partition.ll
@@ -7,19 +7,21 @@
 ; The static-data-splitter pass doesn't run.
 ; RUN: llc -mtriple=aarch64-unknown-linux-gnu -function-sections=true \
 ; RUN:     -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
-; RUN:     -unique-section-names=true %s -o - 2>&1 | FileCheck %s --check-prefixes=DEFAULT,COMM
+; RUN:     -unique-section-names=true -partition-static-data-sections \
+; RUN:     %s -o - 2>&1 | FileCheck %s --check-prefixes=DEFAULT,COMM
 
 ; Repeat the command with -preserve-hot-data-section-prefix=false
 ; RUN: llc -mtriple=aarch64-unknown-linux-gnu -function-sections=true \
 ; RUN:     -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
 ; RUN:     -preserve-hot-data-section-prefix=false \
-; RUN:     -unique-section-names=true %s -o - 2>&1 | FileCheck %s --check-prefixes=DEFNOHOT,COMM
+; RUN:     -unique-section-names=true -partition-static-data-sections \
+; RUN:     %s -o - 2>&1 | FileCheck %s --check-prefixes=DEFNOHOT,COMM
 
 ; DEFAULT: .section .rodata.hot.foo,"a", at progbits
 ; DEFNOHOT: .section .rodata.foo,"a", at progbits
 ; COMM:   .LJTI0_0:
-; COMM:   .LJTI0_1:
 ; COMM:   .LJTI0_2:
+; COMM:   .LJTI0_1:
 ; COMM:   .LJTI0_3:
 ; COMM: .section .rodata.func_without_profile,"a", at progbits
 ; COMM:   .LJTI1_0:
diff --git a/llvm/test/CodeGen/X86/data-section-prefix.ll b/llvm/test/CodeGen/X86/data-section-prefix.ll
index 36e0527eb3c06..b2e1dc22e8445 100644
--- a/llvm/test/CodeGen/X86/data-section-prefix.ll
+++ b/llvm/test/CodeGen/X86/data-section-prefix.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple x86_64-linux-gnu -data-sections %s -o - | FileCheck %s --check-prefix=ELF
-; RUN: llc -mtriple x86_64-linux-gnu -unique-section-names=0 -data-sections %s -o - | FileCheck %s --check-prefix=ELF-NOUNIQ
+; RUN: llc -mtriple x86_64-linux-gnu -data-sections -partition-static-data-sections %s -o - | FileCheck %s --check-prefix=ELF
+; RUN: llc -mtriple x86_64-linux-gnu -unique-section-names=0 -data-sections -partition-static-data-sections %s -o - | FileCheck %s --check-prefix=ELF-NOUNIQ
 
 ; RUN: llc -mtriple x86_64-windows-msvc -data-sections %s -o - | FileCheck %s --check-prefix=COFF-MSVC
 
diff --git a/llvm/test/CodeGen/X86/no-jt-prefix-sdp-disabled.ll b/llvm/test/CodeGen/X86/no-jt-prefix-sdp-disabled.ll
new file mode 100644
index 0000000000000..ac14cac1c9f91
--- /dev/null
+++ b/llvm/test/CodeGen/X86/no-jt-prefix-sdp-disabled.ll
@@ -0,0 +1,32 @@
+; RUN: llc %s -o - | FileCheck %s --check-prefix NO-PARTITION
+; RUN: llc %s -partition-static-data-sections -o - | FileCheck %s --check-prefix PARTITION
+
+; NO-PARTITION: .section        .rodata,"a", at progbits
+; PARTITION:    .section        .rodata.unlikely.,"a", at progbits
+
+target triple = "x86_64-grtev4-linux-gnu"
+
+define fastcc { i64, i64 } @monument_pass_9_25_26() #0 {
+  switch i32 poison, label %3 [
+    i32 16, label %3
+    i32 15, label %3
+    i32 12, label %3
+    i32 26, label %2
+    i32 18, label %1
+    i32 8, label %2
+    i32 6, label %2
+    i32 19, label %3
+    i32 17, label %3
+  ]
+
+1:                                                ; preds = %0
+  ret { i64, i64 } zeroinitializer
+
+2:                                                ; preds = %0, %0, %0
+  ret { i64, i64 } zeroinitializer
+
+3:                                                ; preds = %0, %0, %0, %0, %0, %0
+  ret { i64, i64 } zeroinitializer
+}
+
+attributes #0 = { cold }



More information about the llvm-commits mailing list