• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -mtriple=arm64 -relocation-model=pic -o - %s -mcpu=cyclone | FileCheck %s --check-prefix=CHECK-PIC
2; RUN: llc -mtriple=arm64 -O0 -fast-isel -relocation-model=pic -o - %s -mcpu=cyclone | FileCheck %s --check-prefix=CHECK-FAST-PIC
3
4@var8 = external global i8, align 1
5@var16 = external global i16, align 2
6@var32 = external global i32, align 4
7@var64 = external global i64, align 8
8
9define i8 @test_i8(i8 %new) {
10  %val = load i8, i8* @var8, align 1
11  store i8 %new, i8* @var8
12  ret i8 %val
13; CHECK-PIC-LABEL: test_i8:
14; CHECK-PIC: adrp x[[HIREG:[0-9]+]], :got:var8
15; CHECK-PIC: ldr x[[VAR_ADDR:[0-9]+]], [x[[HIREG]], :got_lo12:var8]
16; CHECK-PIC: ldrb {{w[0-9]+}}, [x[[VAR_ADDR]]]
17
18; CHECK-FAST-PIC: adrp x[[HIREG:[0-9]+]], :got:var8
19; CHECK-FAST-PIC: ldr x[[VARADDR:[0-9]+]], [x[[HIREG]], :got_lo12:var8]
20; CHECK-FAST-PIC: ldr {{w[0-9]+}}, [x[[VARADDR]]]
21}
22
23define i16 @test_i16(i16 %new) {
24  %val = load i16, i16* @var16, align 2
25  store i16 %new, i16* @var16
26  ret i16 %val
27}
28
29define i32 @test_i32(i32 %new) {
30  %val = load i32, i32* @var32, align 4
31  store i32 %new, i32* @var32
32  ret i32 %val
33}
34
35define i64 @test_i64(i64 %new) {
36  %val = load i64, i64* @var64, align 8
37  store i64 %new, i64* @var64
38  ret i64 %val
39}
40
41define i64* @test_addr() {
42  ret i64* @var64
43}
44
45@hiddenvar = hidden global i32 0, align 4
46@protectedvar = protected global i32 0, align 4
47
48define i32 @test_vis() {
49  %lhs = load i32, i32* @hiddenvar, align 4
50  %rhs = load i32, i32* @protectedvar, align 4
51  %ret = add i32 %lhs, %rhs
52  ret i32 %ret
53; CHECK-PIC-LABEL: test_vis:
54; CHECK-PIC: adrp {{x[0-9]+}}, hiddenvar
55; CHECK-PIC: ldr {{w[0-9]+}}, [{{x[0-9]+}}, :lo12:hiddenvar]
56; CHECK-PIC: adrp {{x[0-9]+}}, protectedvar
57; CHECK-PIC: ldr {{w[0-9]+}}, [{{x[0-9]+}}, :lo12:protectedvar]
58}
59
60@var_default = external global [2 x i32]
61
62define i32 @test_default_align() {
63  %addr = getelementptr [2 x i32], [2 x i32]* @var_default, i32 0, i32 0
64  %val = load i32, i32* %addr
65  ret i32 %val
66}
67
68define i64 @test_default_unaligned() {
69  %addr = bitcast [2 x i32]* @var_default to i64*
70  %val = load i64, i64* %addr
71  ret i64 %val
72}
73