1 ; RUN: llc -mtriple armv7-linux -relocation-model=pic -global-isel %s -o - | FileCheck %s -check-prefixes=CHECK,ELF 2 ; RUN: llc -mtriple armv7-linux -relocation-model=pic -mattr=+no-movt -global-isel %s -o - | FileCheck %s -check-prefixes=CHECK,ELF 3 ; RUN: llc -mtriple armv7-darwin -relocation-model=pic -global-isel %s -o - | FileCheck %s -check-prefixes=CHECK,DARWIN,DARWIN-MOVT 4 ; RUN: llc -mtriple armv7-darwin -relocation-model=pic -mattr=+no-movt -global-isel %s -o - | FileCheck %s -check-prefixes=CHECK,DARWIN,DARWIN-NOMOVT 5 6 @internal_global = internal global i32 42 7 define i32 @test_internal_global() { 8 ; CHECK-LABEL: test_internal_global: 9 ; ELF: ldr [[OFFSET:r[0-9]+]], [[LABEL:.L[[:alnum:]_]+]] 10 ; ELF: [[ANCHOR:.L[[:alnum:]_]+]]: 11 ; DARWIN-NOMOVT: ldr [[OFFSET:r[0-9]+]], [[LABEL:L[[:alnum:]_]+]] 12 ; DARWIN-MOVT: movw [[OFFSET:r[0-9]+]], :lower16:(_internal_global-([[ANCHOR:L[[:alnum:]_]+]]+8)) 13 ; DARWIN-MOVT-NEXT: movt [[OFFSET]], :upper16:(_internal_global-([[ANCHOR]]+8)) 14 ; DARWIN: [[ANCHOR:L[[:alnum:]_]+]]: 15 ; CHECK-NEXT: add r[[ADDR:[0-9]+]], pc, [[OFFSET]] 16 ; CHECK-NEXT: ldr r0, [r[[ADDR]]] 17 ; CHECK-NEXT: bx lr 18 ; ELF: [[LABEL]]: 19 ; ELF-NEXT: .long internal_global-([[ANCHOR]]+8) 20 ; DARWIN-NOMOVT: [[LABEL]]: 21 ; DARWIN-NOMOVT-NEXT: .long _internal_global-([[ANCHOR]]+8) 22 ; DARWIN-MOVT-NOT: .long _internal_global 23 24 entry: 25 %v = load i32, i32* @internal_global 26 ret i32 %v 27 } 28 29 @external_global = external global i32 30 define i32 @test_external_global() { 31 ; CHECK-LABEL: test_external_global: 32 ; ELF: ldr [[OFFSET:r[0-9]+]], [[LABEL:.L[[:alnum:]_]+]] 33 ; ELF: [[ANCHOR:.L[[:alnum:]_]+]]: 34 ; ELF-NEXT: ldr r[[ADDR:[0-9]+]], [pc, [[OFFSET]]] 35 ; DARWIN-NOMOVT: ldr [[OFFSET:r[0-9]+]], [[LABEL:L[[:alnum:]_]+]] 36 ; DARWIN-MOVT: movw [[OFFSET:r[0-9]+]], :lower16:(L_external_global$non_lazy_ptr-([[ANCHOR:L[[:alnum:]_]+]]+8)) 37 ; DARWIN-MOVT: movt [[OFFSET]], :upper16:(L_external_global$non_lazy_ptr-([[ANCHOR]]+8)) 38 ; DARWIN: [[ANCHOR:L[[:alnum:]_]+]]: 39 ; DARWIN: ldr r[[ADDR:[0-9]+]], [pc, [[OFFSET]]] 40 ; CHECK-NEXT: ldr r0, [r[[ADDR]]] 41 ; CHECK-NEXT: bx lr 42 ; ELF: [[LABEL]]: 43 ; ELF: [[TMPLABEL:.L[[:alnum:]_]+]]: 44 ; ELF: .long external_global(GOT_PREL)-(([[ANCHOR]]+8)-[[TMPLABEL]]) 45 ; DARWIN-NOMOVT: [[LABEL]]: 46 ; DARWIN-NOMOVT: .long L_external_global$non_lazy_ptr-([[ANCHOR]]+8) 47 ; DARWIN-NOMOVT-NOT: .long L_external_global 48 entry: 49 %v = load i32, i32* @external_global 50 ret i32 %v 51 } 52 53 @internal_constant = internal constant i32 42 54 define i32 @test_internal_constant() { 55 ; CHECK-LABEL: test_internal_constant: 56 ; ELF: ldr [[OFFSET:r[0-9]+]], [[LABEL:.L[[:alnum:]_]+]] 57 ; ELF: [[ANCHOR:.L[[:alnum:]_]+]]: 58 ; DARWIN-NOMOVT: ldr [[OFFSET:r[0-9]+]], [[LABEL:L[[:alnum:]_]+]] 59 ; DARWIN-MOVT: movw [[OFFSET:r[0-9]+]], :lower16:(_internal_constant-([[ANCHOR:L[[:alnum:]_]+]]+8)) 60 ; DARWIN-MOVT-NEXT: movt [[OFFSET]], :upper16:(_internal_constant-([[ANCHOR]]+8)) 61 ; DARWIN: [[ANCHOR:L[[:alnum:]_]+]]: 62 ; CHECK-NEXT: add r[[ADDR:[0-9]+]], pc, [[OFFSET]] 63 ; CHECK-NEXT: ldr r0, [r[[ADDR]]] 64 ; CHECK-NEXT: bx lr 65 ; ELF: [[LABEL]]: 66 ; ELF-NEXT: .long internal_constant-([[ANCHOR]]+8) 67 ; DARWIN-NOMOVT: [[LABEL]]: 68 ; DARWIN-NOMOVT-NEXT: .long _internal_constant-([[ANCHOR]]+8) 69 ; DARWIN-MOVT-NOT: .long _internal_constant 70 71 entry: 72 %v = load i32, i32* @internal_constant 73 ret i32 %v 74 } 75 76 @external_constant = external constant i32 77 define i32 @test_external_constant() { 78 ; CHECK-LABEL: test_external_constant: 79 ; ELF: ldr [[OFFSET:r[0-9]+]], [[LABEL:.L[[:alnum:]_]+]] 80 ; ELF: [[ANCHOR:.L[[:alnum:]_]+]]: 81 ; ELF-NEXT: ldr r[[ADDR:[0-9]+]], [pc, [[OFFSET]]] 82 ; DARWIN-NOMOVT: ldr [[OFFSET:r[0-9]+]], [[LABEL:L[[:alnum:]_]+]] 83 ; DARWIN-MOVT: movw [[OFFSET:r[0-9]+]], :lower16:(L_external_constant$non_lazy_ptr-([[ANCHOR:L[[:alnum:]_]+]]+8)) 84 ; DARWIN-MOVT: movt [[OFFSET]], :upper16:(L_external_constant$non_lazy_ptr-([[ANCHOR]]+8)) 85 ; DARWIN: [[ANCHOR:L[[:alnum:]_]+]]: 86 ; DARWIN: ldr r[[ADDR:[0-9]+]], [pc, [[OFFSET]]] 87 ; CHECK-NEXT: ldr r0, [r[[ADDR]]] 88 ; CHECK-NEXT: bx lr 89 ; ELF: [[LABEL]]: 90 ; ELF: [[TMPLABEL:.L[[:alnum:]_]+]]: 91 ; ELF: .long external_constant(GOT_PREL)-(([[ANCHOR]]+8)-[[TMPLABEL]]) 92 ; DARWIN-NOMOVT: [[LABEL]]: 93 ; DARWIN-NOMOVT: .long L_external_constant$non_lazy_ptr-([[ANCHOR]]+8) 94 ; DARWIN-NOMOVT-NOT: .long L_external_constant 95 entry: 96 %v = load i32, i32* @external_constant 97 ret i32 %v 98 } 99 100 ; ELF: internal_global: 101 ; DARWIN: _internal_global: 102 ; CHECK: .long 42 103 ; ELF: .size internal_global, 4 104 105 ; ELF: internal_constant: 106 ; DARWIN: _internal_constant: 107 ; CHECK: .long 42 108 ; ELF: .size internal_constant, 4 109 110 ; DARWIN-DAG: L_external_global$non_lazy_ptr: 111 ; DARWIN-DAG: .indirect_symbol _external_global 112 113 ; DARWIN-DAG: L_external_constant$non_lazy_ptr: 114 ; DARWIN-DAG: .indirect_symbol _external_constant 115