File: global-alignment.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 (83 lines) | stat: -rw-r--r-- 2,772 bytes parent folder | download | duplicates (7)
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
; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s

@var32 = dso_local global [3 x i32] zeroinitializer
@var64 = dso_local global [3 x i64] zeroinitializer
@var32_align64 = dso_local global [3 x i32] zeroinitializer, align 8
@alias = dso_local alias [3 x i32], [3 x i32]* @var32_align64

define dso_local i64 @test_align32() {
; CHECK-LABEL: test_align32:
  %addr = bitcast [3 x i32]* @var32 to i64*

  ; Since @var32 is only guaranteed to be aligned to 32-bits, it's invalid to
  ; emit an "LDR x0, [x0, #:lo12:var32] instruction to implement this load.
  %val = load i64, i64* %addr
; CHECK: adrp [[HIBITS:x[0-9]+]], var32
; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], {{#?}}:lo12:var32
; CHECK: ldr x0, [x[[ADDR]]]

  ret i64 %val
}

define dso_local i64 @test_align64() {
; CHECK-LABEL: test_align64:
  %addr = bitcast [3 x i64]* @var64 to i64*

  ; However, var64 *is* properly aligned and emitting an adrp/add/ldr would be
  ; inefficient.
  %val = load i64, i64* %addr
; CHECK: adrp x[[HIBITS:[0-9]+]], var64
; CHECK-NOT: add x[[HIBITS]]
; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:var64]

  ret i64 %val
}

define dso_local i64 @test_var32_align64() {
; CHECK-LABEL: test_var32_align64:
  %addr = bitcast [3 x i32]* @var32_align64 to i64*

  ; Since @var32 is only guaranteed to be aligned to 32-bits, it's invalid to
  ; emit an "LDR x0, [x0, #:lo12:var32] instruction to implement this load.
  %val = load i64, i64* %addr
; CHECK: adrp x[[HIBITS:[0-9]+]], var32_align64
; CHECK-NOT: add x[[HIBITS]]
; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:var32_align64]

  ret i64 %val
}

define dso_local i64 @test_var32_alias() {
; CHECK-LABEL: test_var32_alias:
  %addr = bitcast [3 x i32]* @alias to i64*

  ; We don't know anything about the alignment of aliases.
  %val = load i64, i64* %addr
; CHECK: adrp x[[HIBITS:[0-9]+]], alias
; CHECK: add x[[ADDR:[0-9]+]], x[[HIBITS]], {{#?}}:lo12:alias
; CHECK: ldr x0, [x[[ADDR]]]

  ret i64 %val
}

@yet_another_var = external dso_local global {i32, i32}

define dso_local i64 @test_yet_another_var() {
; CHECK-LABEL: test_yet_another_var:

  ; @yet_another_var has a preferred alignment of 8, but that's not enough if
  ; we're going to be linking against other things. Its ABI alignment is only 4
  ; so we can't fold the load.
  %val = load i64, i64* bitcast({i32, i32}* @yet_another_var to i64*)
; CHECK: adrp [[HIBITS:x[0-9]+]], yet_another_var
; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], {{#?}}:lo12:yet_another_var
; CHECK: ldr x0, [x[[ADDR]]]
  ret i64 %val
}

define dso_local i64()* @test_functions() {
; CHECK-LABEL: test_functions:
  ret i64()* @test_yet_another_var
; CHECK: adrp [[HIBITS:x[0-9]+]], test_yet_another_var
; CHECK: add x0, [[HIBITS]], {{#?}}:lo12:test_yet_another_var
}