xref: /llvm-project/llvm/test/CodeGen/Mips/global-address.ll (revision 8663926a544602932d299dda435ed1ef70a05f48)
1; RUN: llc -mtriple=mipsel \
2; RUN:     -relocation-model=pic < %s | FileCheck %s -check-prefix=PIC-O32
3; RUN: llc -mtriple=mipsel-linux-gnu \
4; RUN:     -relocation-model=static < %s | FileCheck %s -check-prefix=STATIC-O32
5; RUN: llc -mtriple=mips64el -mcpu=mips64r2 -target-abi n32 \
6; RUN:     -relocation-model=pic < %s | FileCheck %s -check-prefix=PIC-N32
7; RUN: llc -mtriple=mips64el -mcpu=mips64r2 -target-abi n32 \
8; RUN:     -relocation-model=static < %s | FileCheck %s -check-prefix=STATIC-N32
9; RUN: llc -mtriple=mips64el -mcpu=mips64r2 -target-abi n64 \
10; RUN:     -relocation-model=pic < %s | FileCheck %s -check-prefix=PIC-N64
11; RUN: llc -mtriple=mips64el -mcpu=mips64r2 -target-abi n64 \
12; RUN:     -relocation-model=static < %s | FileCheck %s -check-prefix=STATIC-N64
13
14@s1 = internal unnamed_addr global i32 8, align 4
15@g1 = external global i32
16
17define void @foo() nounwind {
18entry:
19; PIC-O32: lw  $[[R0:[0-9]+]], %got(s1)
20; PIC-O32: lw  ${{[0-9]+}}, %lo(s1)($[[R0]])
21; PIC-O32: lw  ${{[0-9]+}}, %got(g1)
22; STATIC-O32: lui $[[R1:[0-9]+]], %hi(s1)
23; STATIC-O32: lw  ${{[0-9]+}}, %lo(s1)($[[R1]])
24; STATIC-O32: lui $[[R2:[0-9]+]], %hi(g1)
25; STATIC-O32: lw  ${{[0-9]+}}, %lo(g1)($[[R2]])
26
27; PIC-N32: lw  $[[R0:[0-9]+]], %got_page(s1)
28; PIC-N32: lw  ${{[0-9]+}}, %got_ofst(s1)($[[R0]])
29; PIC-N32: lw  ${{[0-9]+}}, %got_disp(g1)
30; STATIC-N32: lui $[[R1:[0-9]+]], %hi(s1)
31; STATIC-N32: lw  ${{[0-9]+}}, %lo(s1)($[[R1]])
32; STATIC-N32: lui $[[R2:[0-9]+]], %hi(g1)
33; STATIC-N32: lw  ${{[0-9]+}}, %lo(g1)($[[R2]])
34
35; PIC-N64: ld  $[[R0:[0-9]+]], %got_page(s1)
36; PIC-N64: lw  ${{[0-9]+}}, %got_ofst(s1)($[[R0]])
37; PIC-N64: ld  ${{[0-9]+}}, %got_disp(g1)
38; STATIC-N64: lui $[[R1:[0-9]+]], %highest(s1)
39; STATIC-N64: daddiu ${{[0-9]+}}, ${{[0-9]+}}, %higher(s1)
40; STATIC-N64: daddiu ${{[0-9]+}}, ${{[0-9]+}}, %hi(s1)
41; STATIC-N64: dsll $[[R2:[0-9]+]], $[[R1]], 16
42; STATIC-N64: lw  ${{[0-9]+}}, %lo(s1)($[[R2]])
43; STATIC-N64: lui $[[R3:[0-9]+]], %highest(g1)
44; STATIC-N64: daddiu $[[R3]], $[[R3]], %higher(g1)
45; STATIC-N64: daddiu $[[R3]], $[[R3]], %hi(g1)
46; STATIC-N64: lw  ${{[0-9]+}}, %lo(g1)($[[R3]])
47
48  %0 = load i32, ptr @s1, align 4
49  tail call void @foo1(i32 %0) nounwind
50  %1 = load i32, ptr @g1, align 4
51  store i32 %1, ptr @s1, align 4
52  %add = add nsw i32 %1, 2
53  store i32 %add, ptr @g1, align 4
54  ret void
55}
56
57declare void @foo1(i32)
58