1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -mtriple aarch64-unknown-unknown -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=DEFAULT,CHECK
3 # RUN: llc -mtriple aarch64-apple-darwin -code-model=large -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=LARGE-MACHO,CHECK
4 # RUN: llc -mtriple aarch64-apple-darwin -code-model=small -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=SMALL-MACHO,CHECK
5 # RUN: llc -mtriple aarch64-linux-elf -code-model=large -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=LARGE-ELF,CHECK
6 # RUN: llc -mtriple aarch64-linux-elf -code-model=tiny -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=TINY,CHECK
7 # RUN: llc -mtriple aarch64-windows-coff -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=WINDOWS,CHECK
9 # Each of these tests has a trivial pattern for folding a G_PTR_ADD into a
12 # Check that given different code models/target features, we do/don't fold.
15 @external_linkage = external hidden global i32
16 @common_linkage = common local_unnamed_addr global i32 0, align 4
17 @internal_linkage = internal unnamed_addr global i32 0, align 4
18 @extern_weak_linkage = extern_weak hidden global i32
19 @dll_import = external dllimport global i32
21 define void @test_external_linkage() { ret void }
22 define void @test_internal_linkage() { ret void }
23 define void @test_common_linkage() { ret void }
24 define void @test_extern_weak_linkage() { ret void }
25 define void @never_fold_tagged_globals() #0 { ret void }
26 define void @test_dll_import() { ret void }
28 attributes #0 = { "target-features"="+tagged-globals" }
31 name: test_external_linkage
33 tracksRegLiveness: true
34 machineFunctionInfo: {}
37 ; Large + Mach-O goes via GOT, so we can't fold.
39 ; DEFAULT-LABEL: name: test_external_linkage
40 ; DEFAULT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @external_linkage + 1
41 ; DEFAULT: $x0 = COPY [[GV]](p0)
42 ; DEFAULT: RET_ReallyLR implicit $x0
43 ; LARGE-MACHO-LABEL: name: test_external_linkage
44 ; LARGE-MACHO: %global:_(p0) = G_GLOBAL_VALUE @external_linkage
45 ; LARGE-MACHO: %imm:_(s64) = G_CONSTANT i64 1
46 ; LARGE-MACHO: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
47 ; LARGE-MACHO: $x0 = COPY %ptr_add(p0)
48 ; LARGE-MACHO: RET_ReallyLR implicit $x0
49 ; SMALL-MACHO-LABEL: name: test_external_linkage
50 ; SMALL-MACHO: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @external_linkage + 1
51 ; SMALL-MACHO: $x0 = COPY [[GV]](p0)
52 ; SMALL-MACHO: RET_ReallyLR implicit $x0
53 ; LARGE-ELF-LABEL: name: test_external_linkage
54 ; LARGE-ELF: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @external_linkage + 1
55 ; LARGE-ELF: $x0 = COPY [[GV]](p0)
56 ; LARGE-ELF: RET_ReallyLR implicit $x0
57 ; TINY-LABEL: name: test_external_linkage
58 ; TINY: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @external_linkage + 1
59 ; TINY: $x0 = COPY [[GV]](p0)
60 ; TINY: RET_ReallyLR implicit $x0
61 ; WINDOWS-LABEL: name: test_external_linkage
62 ; WINDOWS: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @external_linkage + 1
63 ; WINDOWS: $x0 = COPY [[GV]](p0)
64 ; WINDOWS: RET_ReallyLR implicit $x0
65 %global:_(p0) = G_GLOBAL_VALUE @external_linkage
66 %imm:_(s64) = G_CONSTANT i64 1
67 %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
68 $x0 = COPY %ptr_add(p0)
69 RET_ReallyLR implicit $x0
73 name: test_internal_linkage
75 tracksRegLiveness: true
76 machineFunctionInfo: {}
79 ; Large + Mach-O goes via GOT, so we can't fold.
81 ; DEFAULT-LABEL: name: test_internal_linkage
82 ; DEFAULT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @internal_linkage + 1
83 ; DEFAULT: $x0 = COPY [[GV]](p0)
84 ; DEFAULT: RET_ReallyLR implicit $x0
85 ; LARGE-MACHO-LABEL: name: test_internal_linkage
86 ; LARGE-MACHO: %global:_(p0) = G_GLOBAL_VALUE @internal_linkage
87 ; LARGE-MACHO: %imm:_(s64) = G_CONSTANT i64 1
88 ; LARGE-MACHO: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
89 ; LARGE-MACHO: $x0 = COPY %ptr_add(p0)
90 ; LARGE-MACHO: RET_ReallyLR implicit $x0
91 ; SMALL-MACHO-LABEL: name: test_internal_linkage
92 ; SMALL-MACHO: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @internal_linkage + 1
93 ; SMALL-MACHO: $x0 = COPY [[GV]](p0)
94 ; SMALL-MACHO: RET_ReallyLR implicit $x0
95 ; LARGE-ELF-LABEL: name: test_internal_linkage
96 ; LARGE-ELF: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @internal_linkage + 1
97 ; LARGE-ELF: $x0 = COPY [[GV]](p0)
98 ; LARGE-ELF: RET_ReallyLR implicit $x0
99 ; TINY-LABEL: name: test_internal_linkage
100 ; TINY: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @internal_linkage + 1
101 ; TINY: $x0 = COPY [[GV]](p0)
102 ; TINY: RET_ReallyLR implicit $x0
103 ; WINDOWS-LABEL: name: test_internal_linkage
104 ; WINDOWS: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @internal_linkage + 1
105 ; WINDOWS: $x0 = COPY [[GV]](p0)
106 ; WINDOWS: RET_ReallyLR implicit $x0
107 %global:_(p0) = G_GLOBAL_VALUE @internal_linkage
108 %imm:_(s64) = G_CONSTANT i64 1
109 %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
110 $x0 = COPY %ptr_add(p0)
111 RET_ReallyLR implicit $x0
115 name: test_common_linkage
117 tracksRegLiveness: true
118 machineFunctionInfo: {}
121 ; DEFAULT-LABEL: name: test_common_linkage
122 ; DEFAULT: %global:_(p0) = G_GLOBAL_VALUE @common_linkage
123 ; DEFAULT: %imm:_(s64) = G_CONSTANT i64 1
124 ; DEFAULT: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
125 ; DEFAULT: $x0 = COPY %ptr_add(p0)
126 ; DEFAULT: RET_ReallyLR implicit $x0
127 ; LARGE-MACHO-LABEL: name: test_common_linkage
128 ; LARGE-MACHO: %global:_(p0) = G_GLOBAL_VALUE @common_linkage
129 ; LARGE-MACHO: %imm:_(s64) = G_CONSTANT i64 1
130 ; LARGE-MACHO: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
131 ; LARGE-MACHO: $x0 = COPY %ptr_add(p0)
132 ; LARGE-MACHO: RET_ReallyLR implicit $x0
133 ; SMALL-MACHO-LABEL: name: test_common_linkage
134 ; SMALL-MACHO: %global:_(p0) = G_GLOBAL_VALUE @common_linkage
135 ; SMALL-MACHO: %imm:_(s64) = G_CONSTANT i64 1
136 ; SMALL-MACHO: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
137 ; SMALL-MACHO: $x0 = COPY %ptr_add(p0)
138 ; SMALL-MACHO: RET_ReallyLR implicit $x0
139 ; LARGE-ELF-LABEL: name: test_common_linkage
140 ; LARGE-ELF: %global:_(p0) = G_GLOBAL_VALUE @common_linkage
141 ; LARGE-ELF: %imm:_(s64) = G_CONSTANT i64 1
142 ; LARGE-ELF: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
143 ; LARGE-ELF: $x0 = COPY %ptr_add(p0)
144 ; LARGE-ELF: RET_ReallyLR implicit $x0
145 ; TINY-LABEL: name: test_common_linkage
146 ; TINY: %global:_(p0) = G_GLOBAL_VALUE @common_linkage
147 ; TINY: %imm:_(s64) = G_CONSTANT i64 1
148 ; TINY: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
149 ; TINY: $x0 = COPY %ptr_add(p0)
150 ; TINY: RET_ReallyLR implicit $x0
151 ; WINDOWS-LABEL: name: test_common_linkage
152 ; WINDOWS: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @common_linkage + 1
153 ; WINDOWS: $x0 = COPY [[GV]](p0)
154 ; WINDOWS: RET_ReallyLR implicit $x0
155 %global:_(p0) = G_GLOBAL_VALUE @common_linkage
156 %imm:_(s64) = G_CONSTANT i64 1
157 %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
158 $x0 = COPY %ptr_add(p0)
159 RET_ReallyLR implicit $x0
163 name: test_extern_weak_linkage
165 tracksRegLiveness: true
166 machineFunctionInfo: {}
169 ; DEFAULT-LABEL: name: test_extern_weak_linkage
170 ; DEFAULT: %global:_(p0) = G_GLOBAL_VALUE @extern_weak_linkage
171 ; DEFAULT: %imm:_(s64) = G_CONSTANT i64 1
172 ; DEFAULT: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
173 ; DEFAULT: $x0 = COPY %ptr_add(p0)
174 ; DEFAULT: RET_ReallyLR implicit $x0
175 ; LARGE-MACHO-LABEL: name: test_extern_weak_linkage
176 ; LARGE-MACHO: %global:_(p0) = G_GLOBAL_VALUE @extern_weak_linkage
177 ; LARGE-MACHO: %imm:_(s64) = G_CONSTANT i64 1
178 ; LARGE-MACHO: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
179 ; LARGE-MACHO: $x0 = COPY %ptr_add(p0)
180 ; LARGE-MACHO: RET_ReallyLR implicit $x0
181 ; SMALL-MACHO-LABEL: name: test_extern_weak_linkage
182 ; SMALL-MACHO: %global:_(p0) = G_GLOBAL_VALUE @extern_weak_linkage
183 ; SMALL-MACHO: %imm:_(s64) = G_CONSTANT i64 1
184 ; SMALL-MACHO: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
185 ; SMALL-MACHO: $x0 = COPY %ptr_add(p0)
186 ; SMALL-MACHO: RET_ReallyLR implicit $x0
187 ; LARGE-ELF-LABEL: name: test_extern_weak_linkage
188 ; LARGE-ELF: %global:_(p0) = G_GLOBAL_VALUE @extern_weak_linkage
189 ; LARGE-ELF: %imm:_(s64) = G_CONSTANT i64 1
190 ; LARGE-ELF: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
191 ; LARGE-ELF: $x0 = COPY %ptr_add(p0)
192 ; LARGE-ELF: RET_ReallyLR implicit $x0
193 ; TINY-LABEL: name: test_extern_weak_linkage
194 ; TINY: %global:_(p0) = G_GLOBAL_VALUE @extern_weak_linkage
195 ; TINY: %imm:_(s64) = G_CONSTANT i64 1
196 ; TINY: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
197 ; TINY: $x0 = COPY %ptr_add(p0)
198 ; TINY: RET_ReallyLR implicit $x0
199 ; WINDOWS-LABEL: name: test_extern_weak_linkage
200 ; WINDOWS: %global:_(p0) = G_GLOBAL_VALUE @extern_weak_linkage
201 ; WINDOWS: %imm:_(s64) = G_CONSTANT i64 1
202 ; WINDOWS: %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
203 ; WINDOWS: $x0 = COPY %ptr_add(p0)
204 ; WINDOWS: RET_ReallyLR implicit $x0
205 %global:_(p0) = G_GLOBAL_VALUE @extern_weak_linkage
206 %imm:_(s64) = G_CONSTANT i64 1
207 %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
208 $x0 = COPY %ptr_add(p0)
209 RET_ReallyLR implicit $x0
213 name: never_fold_tagged_globals
215 tracksRegLiveness: true
216 machineFunctionInfo: {}
219 ; CHECK-LABEL: name: never_fold_tagged_globals
220 ; CHECK-NOT: %global:_(p0) = G_GLOBAL_VALUE @external_linkage + 1
221 %global:_(p0) = G_GLOBAL_VALUE @external_linkage
222 %imm:_(s64) = G_CONSTANT i64 1
223 %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
224 $x0 = COPY %ptr_add(p0)
225 RET_ReallyLR implicit $x0
229 name: test_dll_import
231 tracksRegLiveness: true
232 machineFunctionInfo: {}
235 ; CHECK-LABEL: name: test_dll_import
236 ; CHECK-NOT: %global:_(p0) = G_GLOBAL_VALUE @dll_import + 1
237 %global:_(p0) = G_GLOBAL_VALUE @dll_import
238 %imm:_(s64) = G_CONSTANT i64 1
239 %ptr_add:_(p0) = G_PTR_ADD %global, %imm(s64)
240 $x0 = COPY %ptr_add(p0)
241 RET_ReallyLR implicit $x0