1 ; RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s 2 3 @var32 = global [3 x i32] zeroinitializer 4 @var64 = global [3 x i64] zeroinitializer 5 @var32_align64 = global [3 x i32] zeroinitializer, align 8 6 @alias = alias [3 x i32]* @var32_align64 7 8 define i64 @test_align32() { 9 ; CHECK-LABEL: test_align32: 10 %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. 14 %val = load i64* %addr 15 ; CHECK: adrp [[HIBITS:x[0-9]+]], var32 16 ; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], {{#?}}:lo12:var32 17 ; CHECK: ldr x0, [x[[ADDR]]] 18 19 ret i64 %val 20 } 21 22 define i64 @test_align64() { 23 ; CHECK-LABEL: test_align64: 24 %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. 28 %val = load i64* %addr 29 ; CHECK: adrp x[[HIBITS:[0-9]+]], var64 30 ; CHECK-NOT: add x[[HIBITS]] 31 ; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:var64] 32 33 ret i64 %val 34 } 35 36 define i64 @test_var32_align64() { 37 ; CHECK-LABEL: test_var32_align64: 38 %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. 42 %val = load i64* %addr 43 ; CHECK: adrp x[[HIBITS:[0-9]+]], var32_align64 44 ; CHECK-NOT: add x[[HIBITS]] 45 ; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:var32_align64] 46 47 ret i64 %val 48 } 49 50 define 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. 55 %val = load i64* %addr 56 ; 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 63 @yet_another_var = external global {i32, i32} 64 65 define i64 @test_yet_another_var() { 66 ; CHECK-LABEL: test_yet_another_var: 67 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. 71 %val = load i64* bitcast({i32, i32}* @yet_another_var to i64*) 72 ; CHECK: adrp [[HIBITS:x[0-9]+]], yet_another_var 73 ; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], {{#?}}:lo12:yet_another_var 74 ; CHECK: ldr x0, [x[[ADDR]]] 75 ret i64 %val 76 } 77 78 define i64()* @test_functions() { 79 ; CHECK-LABEL: test_functions: 80 ret i64()* @test_yet_another_var 81 ; CHECK: adrp [[HIBITS:x[0-9]+]], test_yet_another_var 82 ; CHECK: add x0, [[HIBITS]], {{#?}}:lo12:test_yet_another_var 83 } 84