xref: /llvm-project/llvm/test/CodeGen/RISCV/machine-outliner-leaf-descendants.ll (revision 80df56e03b0455382cec51557bfc9f099d5c0a6f)
1; This test is mainly for the -outliner-leaf-descendants flag for MachineOutliner.
2;
3; ===================== -outliner-leaf-descendants=false =====================
4; MachineOutliner finds THREE key `OutlinedFunction` and outlines them. They are:
5;   ```
6;     mov     w0, #1
7;     mov     w1, #2
8;     mov     w2, #3
9;     mov     w3, #4
10;     mov     w4, #5
11;     mov     w5, #6 or #7 or #8
12;     b
13;   ```
14; Each has:
15;   - `SequenceSize=28` and `OccurrenceCount=2`
16;   - each Candidate has `CallOverhead=4` and `FrameOverhead=0`
17;   - `NotOutlinedCost=28*2=56` and `OutliningCost=4*2+28+0=36`
18;   - `Benefit=56-36=20` and `Priority=56/36=1.56`
19;
20; ===================== -outliner-leaf-descendants=true =====================
21; MachineOutliner finds a FOURTH key `OutlinedFunction`, which is:
22;   ```
23;   mov     w0, #1
24;   mov     w1, #2
25;   mov     w2, #3
26;   mov     w3, #4
27;   mov     w4, #5
28;   ```
29; This corresponds to an internal node that has ZERO leaf children, but SIX leaf descendants.
30; It has:
31;   - `SequenceSize=20` and `OccurrenceCount=6`
32;   - each Candidate has `CallOverhead=12` and `FrameOverhead=4`
33;   - `NotOutlinedCost=20*6=120` and `OutliningCost=12*6+20+4=96`
34;   - `Benefit=120-96=24` and `Priority=120/96=1.25`
35;
36; The FOURTH `OutlinedFunction` has lower _priority_ compared to the first THREE `OutlinedFunction`.
37; Hence, we use `-outliner-benefit-threshold=22` to check if the FOURTH `OutlinedFunction` is identified.
38
39; RUN: llc %s -enable-machine-outliner=always -outliner-leaf-descendants=false -mattr=+m -mtriple=riscv64 -filetype=obj -o %t
40; RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=CHECK-BASELINE
41
42; RUN: llc %s -enable-machine-outliner=always -outliner-leaf-descendants=false -mattr=+m -mtriple=riscv64 -outliner-benefit-threshold=22 -filetype=obj -o %t
43; RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=CHECK-NO-CANDIDATE
44
45; RUN: llc %s -enable-machine-outliner=always -outliner-leaf-descendants=false -mattr=+m -mtriple=riscv32 -filetype=obj -o %t
46; RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=CHECK-BASELINE
47
48; RUN: llc %s -enable-machine-outliner=always -outliner-leaf-descendants=false -mattr=+m -mtriple=riscv32 -outliner-benefit-threshold=22 -filetype=obj -o %t
49; RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=CHECK-NO-CANDIDATE
50
51; RUN: llc %s -enable-machine-outliner=always -outliner-leaf-descendants=true -mattr=+m -mtriple=riscv64 -filetype=obj -o %t
52; RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=CHECK-LEAF-DESCENDANTS
53
54; RUN: llc %s -enable-machine-outliner=always -outliner-leaf-descendants=true -mattr=+m -mtriple=riscv64 -outliner-benefit-threshold=22 -filetype=obj -o %t
55; RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=CHECK-LEAF-DESCENDANTS
56
57
58declare i32 @_Z3fooiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef)
59
60define i32 @_Z2f1v() minsize {
61  %1 = tail call i32 @_Z3fooiiii(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, i32 noundef 6)
62  ret i32 %1
63}
64
65define i32 @_Z2f2v() minsize {
66  %1 = tail call i32 @_Z3fooiiii(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, i32 noundef 6)
67  ret i32 %1
68}
69
70define i32 @_Z2f3v() minsize {
71  %1 = tail call i32 @_Z3fooiiii(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, i32 noundef 7)
72  ret i32 %1
73}
74
75define i32 @_Z2f4v() minsize {
76  %1 = tail call i32 @_Z3fooiiii(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, i32 noundef 7)
77  ret i32 %1
78}
79
80define i32 @_Z2f5v() minsize {
81  %1 = tail call i32 @_Z3fooiiii(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, i32 noundef 8)
82  ret i32 %1
83}
84
85define i32 @_Z2f6v() minsize {
86  %1 = tail call i32 @_Z3fooiiii(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, i32 noundef 8)
87  ret i32 %1
88}
89
90; CHECK-BASELINE: <OUTLINED_FUNCTION_0>:
91; CHECK-BASELINE-NEXT: 	li	a0, 0x1
92; CHECK-BASELINE-NEXT:	li	a1, 0x2
93; CHECK-BASELINE-NEXT:	li	a2, 0x3
94; CHECK-BASELINE-NEXT:	li	a3, 0x4
95; CHECK-BASELINE-NEXT:	li	a4, 0x5
96; CHECK-BASELINE-NEXT:	li	a5, 0x6
97; CHECK-BASELINE-NEXT:	auipc	t1, 0x0
98; CHECK-BASELINE-NEXT:	jr	t1
99
100; CHECK-BASELINE: <OUTLINED_FUNCTION_1>:
101; CHECK-BASELINE-NEXT:	li	a0, 0x1
102; CHECK-BASELINE-NEXT:	li	a1, 0x2
103; CHECK-BASELINE-NEXT:	li	a2, 0x3
104; CHECK-BASELINE-NEXT:	li	a3, 0x4
105; CHECK-BASELINE-NEXT:	li	a4, 0x5
106; CHECK-BASELINE-NEXT:	li	a5, 0x8
107; CHECK-BASELINE-NEXT:	auipc	t1, 0x0
108; CHECK-BASELINE-NEXT:	jr	t1
109
110; CHECK-BASELINE: <OUTLINED_FUNCTION_2>:
111; CHECK-BASELINE-NEXT:	li	a0, 0x1
112; CHECK-BASELINE-NEXT:	li	a1, 0x2
113; CHECK-BASELINE-NEXT:	li	a2, 0x3
114; CHECK-BASELINE-NEXT:	li	a3, 0x4
115; CHECK-BASELINE-NEXT:	li	a4, 0x5
116; CHECK-BASELINE-NEXT:	li	a5, 0x7
117; CHECK-BASELINE-NEXT:	auipc	t1, 0x0
118; CHECK-BASELINE-NEXT:	jr	t1
119
120; CHECK-LEAF-DESCENDANTS: <OUTLINED_FUNCTION_0>:
121; CHECK-LEAF-DESCENDANTS-NEXT:	li	a0, 0x1
122; CHECK-LEAF-DESCENDANTS-NEXT:	li	a1, 0x2
123; CHECK-LEAF-DESCENDANTS-NEXT:	li	a2, 0x3
124; CHECK-LEAF-DESCENDANTS-NEXT:	li	a3, 0x4
125; CHECK-LEAF-DESCENDANTS-NEXT:	li	a4, 0x5
126; CHECK-LEAF-DESCENDANTS-NEXT:	jr	t0
127
128; CHECK-LEAF-DESCENDANTS-NOT: <OUTLINED_FUNCTION_1>:
129
130; CHECK-NO-CANDIDATE-NOT: <OUTLINED_FUNCTION_0>:
131