File: tagged-globals-pic.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (88 lines) | stat: -rw-r--r-- 3,202 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
; RUN: llc --relocation-model=pic < %s \
; RUN:   | FileCheck %s --check-prefix=CHECK-PIC

; Ensure that GlobalISel lowers correctly. GlobalISel is the default ISel for
; -O0 on aarch64. GlobalISel lowers the instruction sequence in the static
; relocation model different to SelectionDAGISel. GlobalISel does the lowering
; of AddLow *after* legalization, and thus doesn't differentiate between
; address-taken-only vs. address-taken-for-loadstore. Hence, we generate a movk
; instruction for load/store instructions as well with GlobalISel. GlobalISel
; also doesn't have the scaffolding to correctly check the bounds of the global
; offset, and cannot fold the lo12 bits into the load/store. Neither of these
; things are a problem as GlobalISel is only used by default at -O0, so we don't
; mind the code size and performance increase.

; RUN: llc --aarch64-enable-global-isel-at-O=0 -O0 --relocation-model=pic < %s \
; RUN:   | FileCheck %s --check-prefix=CHECK-PIC

target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-android"

@global = external global i32
declare void @func()

define i32* @global_addr() #0 {
  ; CHECK-PIC: global_addr:
  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
  ; CHECK-PIC: ldr x0, {{\[}}[[REG]], :got_lo12:global]
  ; CHECK-PIC: ret

  ret i32* @global
}

define i32 @global_load() #0 {
  ; CHECK-SELECTIONDAGISEL: global_load:
  ; CHECK-SELECTIONDAGISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
  ; CHECK-SELECTIONDAGISEL: ldr w0, {{\[}}[[REG]], :lo12:global{{\]}}
  ; CHECK-SELECTIONDAGISEL: ret

  ; CHECK-GLOBALISEL: global_load:
  ; CHECK-GLOBALISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
  ; CHECK-GLOBALISEL: movk [[REG]], #:prel_g3:global+4294967296
  ; CHECK-GLOBALISEL: add [[REG]], [[REG]], :lo12:global
  ; CHECK-GLOBALISEL: ldr w0, {{\[}}[[REG]]{{\]}}
  ; CHECK-GLOBALISEL: ret

  ; CHECK-PIC: global_load:
  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
  ; CHECK-PIC: ldr  [[REG]], {{\[}}[[REG]], :got_lo12:global]
  ; CHECK-PIC: ldr w0, {{\[}}[[REG]]{{\]}}
  ; CHECK-PIC: ret

  %load = load i32, i32* @global
  ret i32 %load
}

define void @global_store() #0 {
  ; CHECK-SELECTIONDAGISEL: global_store:
  ; CHECK-SELECTIONDAGISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
  ; CHECK-SELECTIONDAGISEL: str wzr, {{\[}}[[REG]], :lo12:global{{\]}}
  ; CHECK-SELECTIONDAGISEL: ret

  ; CHECK-GLOBALISEL: global_store:
  ; CHECK-GLOBALISEL: adrp [[REG:x[0-9]+]], :pg_hi21_nc:global
  ; CHECK-GLOBALISEL: movk [[REG]], #:prel_g3:global+4294967296
  ; CHECK-GLOBALISEL: add [[REG]], [[REG]], :lo12:global
  ; CHECK-GLOBALISEL: str wzr, {{\[}}[[REG]]{{\]}}
  ; CHECK-GLOBALISEL: ret

  ; CHECK-PIC: global_store:
  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:global
  ; CHECK-PIC: ldr  [[REG]], {{\[}}[[REG]], :got_lo12:global]
  ; CHECK-PIC: str wzr, {{\[}}[[REG]]{{\]}}
  ; CHECK-PIC: ret

  store i32 0, i32* @global
  ret void
}

define void ()* @func_addr() #0 {
  ; CHECK-PIC: func_addr:
  ; CHECK-PIC: adrp [[REG:x[0-9]+]], :got:func
  ; CHECK-PIC: ldr  x0, {{\[}}[[REG]], :got_lo12:func]
  ; CHECK-PIC: ret

  ret void ()* @func
}

attributes #0 = { "target-features"="+tagged-globals" }