Home | History | Annotate | Download | only in AArch64
      1 ; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs < %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 
      7 define i64 @test_align32() {
      8 ; CHECK-LABEL: test_align32:
      9   %addr = bitcast [3 x i32]* @var32 to i64*
     10 
     11   ; Since @var32 is only guaranteed to be aligned to 32-bits, it's invalid to
     12   ; emit an "LDR x0, [x0, #:lo12:var32] instruction to implement this load.
     13   %val = load i64* %addr
     14 ; CHECK: adrp [[HIBITS:x[0-9]+]], var32
     15 ; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], #:lo12:var32
     16 ; CHECK: ldr x0, [x[[ADDR]]]
     17 
     18   ret i64 %val
     19 }
     20 
     21 define i64 @test_align64() {
     22 ; CHECK-LABEL: test_align64:
     23   %addr = bitcast [3 x i64]* @var64 to i64*
     24 
     25   ; However, var64 *is* properly aligned and emitting an adrp/add/ldr would be
     26   ; inefficient.
     27   %val = load i64* %addr
     28 ; CHECK: adrp x[[HIBITS:[0-9]+]], var64
     29 ; CHECK-NOT: add x[[HIBITS]]
     30 ; CHECK: ldr x0, [x[[HIBITS]], #:lo12:var64]
     31 
     32   ret i64 %val
     33 }
     34 
     35 define i64 @test_var32_align64() {
     36 ; CHECK-LABEL: test_var32_align64:
     37   %addr = bitcast [3 x i32]* @var32_align64 to i64*
     38 
     39   ; Since @var32 is only guaranteed to be aligned to 32-bits, it's invalid to
     40   ; emit an "LDR x0, [x0, #:lo12:var32] instruction to implement this load.
     41   %val = load i64* %addr
     42 ; CHECK: adrp x[[HIBITS:[0-9]+]], var32_align64
     43 ; CHECK-NOT: add x[[HIBITS]]
     44 ; CHECK: ldr x0, [x[[HIBITS]], #:lo12:var32_align64]
     45 
     46   ret i64 %val
     47 }
     48 
     49 @yet_another_var = external global {i32, i32}
     50 
     51 define i64 @test_yet_another_var() {
     52 ; CHECK-LABEL: test_yet_another_var:
     53 
     54   ; @yet_another_var has a preferred alignment of 8, but that's not enough if
     55   ; we're going to be linking against other things. Its ABI alignment is only 4
     56   ; so we can't fold the load.
     57   %val = load i64* bitcast({i32, i32}* @yet_another_var to i64*)
     58 ; CHECK: adrp [[HIBITS:x[0-9]+]], yet_another_var
     59 ; CHECK: add x[[ADDR:[0-9]+]], [[HIBITS]], #:lo12:yet_another_var
     60 ; CHECK: ldr x0, [x[[ADDR]]]
     61   ret i64 %val
     62 }
     63 
     64 define i64()* @test_functions() {
     65 ; CHECK-LABEL: test_functions:
     66   ret i64()* @test_yet_another_var
     67 ; CHECK: adrp [[HIBITS:x[0-9]+]], test_yet_another_var
     68 ; CHECK: add x0, [[HIBITS]], #:lo12:test_yet_another_var
     69 }
     70