1 ; RUN: llc --relocation-model=pic < %s \
2 ; RUN: | FileCheck %s --check-prefix=CHECK-PIC
4 ; Ensure that GlobalISel lowers correctly. GlobalISel is the default ISel for
5 ; -O0 on aarch64. GlobalISel lowers the instruction sequence in the static
6 ; relocation model different to SelectionDAGISel. GlobalISel does the lowering
7 ; of AddLow *after* legalization, and thus doesn't differentiate between
8 ; address-taken-only vs. address-taken-for-loadstore. Hence, we generate a movk
9 ; instruction for load/store instructions as well with GlobalISel. GlobalISel
10 ; also doesn't have the scaffolding to correctly check the bounds of the global
11 ; offset, and cannot fold the lo12 bits into the load/store. Neither of these
12 ; things are a problem as GlobalISel is only used by default at -O0, so we don't
13 ; mind the code size and performance increase.
15 ; RUN: llc --aarch64-enable-global-isel-at-O=0 -O0 --relocation-model=pic < %s \
16 ; RUN: | FileCheck %s --check-prefix=CHECK-PIC
18 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
19 target triple = "aarch64-unknown-linux-android"
21 @global = external global i32
24 define ptr @global_addr() #0 {
25 ; CHECK-PIC: global_addr:
26 ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
27 ; CHECK-PIC: ldr x0, [[[REG]], :got_lo12:global]
33 define i32 @global_load() #0 {
34 ; CHECK-SELECTIONDAGISEL: global_load:
35 ; CHECK-SELECTIONDAGISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
36 ; CHECK-SELECTIONDAGISEL: ldr w0, [[[REG]], :lo12:global]
37 ; CHECK-SELECTIONDAGISEL: ret
39 ; CHECK-GLOBALISEL: global_load:
40 ; CHECK-GLOBALISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
41 ; CHECK-GLOBALISEL: movk [[REG]], #:prel_g3:global+4294967296
42 ; CHECK-GLOBALISEL: add [[REG]], [[REG]], :lo12:global
43 ; CHECK-GLOBALISEL: ldr w0, [[[REG]]]
44 ; CHECK-GLOBALISEL: ret
46 ; CHECK-PIC: global_load:
47 ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
48 ; CHECK-PIC: ldr [[REG]], [[[REG]], :got_lo12:global]
49 ; CHECK-PIC: ldr w0, [[[REG]]]
52 %load = load i32, ptr @global
56 define void @global_store() #0 {
57 ; CHECK-SELECTIONDAGISEL: global_store:
58 ; CHECK-SELECTIONDAGISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
59 ; CHECK-SELECTIONDAGISEL: str wzr, [[[REG]], :lo12:global]
60 ; CHECK-SELECTIONDAGISEL: ret
62 ; CHECK-GLOBALISEL: global_store:
63 ; CHECK-GLOBALISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
64 ; CHECK-GLOBALISEL: movk [[REG]], #:prel_g3:global+4294967296
65 ; CHECK-GLOBALISEL: add [[REG]], [[REG]], :lo12:global
66 ; CHECK-GLOBALISEL: str wzr, [[[REG]]]
67 ; CHECK-GLOBALISEL: ret
69 ; CHECK-PIC: global_store:
70 ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
71 ; CHECK-PIC: ldr [[REG]], [[[REG]], :got_lo12:global]
72 ; CHECK-PIC: str wzr, [[[REG]]]
75 store i32 0, ptr @global
79 define ptr @func_addr() #0 {
80 ; CHECK-PIC: func_addr:
81 ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:func
82 ; CHECK-PIC: ldr x0, [[[REG]], :got_lo12:func]
88 attributes #0 = { "target-features"="+tagged-globals" }