blob: 5e820b8bb3037aeb15dd05d7b4e00b58555564b1 [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s
Tim Northovere0e3aef2013-01-31 12:12:40 +00002
3@var32 = global [3 x i32] zeroinitializer
4@var64 = global [3 x i64] zeroinitializer
5@var32_align64 = global [3 x i32] zeroinitializer, align 8
David Blaikie2f408302015-09-11 03:22:04 +00006@alias = alias [3 x i32], [3 x i32]* @var32_align64
Tim Northovere0e3aef2013-01-31 12:12:40 +00007
8define i64 @test_align32() {
Stephen Linf799e3f2013-07-13 20:38:47 +00009; CHECK-LABEL: test_align32:
Tim Northovere0e3aef2013-01-31 12:12:40 +000010 %addr = bitcast [3 x i32]* @var32 to i64*
11
12 ; Since @var32 is only guaranteed to be aligned to 32-bits, it's invalid to
13 ; emit an "LDR x0, [x0, #:lo12:var32] instruction to implement this load.
David Blaikiea79ac142015-02-27 21:17:42 +000014 %val = load i64, i64* %addr
Tim Northovere0e3aef2013-01-31 12:12:40 +000015; CHECK: adrp [[HIBITS:x[0-9]+]], var32
Tim Northoverbd668872014-04-15 14:00:29 +000016; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], {{#?}}:lo12:var32
Tim Northovere0e3aef2013-01-31 12:12:40 +000017; CHECK: ldr x0, [x[[ADDR]]]
18
19 ret i64 %val
20}
21
22define i64 @test_align64() {
Stephen Linf799e3f2013-07-13 20:38:47 +000023; CHECK-LABEL: test_align64:
Tim Northovere0e3aef2013-01-31 12:12:40 +000024 %addr = bitcast [3 x i64]* @var64 to i64*
25
26 ; However, var64 *is* properly aligned and emitting an adrp/add/ldr would be
27 ; inefficient.
David Blaikiea79ac142015-02-27 21:17:42 +000028 %val = load i64, i64* %addr
Tim Northovere0e3aef2013-01-31 12:12:40 +000029; CHECK: adrp x[[HIBITS:[0-9]+]], var64
30; CHECK-NOT: add x[[HIBITS]]
Tim Northoverbd668872014-04-15 14:00:29 +000031; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:var64]
Tim Northovere0e3aef2013-01-31 12:12:40 +000032
33 ret i64 %val
34}
35
36define i64 @test_var32_align64() {
Stephen Linf799e3f2013-07-13 20:38:47 +000037; CHECK-LABEL: test_var32_align64:
Tim Northovere0e3aef2013-01-31 12:12:40 +000038 %addr = bitcast [3 x i32]* @var32_align64 to i64*
39
40 ; Since @var32 is only guaranteed to be aligned to 32-bits, it's invalid to
41 ; emit an "LDR x0, [x0, #:lo12:var32] instruction to implement this load.
David Blaikiea79ac142015-02-27 21:17:42 +000042 %val = load i64, i64* %addr
Tim Northovere0e3aef2013-01-31 12:12:40 +000043; CHECK: adrp x[[HIBITS:[0-9]+]], var32_align64
44; CHECK-NOT: add x[[HIBITS]]
Tim Northoverbd668872014-04-15 14:00:29 +000045; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:var32_align64]
Tim Northovere0e3aef2013-01-31 12:12:40 +000046
47 ret i64 %val
48}
49
Rafael Espindola52dc5d82014-05-06 16:48:58 +000050define i64 @test_var32_alias() {
51; CHECK-LABEL: test_var32_alias:
52 %addr = bitcast [3 x i32]* @alias to i64*
53
54 ; Test that we can find the alignment for aliases.
David Blaikiea79ac142015-02-27 21:17:42 +000055 %val = load i64, i64* %addr
Rafael Espindola52dc5d82014-05-06 16:48:58 +000056; CHECK: adrp x[[HIBITS:[0-9]+]], alias
57; CHECK-NOT: add x[[HIBITS]]
58; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:alias]
59
60 ret i64 %val
61}
62
Tim Northovere0e3aef2013-01-31 12:12:40 +000063@yet_another_var = external global {i32, i32}
64
65define i64 @test_yet_another_var() {
Stephen Linf799e3f2013-07-13 20:38:47 +000066; CHECK-LABEL: test_yet_another_var:
Tim Northovere0e3aef2013-01-31 12:12:40 +000067
68 ; @yet_another_var has a preferred alignment of 8, but that's not enough if
69 ; we're going to be linking against other things. Its ABI alignment is only 4
70 ; so we can't fold the load.
David Blaikiea79ac142015-02-27 21:17:42 +000071 %val = load i64, i64* bitcast({i32, i32}* @yet_another_var to i64*)
Tim Northovere0e3aef2013-01-31 12:12:40 +000072; CHECK: adrp [[HIBITS:x[0-9]+]], yet_another_var
Tim Northoverbd668872014-04-15 14:00:29 +000073; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], {{#?}}:lo12:yet_another_var
Tim Northovere0e3aef2013-01-31 12:12:40 +000074; CHECK: ldr x0, [x[[ADDR]]]
75 ret i64 %val
76}
77
78define i64()* @test_functions() {
Stephen Linf799e3f2013-07-13 20:38:47 +000079; CHECK-LABEL: test_functions:
Tim Northovere0e3aef2013-01-31 12:12:40 +000080 ret i64()* @test_yet_another_var
81; CHECK: adrp [[HIBITS:x[0-9]+]], test_yet_another_var
Tim Northoverbd668872014-04-15 14:00:29 +000082; CHECK: add x0, [[HIBITS]], {{#?}}:lo12:test_yet_another_var
Tim Northovere0e3aef2013-01-31 12:12:40 +000083}