1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc  -O0 -mtriple=mipsel-linux-gnu -global-isel -relocation-model=pic -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=MIPS32_PIC
3
4declare i32 @f(i32 %a, i32 %b);
5
6define internal i32 @f_with_local_linkage(i32 %x, i32 %y) {
7; MIPS32_PIC-LABEL: f_with_local_linkage:
8; MIPS32_PIC:       # %bb.0: # %entry
9; MIPS32_PIC-NEXT:    addu $2, $5, $4
10; MIPS32_PIC-NEXT:    jr $ra
11; MIPS32_PIC-NEXT:    nop
12entry:
13  %add = add i32 %y, %x
14  ret i32 %add
15}
16
17define i32 @call_global(i32 %a, i32 %b) {
18; MIPS32_PIC-LABEL: call_global:
19; MIPS32_PIC:       # %bb.0: # %entry
20; MIPS32_PIC-NEXT:    lui $2, %hi(_gp_disp)
21; MIPS32_PIC-NEXT:    addiu $2, $2, %lo(_gp_disp)
22; MIPS32_PIC-NEXT:    addiu $sp, $sp, -24
23; MIPS32_PIC-NEXT:    .cfi_def_cfa_offset 24
24; MIPS32_PIC-NEXT:    sw $ra, 20($sp) # 4-byte Folded Spill
25; MIPS32_PIC-NEXT:    .cfi_offset 31, -4
26; MIPS32_PIC-NEXT:    addu $gp, $2, $25
27; MIPS32_PIC-NEXT:    lw $25, %call16(f)($gp)
28; MIPS32_PIC-NEXT:    jalr $25
29; MIPS32_PIC-NEXT:    nop
30; MIPS32_PIC-NEXT:    lw $ra, 20($sp) # 4-byte Folded Reload
31; MIPS32_PIC-NEXT:    addiu $sp, $sp, 24
32; MIPS32_PIC-NEXT:    jr $ra
33; MIPS32_PIC-NEXT:    nop
34entry:
35  %call = call i32 @f(i32 %a, i32 %b)
36  ret i32 %call
37}
38
39define i32 @call_global_with_local_linkage(i32 %a, i32 %b) {
40; MIPS32_PIC-LABEL: call_global_with_local_linkage:
41; MIPS32_PIC:       # %bb.0: # %entry
42; MIPS32_PIC-NEXT:    lui $2, %hi(_gp_disp)
43; MIPS32_PIC-NEXT:    addiu $2, $2, %lo(_gp_disp)
44; MIPS32_PIC-NEXT:    addiu $sp, $sp, -24
45; MIPS32_PIC-NEXT:    .cfi_def_cfa_offset 24
46; MIPS32_PIC-NEXT:    sw $ra, 20($sp) # 4-byte Folded Spill
47; MIPS32_PIC-NEXT:    .cfi_offset 31, -4
48; MIPS32_PIC-NEXT:    addu $gp, $2, $25
49; MIPS32_PIC-NEXT:    lw $1, %got(f_with_local_linkage)($gp)
50; MIPS32_PIC-NEXT:    addiu $25, $1, %lo(f_with_local_linkage)
51; MIPS32_PIC-NEXT:    jalr $25
52; MIPS32_PIC-NEXT:    nop
53; MIPS32_PIC-NEXT:    lw $ra, 20($sp) # 4-byte Folded Reload
54; MIPS32_PIC-NEXT:    addiu $sp, $sp, 24
55; MIPS32_PIC-NEXT:    jr $ra
56; MIPS32_PIC-NEXT:    nop
57entry:
58  %call = call i32 @f_with_local_linkage(i32 %a, i32 %b)
59  ret i32 %call
60}
61
62
63@val = global i32 0
64@val_with_local_linkage = internal global i32 1
65
66define i32 @ret_global_int() {
67; MIPS32_PIC-LABEL: ret_global_int:
68; MIPS32_PIC:       # %bb.0: # %entry
69; MIPS32_PIC-NEXT:    lui $2, %hi(_gp_disp)
70; MIPS32_PIC-NEXT:    addiu $2, $2, %lo(_gp_disp)
71; MIPS32_PIC-NEXT:    addu $1, $2, $25
72; MIPS32_PIC-NEXT:    lw $1, %got(val)($1)
73; MIPS32_PIC-NEXT:    lw $2, 0($1)
74; MIPS32_PIC-NEXT:    jr $ra
75; MIPS32_PIC-NEXT:    nop
76entry:
77  %0 = load i32, i32* @val
78  ret i32 %0
79}
80
81define i32 @ret_global_int_with_local_linkage() {
82; MIPS32_PIC-LABEL: ret_global_int_with_local_linkage:
83; MIPS32_PIC:       # %bb.0: # %entry
84; MIPS32_PIC-NEXT:    lui $2, %hi(_gp_disp)
85; MIPS32_PIC-NEXT:    addiu $2, $2, %lo(_gp_disp)
86; MIPS32_PIC-NEXT:    addu $1, $2, $25
87; MIPS32_PIC-NEXT:    lw $1, %got(val_with_local_linkage)($1)
88; MIPS32_PIC-NEXT:    addiu $1, $1, %lo(val_with_local_linkage)
89; MIPS32_PIC-NEXT:    lw $2, 0($1)
90; MIPS32_PIC-NEXT:    jr $ra
91; MIPS32_PIC-NEXT:    nop
92entry:
93  %0 = load i32, i32* @val_with_local_linkage
94  ret i32 %0
95}
96