[DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)
[llvm-project.git] / llvm / test / MC / Mips / cpsetup.s
blob15e9c4db15f29bb85888b88d79d46ba93f139ef6
1 # RUN: llvm-mc -triple mips-unknown-linux -target-abi o32 -filetype=obj -o - %s | \
2 # RUN: llvm-objdump -d -r -z - | FileCheck --check-prefixes=ALL,O32 %s
4 # RUN: llvm-mc -triple mips-unknown-linux -target-abi o32 %s | \
5 # RUN: FileCheck -check-prefixes=ASM,ASM-O32 %s
7 # FIXME: Now we check .cpsetup expansion for `-mno-shared` case only.
8 # We also need to implement/check the `-mshared` case.
9 # RUN: llvm-mc -triple mips64-unknown-linux -target-abi n32 -filetype=obj -o - %s | \
10 # RUN: llvm-objdump -d -r -z - | \
11 # RUN: FileCheck -check-prefixes=ALL,NXX,N32 %s
13 # RUN: llvm-mc -triple mips64-unknown-linux -target-abi n32 %s | \
14 # RUN: FileCheck -check-prefixes=ASM,ASM-N32 %s
16 # RUN: llvm-mc -triple mips64-unknown-linux %s -filetype=obj -o - | \
17 # RUN: llvm-objdump -d -r -z - | \
18 # RUN: FileCheck -check-prefixes=ALL,NXX,N64 %s
20 # RUN: llvm-mc -triple mips64-unknown-linux %s | \
21 # RUN: FileCheck -check-prefixes=ASM,ASM-N64 %s
23 .text
24 .option pic2
25 t1:
26 .cpsetup $25, 8, __cerror
27 nop
28 .cpreturn
29 nop
31 # ALL-LABEL: <t1>:
32 # ASM-LABEL: t1:
34 # O32-NOT: __cerror
36 # NXX-NEXT: sd $gp, 8($sp)
37 # NXX-NEXT: lui $gp, 0
38 # N32-NEXT: R_MIPS_HI16 __gnu_local_gp
39 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_HI16 __cerror
40 # NXX-NEXT: addiu $gp, $gp, 0
41 # N32-NEXT: R_MIPS_LO16 __gnu_local_gp
42 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_LO16 __cerror
43 # N64-NEXT: daddu $gp, $gp, $25
45 # ASM-NEXT: .cpsetup $25, 8, __cerror
47 # ALL-NEXT: nop
49 # ASM: .cpreturn
50 # NXX-NEXT: ld $gp, 8($sp)
52 # ALL-NEXT: nop
54 t2:
55 .cpsetup $25, $2, __cerror
56 nop
57 .cpreturn
58 nop
60 # ALL-LABEL: <t2>:
61 # ASM-LABEL: t2:
63 # O32-NOT: __cerror
65 # NXX-NEXT: move $2, $gp
66 # NXX-NEXT: lui $gp, 0
67 # N32-NEXT: R_MIPS_HI16 __gnu_local_gp
68 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_HI16 __cerror
69 # NXX-NEXT: addiu $gp, $gp, 0
70 # N32-NEXT: R_MIPS_LO16 __gnu_local_gp
71 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_LO16 __cerror
72 # N64-NEXT: daddu $gp, $gp, $25
74 # ASM-NEXT: .cpsetup $25, $2, __cerror
76 # ALL-NEXT: nop
78 # ASM: .cpreturn
79 # NXX-NEXT: move $gp, $2
81 # ALL-NEXT: nop
83 # .cpsetup with local labels (PR22518):
85 # The '1:' label isn't emitted in all cases but we still want a label to match
86 # so we force one here.
88 t3:
89 nop
91 .cpsetup $25, $2, 1b
92 nop
93 sub $3, $3, $2
95 # ALL-LABEL: <t3>:
96 # ASM-LABEL: t3:
97 # ALL-NEXT: nop
99 # O32-NEXT: nop
100 # O32-NEXT: sub $3, $3, $2
102 # NXX-NEXT: move $2, $gp
103 # NXX-NEXT: lui $gp, 0
104 # N32-NEXT: {{^ *0+}}38: R_MIPS_HI16 __gnu_local_gp
105 # N64-NEXT: {{^ *0+}}40: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_HI16 .text
106 # NXX-NEXT: addiu $gp, $gp, 0
107 # N32-NEXT: {{^ *0+}}3c: R_MIPS_LO16 __gnu_local_gp
108 # N64-NEXT: {{^ *0+}}44: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_LO16 .text
109 # N64-NEXT: daddu $gp, $gp, $25
110 # NXX-NEXT: nop
111 # NXX-NEXT: sub $3, $3, $2
113 # ASM-O32: [[LABEL:\$tmp0]]:
114 # ASM-N32: [[LABEL:\.Ltmp0]]:
115 # ASM-N64: [[LABEL:\.Ltmp0]]:
116 # ASM-NEXT: .cpsetup $25, $2, [[LABEL]]
118 # Ensure we have at least one instruction between labels so that the labels
119 # we're matching aren't removed.
121 # ALL-NEXT: nop
123 .option pic0
126 .cpsetup $25, 8, __cerror
128 .cpreturn
131 # Testing that .cpsetup expands to nothing in this case
132 # by checking that the next instruction after the first
133 # nop is also a 'nop'.
135 # ALL-LABEL: <t4>:
136 # ASM-LABEL: t4:
138 # NXX-NEXT: nop
139 # NXX-NEXT: nop
140 # NXX-NEXT: nop
142 # ASM-NEXT: nop
143 # ASM-NEXT: .cpsetup $25, 8, __cerror
144 # ASM-NEXT: nop
145 # ASM-NEXT: .cpreturn
146 # ASM-NEXT: nop
148 # Test that we accept constant expressions.
149 .option pic2
151 .cpsetup $25, ((8*4) - (3*8)), __cerror
154 # ALL-LABEL: <t5>:
155 # ASM-LABEL: t5:
157 # O32-NOT: __cerror
159 # NXX-NEXT: sd $gp, 8($sp)
160 # NXX-NEXT: lui $gp, 0
161 # N32-NEXT: R_MIPS_HI16 __gnu_local_gp
162 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_HI16 __cerror
163 # NXX-NEXT: addiu $gp, $gp, 0
164 # N32-NEXT: R_MIPS_LO16 __gnu_local_gp
165 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_LO16 __cerror
166 # N64-NEXT: daddu $gp, $gp, $25
168 # ASM-NEXT: .cpsetup $25, 8, __cerror
170 # ALL-NEXT: nop
172 t1b:
173 IMM_8 = 8
174 .cpsetup $25, IMM_8, __cerror
176 .cpreturn
179 # ALL-LABEL: <t1b>:
180 # ASM-LABEL: t1b:
181 # ASM-NEXT: .set IMM_8, 8
183 # O32-NOT: __cerror
185 # NXX-NEXT: sd $gp, 8($sp)
186 # NXX-NEXT: lui $gp, 0
187 # N32-NEXT: R_MIPS_HI16 __gnu_local_gp
188 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_HI16 __cerror
189 # NXX-NEXT: addiu $gp, $gp, 0
190 # N32-NEXT: R_MIPS_LO16 __gnu_local_gp
191 # N64-NEXT: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_LO16 __cerror
192 # N64-NEXT: daddu $gp, $gp, $25
194 # ASM-NEXT: .cpsetup $25, 8, __cerror
196 # ALL-NEXT: nop
198 # ASM: .cpreturn
199 # NXX-NEXT: ld $gp, 8($sp)
201 # ALL-NEXT: nop