93 lines · plain
1; RUN: llc -mtriple=arm64-apple-darwin %s -o - | FileCheck %s2 3; GOT equivalent globals references can be replaced by the GOT entry of the4; final symbol instead.5 6%struct.data = type { i32, %struct.anon }7%struct.anon = type { i32, i32 }8 9@localfoo = global i32 4210@localgotequiv = private unnamed_addr constant ptr @localfoo11 12@extfoo = external global i3213@extgotequiv = private unnamed_addr constant ptr @extfoo14 15; Don't replace GOT equivalent usage within instructions and emit the GOT16; equivalent since it can't be replaced by the GOT entry. @bargotequiv is17; used by an instruction inside @t0.18;19; CHECK: l_bargotequiv:20; CHECK-NEXT: .quad _extbar21@extbar = external global i3222@bargotequiv = private unnamed_addr constant ptr @extbar23 24@table = global [4 x %struct.data] [25; CHECK-LABEL: _table26 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },27; Test GOT equivalent usage inside nested constant arrays.28 29; CHECK: .long 530; CHECK-NOT: .long _localgotequiv-(_table+20)31; CHECK-NEXT: Ltmp0:32; CHECK-NEXT: .long _localfoo@GOT-Ltmp033 %struct.data { i32 4, %struct.anon { i32 5,34 i32 trunc (i64 sub (i64 ptrtoint (ptr @localgotequiv to i64),35 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 1, i32 1, i32 1) to i64))36 to i32)}37 },38 39; CHECK: .long 540; CHECK-NOT: _extgotequiv-(_table+32)41; CHECK-NEXT: Ltmp1:42; CHECK-NEXT: _extfoo@GOT-Ltmp143 %struct.data { i32 4, %struct.anon { i32 5,44 i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),45 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 2, i32 1, i32 1) to i64))46 to i32)}47 },48; Test support for arbitrary constants into the GOTPCREL offset, which is49; supported on x86-64 but not on ARM6450 51; CHECK: .long 552; CHECK-NEXT: .long l_extgotequiv-_table-44+2453 %struct.data { i32 4, %struct.anon { i32 5,54 i32 add (i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),55 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 3, i32 1, i32 1) to i64))56 to i32), i32 24)}57 }58], align 1659 60; Test multiple uses of GOT equivalents.61 62; CHECK-LABEL: _delta63; CHECK: Ltmp2:64; CHECK-NEXT: .long _extfoo@GOT-Ltmp265@delta = global i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),66 i64 ptrtoint (ptr @delta to i64))67 to i32)68 69; CHECK-LABEL: _deltaplus:70; CHECK: .long l_localgotequiv-_deltaplus+5571@deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (ptr @localgotequiv to i64),72 i64 ptrtoint (ptr @deltaplus to i64))73 to i32), i32 55)74 75define i32 @t0(i32 %a) {76 %x = add i32 trunc (i64 sub (i64 ptrtoint (ptr @bargotequiv to i64),77 i64 ptrtoint (ptr @t0 to i64))78 to i32), %a79 ret i32 %x80}81 82; Check that these got equivalent symbols are emitted on ARM64. Since ARM6483; does not support encoding an extra offset with @GOT, we still need to emit the84; equivalents for use by such IR constructs. Check them at the end of the test85; since they will start out as GOT equivalent candidates, but they are actually86; needed and are therefore emitted at the end.87 88; CHECK-LABEL: l_localgotequiv:89; CHECK-NEXT: .quad _localfoo90 91; CHECK-LABEL: l_extgotequiv:92; CHECK-NEXT: .quad _extfoo93