1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 ; RUN: llc -o - -verify-machineinstrs -O0 -global-isel -stop-after=localizer %s | FileCheck %s
3 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
4 target triple = "arm64-apple-ios5.0.0"
6 @var1 = common global i32 0, align 4
7 @var2 = common global i32 0, align 4
8 @var3 = common global i32 0, align 4
9 @var4 = common global i32 0, align 4
11 ; This is an ll test instead of MIR because -run-pass doesn't seem to support
12 ; initializing the target TTI which we need for this test.
14 ; Some of the instructions in entry block are dead after this pass so don't
15 ; strictly need to be checked for.
18 ; CHECK-LABEL: name: foo
20 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.3(0x40000000)
22 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
23 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2
24 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
25 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3
26 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
27 ; CHECK-NEXT: [[GV2:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1
28 ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[GV2]](p0) :: (dereferenceable load (s32) from @var1)
29 ; CHECK-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
30 ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[LOAD]](s32), [[C3]]
31 ; CHECK-NEXT: G_BRCOND [[ICMP]](s1), %bb.3
32 ; CHECK-NEXT: G_BR %bb.2
34 ; CHECK-NEXT: bb.2.if.then:
35 ; CHECK-NEXT: successors: %bb.3(0x80000000)
37 ; CHECK-NEXT: [[GV3:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2
38 ; CHECK-NEXT: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
39 ; CHECK-NEXT: G_STORE [[C4]](s32), [[GV3]](p0) :: (store (s32) into @var2)
40 ; CHECK-NEXT: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
41 ; CHECK-NEXT: [[GV4:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1
42 ; CHECK-NEXT: G_STORE [[C5]](s32), [[GV4]](p0) :: (store (s32) into @var1)
43 ; CHECK-NEXT: [[GV5:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3
44 ; CHECK-NEXT: G_STORE [[C4]](s32), [[GV5]](p0) :: (store (s32) into @var3)
45 ; CHECK-NEXT: G_STORE [[C5]](s32), [[GV4]](p0) :: (store (s32) into @var1)
46 ; CHECK-NEXT: G_BR %bb.3
48 ; CHECK-NEXT: bb.3.if.end:
49 ; CHECK-NEXT: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
50 ; CHECK-NEXT: $w0 = COPY [[C6]](s32)
51 ; CHECK-NEXT: RET_ReallyLR implicit $w0
53 %0 = load i32, ptr @var1, align 4
54 %cmp = icmp eq i32 %0, 1
55 br i1 %cmp, label %if.then, label %if.end
58 store i32 2, ptr @var2, align 4
59 store i32 3, ptr @var1, align 4
60 store i32 2, ptr @var3, align 4
61 store i32 3, ptr @var1, align 4
68 @tls_gv = common thread_local global i32 0, align 4
70 ; This test checks that we don't try to localize TLS variables on Darwin.
71 ; If the user happens to be inside a call sequence, we could end up rematerializing
72 ; below a physreg write, clobbering it (TLS accesses on Darwin need a function call).
73 ; For now, we check we don't localize at all. We could in theory make sure that
74 ; we don't localize into the middle of a call sequence instead.
75 define i32 @darwin_tls() {
76 ; CHECK-LABEL: name: darwin_tls
78 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.3(0x40000000)
80 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @tls_gv
81 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2
82 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
83 ; CHECK-NEXT: [[GV2:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1
84 ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[GV2]](p0) :: (dereferenceable load (s32) from @var1)
85 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
86 ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[LOAD]](s32), [[C1]]
87 ; CHECK-NEXT: G_BRCOND [[ICMP]](s1), %bb.3
88 ; CHECK-NEXT: G_BR %bb.2
90 ; CHECK-NEXT: bb.2.if.then:
91 ; CHECK-NEXT: successors: %bb.3(0x80000000)
93 ; CHECK-NEXT: [[LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[GV]](p0) :: (dereferenceable load (s32) from @tls_gv)
94 ; CHECK-NEXT: [[GV3:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2
95 ; CHECK-NEXT: G_STORE [[LOAD1]](s32), [[GV3]](p0) :: (store (s32) into @var2)
96 ; CHECK-NEXT: G_BR %bb.3
98 ; CHECK-NEXT: bb.3.if.end:
99 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
100 ; CHECK-NEXT: $w0 = COPY [[C2]](s32)
101 ; CHECK-NEXT: RET_ReallyLR implicit $w0
103 %0 = load i32, ptr @var1, align 4
104 %cmp = icmp eq i32 %0, 1
105 br i1 %cmp, label %if.then, label %if.end
108 %tls = load i32, ptr @tls_gv, align 4
109 store i32 %tls, ptr @var2, align 4
116 define i32 @imm_cost_too_large_cost_of_2() {
117 ; CHECK-LABEL: name: imm_cost_too_large_cost_of_2
119 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.4(0x40000000)
121 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2
122 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3
123 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
124 ; CHECK-NEXT: [[GV2:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1
125 ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[GV2]](p0) :: (dereferenceable load (s32) from @var1)
126 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 -2228259
127 ; CHECK-NEXT: [[CONSTANT_FOLD_BARRIER:%[0-9]+]]:_(s32) = G_CONSTANT_FOLD_BARRIER [[C1]]
128 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
129 ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[LOAD]](s32), [[C2]]
130 ; CHECK-NEXT: G_BRCOND [[ICMP]](s1), %bb.4
131 ; CHECK-NEXT: G_BR %bb.2
133 ; CHECK-NEXT: bb.2.if.then:
134 ; CHECK-NEXT: successors: %bb.3(0x80000000)
136 ; CHECK-NEXT: [[GV3:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2
137 ; CHECK-NEXT: G_STORE [[CONSTANT_FOLD_BARRIER]](s32), [[GV3]](p0) :: (store (s32) into @var2)
138 ; CHECK-NEXT: G_BR %bb.3
140 ; CHECK-NEXT: bb.3.if.then2:
141 ; CHECK-NEXT: successors: %bb.4(0x80000000)
143 ; CHECK-NEXT: [[GV4:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1
144 ; CHECK-NEXT: G_STORE [[CONSTANT_FOLD_BARRIER]](s32), [[GV4]](p0) :: (store (s32) into @var1)
145 ; CHECK-NEXT: G_BR %bb.4
147 ; CHECK-NEXT: bb.4.if.end:
148 ; CHECK-NEXT: [[GV5:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3
149 ; CHECK-NEXT: G_STORE [[CONSTANT_FOLD_BARRIER]](s32), [[GV5]](p0) :: (store (s32) into @var3)
150 ; CHECK-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
151 ; CHECK-NEXT: $w0 = COPY [[C3]](s32)
152 ; CHECK-NEXT: RET_ReallyLR implicit $w0
154 %0 = load i32, ptr @var1, align 4
155 %cst1 = bitcast i32 -2228259 to i32
156 %cmp = icmp eq i32 %0, 1
157 br i1 %cmp, label %if.then, label %if.end
160 store i32 %cst1, ptr @var2
164 store i32 %cst1, ptr @var1
168 store i32 %cst1, ptr @var3
172 define i64 @imm_cost_too_large_cost_of_4() {
173 ; CHECK-LABEL: name: imm_cost_too_large_cost_of_4
175 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.4(0x40000000)
177 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2_64
178 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3_64
179 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
180 ; CHECK-NEXT: [[GV2:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1_64
181 ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s64) = G_LOAD [[GV2]](p0) :: (dereferenceable load (s64) from @var1_64, align 4)
182 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 -2228259
183 ; CHECK-NEXT: [[CONSTANT_FOLD_BARRIER:%[0-9]+]]:_(s64) = G_CONSTANT_FOLD_BARRIER [[C1]]
184 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
185 ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[LOAD]](s64), [[C2]]
186 ; CHECK-NEXT: G_BRCOND [[ICMP]](s1), %bb.4
187 ; CHECK-NEXT: G_BR %bb.2
189 ; CHECK-NEXT: bb.2.if.then:
190 ; CHECK-NEXT: successors: %bb.3(0x80000000)
192 ; CHECK-NEXT: [[GV3:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2_64
193 ; CHECK-NEXT: G_STORE [[CONSTANT_FOLD_BARRIER]](s64), [[GV3]](p0) :: (store (s64) into @var2_64)
194 ; CHECK-NEXT: G_BR %bb.3
196 ; CHECK-NEXT: bb.3.if.then2:
197 ; CHECK-NEXT: successors: %bb.4(0x80000000)
199 ; CHECK-NEXT: [[GV4:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1_64
200 ; CHECK-NEXT: G_STORE [[CONSTANT_FOLD_BARRIER]](s64), [[GV4]](p0) :: (store (s64) into @var1_64)
201 ; CHECK-NEXT: G_BR %bb.4
203 ; CHECK-NEXT: bb.4.if.end:
204 ; CHECK-NEXT: [[GV5:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3_64
205 ; CHECK-NEXT: G_STORE [[CONSTANT_FOLD_BARRIER]](s64), [[GV5]](p0) :: (store (s64) into @var3_64)
206 ; CHECK-NEXT: [[C3:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
207 ; CHECK-NEXT: $x0 = COPY [[C3]](s64)
208 ; CHECK-NEXT: RET_ReallyLR implicit $x0
210 %0 = load i64, ptr @var1_64, align 4
211 %cst1 = bitcast i64 -2228259 to i64
212 %cmp = icmp eq i64 %0, 1
213 br i1 %cmp, label %if.then, label %if.end
216 store i64 %cst1, ptr @var2_64
220 store i64 %cst1, ptr @var1_64
224 store i64 %cst1, ptr @var3_64
228 define i64 @f64_imm_cost_too_high(double %a) {
229 ; CHECK-LABEL: name: f64_imm_cost_too_high
231 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.4(0x40000000)
232 ; CHECK-NEXT: liveins: $d0
234 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_FCONSTANT double 1.000000e-02
235 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2_64
236 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3_64
237 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
238 ; CHECK-NEXT: [[GV2:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1_64
239 ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s64) = G_LOAD [[GV2]](p0) :: (dereferenceable load (s64) from @var1_64, align 4)
240 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
241 ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[LOAD]](s64), [[C2]]
242 ; CHECK-NEXT: G_BRCOND [[ICMP]](s1), %bb.4
243 ; CHECK-NEXT: G_BR %bb.2
245 ; CHECK-NEXT: bb.2.if.then:
246 ; CHECK-NEXT: successors: %bb.3(0x80000000)
248 ; CHECK-NEXT: [[GV3:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2_64
249 ; CHECK-NEXT: G_STORE [[C]](s64), [[GV3]](p0) :: (store (s64) into @var2_64)
250 ; CHECK-NEXT: G_BR %bb.3
252 ; CHECK-NEXT: bb.3.if.then2:
253 ; CHECK-NEXT: successors: %bb.4(0x80000000)
255 ; CHECK-NEXT: [[GV4:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1_64
256 ; CHECK-NEXT: G_STORE [[C]](s64), [[GV4]](p0) :: (store (s64) into @var1_64)
257 ; CHECK-NEXT: G_BR %bb.4
259 ; CHECK-NEXT: bb.4.if.end:
260 ; CHECK-NEXT: [[GV5:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3_64
261 ; CHECK-NEXT: G_STORE [[C]](s64), [[GV5]](p0) :: (store (s64) into @var3_64)
262 ; CHECK-NEXT: [[C3:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
263 ; CHECK-NEXT: $x0 = COPY [[C3]](s64)
264 ; CHECK-NEXT: RET_ReallyLR implicit $x0
266 %0 = load i64, ptr @var1_64, align 4
267 %cmp = icmp eq i64 %0, 1
268 br i1 %cmp, label %if.then, label %if.end
271 store double 1.000000e-02, ptr @var2_64
275 store double 1.000000e-02, ptr @var1_64
279 store double 1.000000e-02, ptr @var3_64
283 define i64 @f64_imm_cheap(double %a) {
284 ; CHECK-LABEL: name: f64_imm_cheap
286 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.4(0x40000000)
287 ; CHECK-NEXT: liveins: $d0
289 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_FCONSTANT double 0.000000e+00
290 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2_64
291 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3_64
292 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
293 ; CHECK-NEXT: [[GV2:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1_64
294 ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s64) = G_LOAD [[GV2]](p0) :: (dereferenceable load (s64) from @var1_64, align 4)
295 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
296 ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[LOAD]](s64), [[C2]]
297 ; CHECK-NEXT: G_BRCOND [[ICMP]](s1), %bb.4
298 ; CHECK-NEXT: G_BR %bb.2
300 ; CHECK-NEXT: bb.2.if.then:
301 ; CHECK-NEXT: successors: %bb.3(0x80000000)
303 ; CHECK-NEXT: [[GV3:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2_64
304 ; CHECK-NEXT: [[C3:%[0-9]+]]:_(s64) = G_FCONSTANT double 0.000000e+00
305 ; CHECK-NEXT: G_STORE [[C3]](s64), [[GV3]](p0) :: (store (s64) into @var2_64)
306 ; CHECK-NEXT: G_BR %bb.3
308 ; CHECK-NEXT: bb.3.if.then2:
309 ; CHECK-NEXT: successors: %bb.4(0x80000000)
311 ; CHECK-NEXT: [[C4:%[0-9]+]]:_(s64) = G_FCONSTANT double 0.000000e+00
312 ; CHECK-NEXT: [[GV4:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1_64
313 ; CHECK-NEXT: G_STORE [[C4]](s64), [[GV4]](p0) :: (store (s64) into @var1_64)
314 ; CHECK-NEXT: G_BR %bb.4
316 ; CHECK-NEXT: bb.4.if.end:
317 ; CHECK-NEXT: [[GV5:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var3_64
318 ; CHECK-NEXT: [[C5:%[0-9]+]]:_(s64) = G_FCONSTANT double 0.000000e+00
319 ; CHECK-NEXT: G_STORE [[C5]](s64), [[GV5]](p0) :: (store (s64) into @var3_64)
320 ; CHECK-NEXT: [[C6:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
321 ; CHECK-NEXT: $x0 = COPY [[C6]](s64)
322 ; CHECK-NEXT: RET_ReallyLR implicit $x0
324 %0 = load i64, ptr @var1_64, align 4
325 %cmp = icmp eq i64 %0, 1
326 br i1 %cmp, label %if.then, label %if.end
329 store double 0.0, ptr @var2_64
333 store double 0.0, ptr @var1_64
337 store double 0.0, ptr @var3_64
341 @var1_64 = common global i64 0, align 4
342 @var2_64 = common global i64 0, align 4
343 @var3_64 = common global i64 0, align 4