Skip to content

Commit 7398591

Browse files
authored
[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.
1 parent 2bc22ea commit 7398591

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

llvm/lib/CodeGen/MachineFunctionSplitter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ static bool isColdBlock(const MachineBasicBlock &MBB,
129129
}
130130

131131
bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) {
132+
if (skipFunction(MF.getFunction()))
133+
return false;
134+
132135
// Do not split functions when -basic-block-sections=all is specified.
133136
if (MF.getTarget().getBBSectionsType() == llvm::BasicBlockSection::All)
134137
return false;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; REQUIRES: x86-registered-target
2+
3+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions -O0 -mfs-psi-cutoff=0 -mfs-count-threshold=10000 | FileCheck %s
4+
5+
;; Check that functions with optnone attribute are not split.
6+
; CHECK-LABEL: foo_optnone:
7+
; CHECK-NOT: .section .text.split.foo_optnone
8+
; CHECK-NOT: foo_optnone.cold:
9+
; CHECK: .LBB0_2:
10+
; CHECK: .size foo_optnone
11+
12+
define void @foo_optnone(i1 zeroext %0) nounwind optnone noinline !prof !14 !section_prefix !15 {
13+
entry:
14+
br i1 %0, label %hot, label %cold, !prof !17
15+
16+
hot:
17+
%1 = call i32 @bar()
18+
br label %exit
19+
20+
cold:
21+
%2 = call i32 @baz()
22+
br label %exit
23+
24+
exit:
25+
%3 = tail call i32 @qux()
26+
ret void
27+
}
28+
29+
declare i32 @bar()
30+
declare i32 @baz()
31+
declare i32 @qux()
32+
33+
!llvm.module.flags = !{!0}
34+
!0 = !{i32 1, !"ProfileSummary", !1}
35+
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
36+
!2 = !{!"ProfileFormat", !"InstrProf"}
37+
!3 = !{!"TotalCount", i64 10000}
38+
!4 = !{!"MaxCount", i64 10}
39+
!5 = !{!"MaxInternalCount", i64 1}
40+
!6 = !{!"MaxFunctionCount", i64 1000}
41+
!7 = !{!"NumCounts", i64 3}
42+
!8 = !{!"NumFunctions", i64 5}
43+
!9 = !{!"DetailedSummary", !10}
44+
!10 = !{!11, !12, !13}
45+
!11 = !{i32 10000, i64 100, i32 1}
46+
!12 = !{i32 999900, i64 100, i32 1}
47+
!13 = !{i32 999999, i64 1, i32 2}
48+
!14 = !{!"function_entry_count", i64 7000}
49+
!15 = !{!"function_section_prefix", !"hot"}
50+
!17 = !{!"branch_weights", i32 7000, i32 0}

0 commit comments

Comments
 (0)