xref: /llvm-project/llvm/test/CodeGen/Mips/GlobalISel/instruction-select/gloal_address_pic.mir (revision fae05692a36f9ebbd201d93c2a6b0f927564d7e6)
1# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2# RUN: llc -O0 -mtriple=mipsel-linux-gnu -relocation-model=pic -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=MIPS32
3--- |
4
5  @val = global i32 0
6  @val_with_local_linkage = internal global i32 1
7
8  declare i32 @f(i32, i32)
9  define internal void @f_with_local_linkage() {entry: ret void}
10  define void @call_global() {entry: ret void}
11  define void @call_global_with_local_linkage() {entry: ret void}
12  define void @ret_global_int() {entry: ret void}
13  define void @ret_global_int_with_local_linkage() {entry: ret void}
14
15...
16---
17name:            f_with_local_linkage
18alignment:       4
19legalized:       true
20regBankSelected: true
21tracksRegLiveness: true
22body:             |
23  bb.1.entry:
24    liveins: $a0, $a1
25
26    ; MIPS32-LABEL: name: f_with_local_linkage
27    ; MIPS32: liveins: $a0, $a1
28    ; MIPS32: [[COPY:%[0-9]+]]:gpr32 = COPY $a0
29    ; MIPS32: [[COPY1:%[0-9]+]]:gpr32 = COPY $a1
30    ; MIPS32: [[ADDu:%[0-9]+]]:gpr32 = ADDu [[COPY1]], [[COPY]]
31    ; MIPS32: $v0 = COPY [[ADDu]]
32    ; MIPS32: RetRA implicit $v0
33    %0:gprb(s32) = COPY $a0
34    %1:gprb(s32) = COPY $a1
35    %2:gprb(s32) = G_ADD %1, %0
36    $v0 = COPY %2(s32)
37    RetRA implicit $v0
38
39...
40---
41name:            call_global
42alignment:       4
43legalized:       true
44regBankSelected: true
45tracksRegLiveness: true
46body:             |
47  bb.1.entry:
48    liveins: $a0, $a1, $t9, $v0
49
50    ; MIPS32-LABEL: name: call_global
51    ; MIPS32: liveins: $a0, $a1, $t9, $v0, $t9, $v0
52    ; MIPS32: [[ADDu:%[0-9]+]]:gpr32 = ADDu $v0, $t9
53    ; MIPS32: [[ADDu1:%[0-9]+]]:gpr32 = ADDu $v0, $t9
54    ; MIPS32: [[COPY:%[0-9]+]]:gpr32 = COPY $a0
55    ; MIPS32: [[COPY1:%[0-9]+]]:gpr32 = COPY $a1
56    ; MIPS32: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp
57    ; MIPS32: [[LW:%[0-9]+]]:gpr32 = LW [[ADDu]], target-flags(mips-got-call) @f :: (load (s32) from got)
58    ; MIPS32: $a0 = COPY [[COPY]]
59    ; MIPS32: $a1 = COPY [[COPY1]]
60    ; MIPS32: $gp = COPY [[ADDu1]]
61    ; MIPS32: JALRPseudo [[LW]], csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $gp, implicit-def $v0
62    ; MIPS32: [[COPY2:%[0-9]+]]:gpr32 = COPY $v0
63    ; MIPS32: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp
64    ; MIPS32: $v0 = COPY [[COPY2]]
65    ; MIPS32: RetRA implicit $v0
66    %4:gpr32 = ADDu $v0, $t9
67    %0:gprb(s32) = COPY $a0
68    %1:gprb(s32) = COPY $a1
69    ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp
70    %3:gpr32(p0) = G_GLOBAL_VALUE target-flags(mips-got-call) @f
71    $a0 = COPY %0(s32)
72    $a1 = COPY %1(s32)
73    $gp = COPY %4
74    JALRPseudo %3(p0), csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $gp, implicit-def $v0
75    %2:gprb(s32) = COPY $v0
76    ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp
77    $v0 = COPY %2(s32)
78    RetRA implicit $v0
79
80...
81---
82name:            call_global_with_local_linkage
83alignment:       4
84legalized:       true
85regBankSelected: true
86tracksRegLiveness: true
87body:             |
88  bb.1.entry:
89    liveins: $a0, $a1, $t9, $v0
90
91    ; MIPS32-LABEL: name: call_global_with_local_linkage
92    ; MIPS32: liveins: $a0, $a1, $t9, $v0, $t9, $v0
93    ; MIPS32: [[ADDu:%[0-9]+]]:gpr32 = ADDu $v0, $t9
94    ; MIPS32: [[ADDu1:%[0-9]+]]:gpr32 = ADDu $v0, $t9
95    ; MIPS32: [[COPY:%[0-9]+]]:gpr32 = COPY $a0
96    ; MIPS32: [[COPY1:%[0-9]+]]:gpr32 = COPY $a1
97    ; MIPS32: ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp
98    ; MIPS32: [[LW:%[0-9]+]]:gpr32 = LW [[ADDu]], target-flags(mips-got) @f_with_local_linkage :: (load (s32) from got)
99    ; MIPS32: [[ADDiu:%[0-9]+]]:gpr32 = ADDiu [[LW]], target-flags(mips-abs-lo) @f_with_local_linkage
100    ; MIPS32: $a0 = COPY [[COPY]]
101    ; MIPS32: $a1 = COPY [[COPY1]]
102    ; MIPS32: $gp = COPY [[ADDu1]]
103    ; MIPS32: JALRPseudo [[ADDiu]], csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $gp, implicit-def $v0
104    ; MIPS32: [[COPY2:%[0-9]+]]:gpr32 = COPY $v0
105    ; MIPS32: ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp
106    ; MIPS32: $v0 = COPY [[COPY2]]
107    ; MIPS32: RetRA implicit $v0
108    %4:gpr32 = ADDu $v0, $t9
109    %0:gprb(s32) = COPY $a0
110    %1:gprb(s32) = COPY $a1
111    ADJCALLSTACKDOWN 16, 0, implicit-def $sp, implicit $sp
112    %3:gpr32(p0) = G_GLOBAL_VALUE @f_with_local_linkage
113    $a0 = COPY %0(s32)
114    $a1 = COPY %1(s32)
115    $gp = COPY %4
116    JALRPseudo %3(p0), csr_o32, implicit-def $ra, implicit-def $sp, implicit $a0, implicit $a1, implicit-def $gp, implicit-def $v0
117    %2:gprb(s32) = COPY $v0
118    ADJCALLSTACKUP 16, 0, implicit-def $sp, implicit $sp
119    $v0 = COPY %2(s32)
120    RetRA implicit $v0
121
122...
123---
124name:            ret_global_int
125alignment:       4
126legalized:       true
127regBankSelected: true
128tracksRegLiveness: true
129body:             |
130  bb.1.entry:
131    ; MIPS32-LABEL: name: ret_global_int
132    ; MIPS32: liveins: $t9, $v0
133    ; MIPS32: [[ADDu:%[0-9]+]]:gpr32 = ADDu $v0, $t9
134    ; MIPS32: [[LW:%[0-9]+]]:gpr32 = LW [[ADDu]], target-flags(mips-got) @val :: (load (s32) from got)
135    ; MIPS32: [[LW1:%[0-9]+]]:gpr32 = LW [[LW]], 0 :: (load (s32) from @val)
136    ; MIPS32: $v0 = COPY [[LW1]]
137    ; MIPS32: RetRA implicit $v0
138    %1:gprb(p0) = G_GLOBAL_VALUE @val
139    %0:gprb(s32) = G_LOAD %1(p0) :: (load (s32) from @val)
140    $v0 = COPY %0(s32)
141    RetRA implicit $v0
142
143...
144---
145name:            ret_global_int_with_local_linkage
146alignment:       4
147legalized:       true
148regBankSelected: true
149tracksRegLiveness: true
150body:             |
151  bb.1.entry:
152    ; MIPS32-LABEL: name: ret_global_int_with_local_linkage
153    ; MIPS32: liveins: $t9, $v0
154    ; MIPS32: [[ADDu:%[0-9]+]]:gpr32 = ADDu $v0, $t9
155    ; MIPS32: [[LW:%[0-9]+]]:gpr32 = LW [[ADDu]], target-flags(mips-got) @val_with_local_linkage :: (load (s32) from got)
156    ; MIPS32: [[ADDiu:%[0-9]+]]:gpr32 = ADDiu [[LW]], target-flags(mips-abs-lo) @val_with_local_linkage
157    ; MIPS32: [[LW1:%[0-9]+]]:gpr32 = LW [[ADDiu]], 0 :: (load (s32) from @val_with_local_linkage)
158    ; MIPS32: $v0 = COPY [[LW1]]
159    ; MIPS32: RetRA implicit $v0
160    %1:gprb(p0) = G_GLOBAL_VALUE @val_with_local_linkage
161    %0:gprb(s32) = G_LOAD %1(p0) :: (load (s32) from @val_with_local_linkage)
162    $v0 = COPY %0(s32)
163    RetRA implicit $v0
164
165...
166