1# RUN: llc -mtriple=aarch64--- -run-pass=machine-outliner \
2# RUN: -verify-machineinstrs %s -o - | FileCheck %s
3
4# Ensure that we don't outline from regions where x16, x17, or nzcv are live
5# across the outlining candidate. These values are allowed to be clobbered by,
6# say, the linker, in the presence of function calls. Thus, we can't outline
7# these, since the insertion of the outlined call could change the values of
8# these registers.
9--- |
10  ; No problematic register appears at all. Safe for outlining.
11  define void @reg_never_defined() #0 { ret void }
12
13  ; A problematic register is live, but after the candidate. Safe for outlining.
14  define void @reg_defined_after_candidate() #0 { ret void }
15
16  ; A problematic register is live before the candidate, but killed before
17  ; entry to the candidate. Safe for outlining.
18  define void @reg_killed_before_candidate() #0 { ret void }
19
20  ; Ensure that we never outline when any of the problematic registers we care
21  ; about are defined across the outlining candidate.
22  define void @x16_live() #0 { ret void }
23  define void @x17_live() #0 { ret void }
24  define void @nzcv_live() #0 { ret void }
25
26  ; Test a combination of the above behaviours.
27  ; [candidate] (1)
28  ; - define a bad register -
29  ; [candidate] (2)
30  ; - kill the bad register -
31  ; [candidate] (3)
32  ;
33  ; (1) and (3) should be outlined, while (2) should not be outlined.
34  define void @multiple_ranges() #0 { ret void }
35
36  attributes #0 = { noredzone }
37...
38---
39
40# There should be two calls to outlined functions here, since we haven't tripped
41# any of the cases above.
42name:           reg_never_defined
43tracksRegLiveness: true
44body:             |
45  bb.0:
46    ; CHECK-LABEL: bb.0:
47    ; CHECK: BL
48    liveins: $w8, $wzr
49    $w8 = ORRWri $wzr, 1
50    $w8 = ORRWri $wzr, 2
51    $w8 = ORRWri $wzr, 3
52    $w8 = ORRWri $wzr, 4
53  bb.1:
54    ; CHECK-LABEL: bb.1:
55    ; CHECK: BL
56    liveins: $w8, $wzr
57    $w8 = ORRWri $wzr, 1
58    $w8 = ORRWri $wzr, 2
59    $w8 = ORRWri $wzr, 3
60    $w8 = ORRWri $wzr, 4
61  bb.2:
62    RET undef $lr
63...
64---
65
66name:            reg_defined_after_candidate
67tracksRegLiveness: true
68body:             |
69  bb.0:
70    ; CHECK-LABEL: bb.0:
71    ; CHECK: BL
72    ; CHECK-NEXT: $x16 = ORRXri $x8, 5, implicit-def $x16, implicit-def $w16
73    liveins: $w8, $wzr
74    $w8 = ORRWri $wzr, 1
75    $w8 = ORRWri $wzr, 2
76    $w8 = ORRWri $wzr, 3
77    $w8 = ORRWri $wzr, 4
78    $x16 = ORRXri $x8, 5, implicit-def $x16, implicit-def $w16
79    $w8 = ORRWri $w16, 5
80    RET undef $lr
81...
82---
83
84name:            reg_killed_before_candidate
85tracksRegLiveness: true
86body:             |
87  bb.0:
88    ; CHECK-LABEL: bb.0:
89    ; CHECK: BL
90    liveins: $w8, $wzr, $x16
91    dead $x16 = ORRXri $x8, 6
92    $w8 = ORRWri $wzr, 1
93    $w8 = ORRWri $wzr, 2
94    $w8 = ORRWri $wzr, 3
95    $w8 = ORRWri $wzr, 4
96    RET undef $lr
97...
98---
99
100name:            x16_live
101tracksRegLiveness: true
102body:             |
103  bb.0:
104    ; CHECK-LABEL: bb.0:
105    ; CHECK-NOT: BL
106    liveins: $w8, $wzr, $x16
107    $w8 = ORRWri $wzr, 1
108    $w8 = ORRWri $wzr, 2
109    $w8 = ORRWri $wzr, 3
110    $w8 = ORRWri $wzr, 4
111  bb.1:
112    liveins: $x16
113    RET undef $lr
114...
115---
116
117name:            x17_live
118tracksRegLiveness: true
119body:             |
120  bb.0:
121    ; CHECK-LABEL: bb.0:
122    ; CHECK-NOT: BL
123    liveins: $w8, $wzr, $x17
124    $w8 = ORRWri $wzr, 1
125    $w8 = ORRWri $wzr, 2
126    $w8 = ORRWri $wzr, 3
127    $w8 = ORRWri $wzr, 4
128    $w8 = ORRWri $w17, 5
129    RET undef $lr
130...
131---
132
133name:            nzcv_live
134tracksRegLiveness: true
135body:             |
136  bb.0:
137    liveins: $w8, $wzr, $nzcv
138    ; CHECK-LABEL: bb.0:
139    ; CHECK-NOT: BL
140    $w8 = ORRWri $wzr, 1
141    $w8 = ORRWri $wzr, 2
142    $w8 = ORRWri $wzr, 3
143    $w8 = ORRWri $wzr, 4
144  bb.1:
145    liveins: $nzcv
146    RET undef $lr
147...
148---
149
150name:            multiple_ranges
151tracksRegLiveness: true
152body:             |
153  bb.0:
154    ; CHECK-LABEL: bb.0:
155    ; CHECK: BL
156    liveins: $w8, $wzr
157    $w8 = ORRWri $wzr, 1
158    $w8 = ORRWri $wzr, 2
159    $w8 = ORRWri $wzr, 3
160    $w8 = ORRWri $wzr, 4
161    $x16 = ORRXri $x8, 5, implicit-def $x16
162  bb.1:
163    ; CHECK-LABEL: bb.1:
164    ; CHECK-NOT: BL
165    liveins: $w8, $x16
166    $w8 = ORRWri $wzr, 1
167    $w8 = ORRWri $wzr, 2
168    $w8 = ORRWri $wzr, 3
169    $w8 = ORRWri $wzr, 4
170  bb.2:
171    ; CHECK-LABEL: bb.2:
172    ; CHECK: BL
173    liveins: $w8, $x16
174    dead $x16 = ORRXri $x8, 0
175    $w8 = ORRWri $wzr, 1
176    $w8 = ORRWri $wzr, 2
177    $w8 = ORRWri $wzr, 3
178    $w8 = ORRWri $wzr, 4
179  bb.3:
180    liveins: $w8
181    RET undef $lr
182...
183---
184