aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrigory Pastukhov <99913765+grigorypas@users.noreply.github.com>2025-11-04 11:01:50 -0800
committerGitHub <noreply@github.com>2025-11-04 11:01:50 -0800
commit7398591148f4351b38404304d8e2acb80651aaf3 (patch)
treef6be82f9151293cd29c03fd2e49431ecb8893270
parent2bc22ea02edda5926f3e53f141def9bf212ac1db (diff)
downloadllvm-7398591148f4351b38404304d8e2acb80651aaf3.zip
llvm-7398591148f4351b38404304d8e2acb80651aaf3.tar.gz
llvm-7398591148f4351b38404304d8e2acb80651aaf3.tar.bz2
[CodeGen] Add skipFunction() check to MachineFunctionSplitter (#166260)
MachineFunctionSplitter was missing a skipFunction() check, causing it to incorrectly split functions that should be skipped (e.g., functions with optnone attribute). This patch adds an early skipFunction() check in runOnMachineFunction() to ensure these functions are never split, regardless of profile data availability or other splitting conditions.
-rw-r--r--llvm/lib/CodeGen/MachineFunctionSplitter.cpp3
-rw-r--r--llvm/test/CodeGen/Generic/machine-function-splitter-optnone.ll50
2 files changed, 53 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
index c31454a..b5d3092 100644
--- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
+++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
@@ -129,6 +129,9 @@ static bool isColdBlock(const MachineBasicBlock &MBB,
}
bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) {
+ if (skipFunction(MF.getFunction()))
+ return false;
+
// Do not split functions when -basic-block-sections=all is specified.
if (MF.getTarget().getBBSectionsType() == llvm::BasicBlockSection::All)
return false;
diff --git a/llvm/test/CodeGen/Generic/machine-function-splitter-optnone.ll b/llvm/test/CodeGen/Generic/machine-function-splitter-optnone.ll
new file mode 100644
index 0000000..67d2ad7
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/machine-function-splitter-optnone.ll
@@ -0,0 +1,50 @@
+; REQUIRES: x86-registered-target
+
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions -O0 -mfs-psi-cutoff=0 -mfs-count-threshold=10000 | FileCheck %s
+
+;; Check that functions with optnone attribute are not split.
+; CHECK-LABEL: foo_optnone:
+; CHECK-NOT: .section .text.split.foo_optnone
+; CHECK-NOT: foo_optnone.cold:
+; CHECK: .LBB0_2:
+; CHECK: .size foo_optnone
+
+define void @foo_optnone(i1 zeroext %0) nounwind optnone noinline !prof !14 !section_prefix !15 {
+entry:
+ br i1 %0, label %hot, label %cold, !prof !17
+
+hot:
+ %1 = call i32 @bar()
+ br label %exit
+
+cold:
+ %2 = call i32 @baz()
+ br label %exit
+
+exit:
+ %3 = tail call i32 @qux()
+ ret void
+}
+
+declare i32 @bar()
+declare i32 @baz()
+declare i32 @qux()
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"ProfileSummary", !1}
+!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
+!2 = !{!"ProfileFormat", !"InstrProf"}
+!3 = !{!"TotalCount", i64 10000}
+!4 = !{!"MaxCount", i64 10}
+!5 = !{!"MaxInternalCount", i64 1}
+!6 = !{!"MaxFunctionCount", i64 1000}
+!7 = !{!"NumCounts", i64 3}
+!8 = !{!"NumFunctions", i64 5}
+!9 = !{!"DetailedSummary", !10}
+!10 = !{!11, !12, !13}
+!11 = !{i32 10000, i64 100, i32 1}
+!12 = !{i32 999900, i64 100, i32 1}
+!13 = !{i32 999999, i64 1, i32 2}
+!14 = !{!"function_entry_count", i64 7000}
+!15 = !{!"function_section_prefix", !"hot"}
+!17 = !{!"branch_weights", i32 7000, i32 0}