1; RUN: llc -mtriple=x86_64-apple-darwin %s -o %t 2; RUN: FileCheck %s -check-prefix=X86 < %t 3; RUN: FileCheck %s -check-prefix=X86-GOT-EQUIV < %t 4 5; GOT equivalent globals references can be replaced by the GOT entry of the 6; final symbol instead. 7 8%struct.data = type { i32, %struct.anon } 9%struct.anon = type { i32, i32 } 10 11; Check that these got equivalent symbols are never emitted. 12 13; X86-GOT-EQUIV-NOT: L_localgotequiv 14; X86-GOT-EQUIV-NOT: l_extgotequiv 15@localfoo = global i32 42 16@localgotequiv = private unnamed_addr constant i32* @localfoo 17 18@extfoo = external global i32 19@extgotequiv = private unnamed_addr constant i32* @extfoo 20 21; Don't replace GOT equivalent usage within instructions and emit the GOT 22; equivalent since it can't be replaced by the GOT entry. @bargotequiv is 23; used by an instruction inside @t0. 24; 25; X86: l_bargotequiv: 26; X86-NEXT: .quad _extbar 27@extbar = external global i32 28@bargotequiv = private unnamed_addr constant i32* @extbar 29 30@table = global [4 x %struct.data] [ 31 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } }, 32; Test GOT equivalent usage inside nested constant arrays. 33 34; X86: .long 5 35; X86-NOT: .long _localgotequiv-(_table+20) 36; X86-NEXT: .long _localfoo@GOTPCREL+4 37 %struct.data { i32 4, %struct.anon { i32 5, 38 i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64), 39 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 1, i32 1, i32 1) to i64)) 40 to i32)} 41 }, 42; X86: .long 5 43; X86-NOT: _extgotequiv-(_table+32) 44; X86-NEXT: .long _extfoo@GOTPCREL+4 45 %struct.data { i32 4, %struct.anon { i32 5, 46 i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64), 47 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 2, i32 1, i32 1) to i64)) 48 to i32)} 49 }, 50; Test support for arbitrary constants into the GOTPCREL offset. 51 52; X86: .long 5 53; X86-NOT: _extgotequiv-(_table+44) 54; X86-NEXT: .long _extfoo@GOTPCREL+28 55 %struct.data { i32 4, %struct.anon { i32 5, 56 i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64), 57 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 3, i32 1, i32 1) to i64)) 58 to i32), i32 24)} 59 } 60], align 16 61 62; Test multiple uses of GOT equivalents. 63 64; X86-LABEL: _delta 65; X86: .long _extfoo@GOTPCREL+4 66@delta = global i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64), 67 i64 ptrtoint (i32* @delta to i64)) 68 to i32) 69 70; X86-LABEL: _deltaplus: 71; X86: .long _localfoo@GOTPCREL+59 72@deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64), 73 i64 ptrtoint (i32* @deltaplus to i64)) 74 to i32), i32 55) 75 76define i32 @t0(i32 %a) { 77 %x = add i32 trunc (i64 sub (i64 ptrtoint (i32** @bargotequiv to i64), 78 i64 ptrtoint (i32 (i32)* @t0 to i64)) 79 to i32), %a 80 ret i32 %x 81} 82 83; Also test direct instruction uses. 84define i32** @t1() { 85 ret i32** @bargotequiv 86} 87