115 lines · plain
1; RUN: llc -mtriple=x86_64-apple-darwin %s -o %t2; RUN: FileCheck %s -check-prefix=X86 < %t3; RUN: FileCheck %s -check-prefix=X86-GOT-EQUIV < %t4; RUN: FileCheck %s -check-prefix=X86-NOGOT-EQUIV < %t5 6; GOT equivalent globals references can be replaced by the GOT entry of the7; final symbol instead.8 9%struct.data = type { i32, %struct.anon }10%struct.anon = type { i32, i32 }11 12; Check that these got equivalent symbols are never emitted.13 14; X86-GOT-EQUIV-NOT: L_localgotequiv15; X86-GOT-EQUIV-NOT: l_extgotequiv16@localfoo = global i32 4217@localgotequiv = private unnamed_addr constant ptr @localfoo18 19@extfoo = external global i3220@extgotequiv = private unnamed_addr constant ptr @extfoo21 22; Don't replace GOT equivalent usage within instructions and emit the GOT23; equivalent since it can't be replaced by the GOT entry. @bargotequiv is24; used by an instruction inside @t0.25;26; X86: l_bargotequiv:27; X86-NEXT: .quad _extbar28@extbar = external global i3229@bargotequiv = private unnamed_addr constant ptr @extbar30 31@table = global [4 x %struct.data] [32 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },33; Test GOT equivalent usage inside nested constant arrays.34 35; X86: .long 536; X86-NOT: .long _localgotequiv-(_table+20)37; X86-NEXT: .long _localfoo@GOTPCREL+438 %struct.data { i32 4, %struct.anon { i32 5,39 i32 trunc (i64 sub (i64 ptrtoint (ptr @localgotequiv to i64),40 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 1, i32 1, i32 1) to i64))41 to i32)}42 },43; X86: .long 544; X86-NOT: _extgotequiv-(_table+32)45; X86-NEXT: .long _extfoo@GOTPCREL+446 %struct.data { i32 4, %struct.anon { i32 5,47 i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),48 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 2, i32 1, i32 1) to i64))49 to i32)}50 },51; Test support for arbitrary constants into the GOTPCREL offset.52 53; X86: .long 554; X86-NOT: _extgotequiv-(_table+44)55; X86-NEXT: .long _extfoo@GOTPCREL+2856 %struct.data { i32 4, %struct.anon { i32 5,57 i32 add (i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),58 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 3, i32 1, i32 1) to i64))59 to i32), i32 24)}60 }61], align 1662 63; Test multiple uses of GOT equivalents.64 65; X86-LABEL: _delta66; X86: .long _extfoo@GOTPCREL+467@delta = global i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),68 i64 ptrtoint (ptr @delta to i64))69 to i32)70 71; X86-LABEL: _deltaplus:72; X86: .long _localfoo@GOTPCREL+5973@deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (ptr @localgotequiv to i64),74 i64 ptrtoint (ptr @deltaplus to i64))75 to i32), i32 55)76 77define i32 @t0(i32 %a) {78 %x = add i32 trunc (i64 sub (i64 ptrtoint (ptr @bargotequiv to i64),79 i64 ptrtoint (ptr @t0 to i64))80 to i32), %a81 ret i32 %x82}83 84; Also test direct instruction uses.85define ptr @t1() {86 ret ptr @bargotequiv87}88 89; Do not crash when a pattern cannot be matched as a GOT equivalent90define void @foo() {91; X86-NOGOT-EQUIV-LABEL: _foo:92; X86-NOGOT-EQUIV: leaq _b(%rip), %rax93 store ptr @b, ptr null94 ret void95}96@a = external global i897@b = internal unnamed_addr constant ptr @a98 99; X86-NOGOT-EQUIV-LABEL: _c:100; X86-NOGOT-EQUIV: .quad _b101@c = global ptr @b102 103; X86-LABEL: table_with_negative_offset:104; X86-NEXT: .long _a@GOTPCREL+4294967292105@table_with_negative_offset = dso_local unnamed_addr constant [3 x i32] [106 i32 trunc (107 i64 sub (108 i64 ptrtoint (ptr @b to i64),109 i64 ptrtoint (ptr getelementptr inbounds ([3 x i32], ptr @table_with_negative_offset, i32 0, i32 2) to i64)110 )111 to i32),112 i32 0,113 i32 0114], align 4115