1# RUN: llc -mtriple=aarch64--- -run-pass=prologepilog -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s
2--- |
3
4  @x = common global i32 0, align 4
5
6  define void @baz() #0 {
7    ret void
8  }
9
10  define i32 @main() #0 {
11    ret i32 0
12  }
13
14  define void @bar(i32 %a) #0 {
15    ret void
16  }
17
18  attributes #0 = { noinline noredzone "no-frame-pointer-elim"="true" }
19...
20---
21# This test ensures that we
22# - Create outlined functions
23# - Don't outline anything to do with LR or W30
24# - Save LR when it's not available
25# - Don't outline stack instructions when we might need to save + restore
26# - Functions whose addresses are taken can still be outlined
27#
28# CHECK-LABEL: name: main
29
30# CHECK: BL @OUTLINED_FUNCTION_[[F0:[0-9]+]]
31# CHECK-NEXT: $lr = ORRXrs $xzr, $x[[REG:[0-9]+]], 0
32# CHECK-NEXT: $x16 = ADDXri $sp, 48, 0
33# CHECK-NEXT: STRHHroW $w16, $x9, $w30, 1, 1
34# CHECK-NEXT: $lr = ORRXri $xzr, 1
35
36# CHECK: BL @OUTLINED_FUNCTION_[[F0]]
37# CHECK-NEXT: $lr = ORRXrs $xzr, $x[[REG]], 0
38# CHECK-NEXT: $x16 = ADDXri $sp, 48, 0
39# CHECK-NEXT: STRHHroW $w16, $x9, $w30, 1, 1
40# CHECK-NEXT: $lr = ORRXri $xzr, 1
41
42# CHECK: BL @OUTLINED_FUNCTION_[[F0]]
43# CHECK-NEXT: $lr = ORRXrs $xzr, $x[[REG]], 0
44# CHECK-NEXT: $x16 = ADDXri $sp, 48, 0
45# CHECK-NEXT: STRHHroW $w16, $x9, $w30, 1, 1
46# CHECK-NEXT: $lr = ORRXri $xzr, 1
47name:            main
48tracksRegLiveness: true
49body:             |
50  bb.0:
51    $sp = frame-setup SUBXri $sp, 16, 0
52    renamable $x9 = ADRP target-flags(aarch64-page) @bar
53    $x9 = ORRXri $xzr, 1
54    $w16 = ORRWri $wzr, 1
55    $w30 = ORRWri $wzr, 1
56    $lr = ORRXri $xzr, 1
57
58    $x20, $x19 = LDPXi $sp, 10
59    $w16 = ORRWri $wzr, 1
60    $w16 = ORRWri $wzr, 1
61    $w16 = ORRWri $wzr, 1
62    $w16 = ORRWri $wzr, 1
63    $w16 = ORRWri $wzr, 1
64    $w16 = ORRWri $wzr, 1
65    renamable $x9 = ADRP target-flags(aarch64-page) @x
66    $x16 = ADDXri $sp, 48, 0;
67    STRHHroW $w16, $x9, $w30, 1, 1
68    $lr = ORRXri $xzr, 1
69    $w3 = ORRWri $wzr, 1993
70
71    $x20, $x19 = LDPXi $sp, 10
72    $w16 = ORRWri $wzr, 1
73    $w16 = ORRWri $wzr, 1
74    $w16 = ORRWri $wzr, 1
75    $w16 = ORRWri $wzr, 1
76    $w16 = ORRWri $wzr, 1
77    $w16 = ORRWri $wzr, 1
78    renamable $x9 = ADRP target-flags(aarch64-page) @x
79    $x16 = ADDXri $sp, 48, 0;
80    STRHHroW $w16, $x9, $w30, 1, 1
81    $lr = ORRXri $xzr, 1
82
83    $w4 = ORRWri $wzr, 1994
84
85    $x20, $x19 = LDPXi $sp, 10
86    $w16 = ORRWri $wzr, 1
87    $w16 = ORRWri $wzr, 1
88    $w16 = ORRWri $wzr, 1
89    $w16 = ORRWri $wzr, 1
90    $w16 = ORRWri $wzr, 1
91    $w16 = ORRWri $wzr, 1
92    renamable $x9 = ADRP target-flags(aarch64-page) @x
93    $x16 = ADDXri $sp, 48, 0;
94    STRHHroW $w16, $x9, $w30, 1, 1
95    $lr = ORRXri $xzr, 1
96
97    $sp = ADDXri $sp, 16, 0
98    RET undef $lr
99
100...
101---
102# This test ensures that we can avoid saving LR when it's available.
103# It also makes sure that KILL instructions don't impact outlining.
104# CHECK-LABEL: bb.1:
105# CHECK-NOT: BL @baz, implicit-def dead $lr, implicit $sp
106# CHECK: BL @OUTLINED_FUNCTION_[[F1:[0-9]+]], implicit-def $lr, implicit $sp
107# CHECK-NEXT: $w17 = ORRWri $wzr, 2
108# CHECK-NEXT: BL @OUTLINED_FUNCTION_[[F1]], implicit-def $lr, implicit $sp
109# CHECK-NEXT: $w8 = ORRWri $wzr, 0
110# CHECK-NOT: $w17 = KILL renamable $w17, implicit killed $w17
111name:            bar
112tracksRegLiveness: true
113body:             |
114  bb.0:
115    liveins: $w0, $lr, $w8
116    $sp = frame-setup SUBXri $sp, 32, 0
117    $fp = frame-setup ADDXri $sp, 16, 0
118
119  bb.1:
120    BL @baz, implicit-def dead $lr, implicit $sp
121    $w17 = ORRWri $wzr, 1
122    $w17 = ORRWri $wzr, 1
123    $w17 = KILL renamable $w17, implicit killed $w17
124    $w17 = ORRWri $wzr, 1
125    $w17 = ORRWri $wzr, 1
126    BL @baz, implicit-def dead $lr, implicit $sp
127    $w17 = ORRWri $wzr, 1
128    $w17 = ORRWri $wzr, 1
129    $w17 = ORRWri $wzr, 2
130    BL @baz, implicit-def dead $lr, implicit $sp
131    $w17 = ORRWri $wzr, 1
132    $w17 = ORRWri $wzr, 1
133    $w17 = ORRWri $wzr, 1
134    $w17 = ORRWri $wzr, 1
135    BL @baz, implicit-def dead $lr, implicit $sp
136    $w17 = ORRWri $wzr, 1
137    $w17 = ORRWri $wzr, 1
138    $w8 = ORRWri $wzr, 0
139
140  bb.2:
141    $w15 = ORRWri $wzr, 1
142    $w15 = ORRWri $wzr, 1
143    $w15 = ORRWri $wzr, 1
144    $w15 = ORRWri $wzr, 1
145    $x15 = ADDXri $sp, 48, 0;
146    $w9 = ORRWri $wzr, 0
147    $w15 = ORRWri $wzr, 1
148    $w15 = ORRWri $wzr, 1
149    $w15 = ORRWri $wzr, 1
150    $w15 = ORRWri $wzr, 1
151    $x15 = ADDXri $sp, 48, 0;
152    $w8 = ORRWri $wzr, 0
153
154  bb.3:
155    $fp, $lr = LDPXi $sp, 2
156    $sp = ADDXri $sp, 32, 0
157    RET undef $lr
158
159...
160---
161name:            baz
162tracksRegLiveness: true
163body:             |
164  bb.0:
165    liveins: $w0, $lr, $w8
166    RET undef $lr
167
168# CHECK-LABEL: name:            OUTLINED_FUNCTION_{{[0-9]}}
169# CHECK=LABEL: name:            OUTLINED_FUNCTION_{{[1-9]}}
170