[DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)
[llvm-project.git] / llvm / test / MC / ARM / thumb2-branches.s
blob04c8053741721a0db0085581e2d168560f5bb124
1 @ RUN: llvm-mc -triple=thumbv7-apple-darwin -mcpu=cortex-a8 -show-encoding < %s | FileCheck %s
3 @------------------------------------------------------------------------------
4 @ unconditional branches accept narrow suffix and encode to short encodings
5 @------------------------------------------------------------------------------
7 b.n #-2048
8 b.n #2046
10 @ CHECK: b #-2048 @ encoding: [0x00,0xe4]
11 @ CHECK: b #2046 @ encoding: [0xff,0xe3]
13 @------------------------------------------------------------------------------
14 @ unconditional branches accept wide suffix and encode to wide encodings
15 @------------------------------------------------------------------------------
17 b.w #-2048
18 b.w #2046
19 b.w #-1677216
20 b.w #1677214
22 @ CHECK: b.w #-2048 @ encoding: [0xff,0xf7,0x00,0xbc]
23 @ CHECK: b.w #2046 @ encoding: [0x00,0xf0,0xff,0xbb]
24 @ CHECK: b.w #-1677216 @ encoding: [0x66,0xf6,0x30,0xbc]
25 @ CHECK: b.w #1677214 @ encoding: [0x99,0xf1,0xcf,0xbb]
27 @------------------------------------------------------------------------------
28 @ unconditional branches without width suffix encode depending of offset size
29 @------------------------------------------------------------------------------
31 b #-2048
32 b #2046
33 b #-2050
34 b #2048
35 b #-1677216
36 b #1677214
38 @ CHECK: b #-2048 @ encoding: [0x00,0xe4]
39 @ CHECK: b #2046 @ encoding: [0xff,0xe3]
40 @ CHECK: b.w #-2050 @ encoding: [0xff,0xf7,0xff,0xbb]
41 @ CHECK: b.w #2048 @ encoding: [0x00,0xf0,0x00,0xbc]
42 @ CHECK: b.w #-1677216 @ encoding: [0x66,0xf6,0x30,0xbc]
43 @ CHECK: b.w #1677214 @ encoding: [0x99,0xf1,0xcf,0xbb]
45 @------------------------------------------------------------------------------
46 @ unconditional branches with width narrow suffix in IT block
47 @------------------------------------------------------------------------------
49 it eq
50 beq.n #-2048
51 it ne
52 bne.n #-2046
54 @ CHECK: it eq @ encoding: [0x08,0xbf]
55 @ CHECK: beq #-2048 @ encoding: [0x00,0xe4]
56 @ CHECK: it ne @ encoding: [0x18,0xbf]
57 @ CHECK: bne #-2046 @ encoding: [0x01,0xe4]
59 @------------------------------------------------------------------------------
60 @ unconditional branches with wide suffix in IT block
61 @------------------------------------------------------------------------------
63 it gt
64 bgt.w #-2048
65 it le
66 ble.w #2046
67 it ge
68 bge.w #-1677216
69 it lt
70 blt.w #1677214
72 @ CHECK: it gt @ encoding: [0xc8,0xbf]
73 @ CHECK: bgt.w #-2048 @ encoding: [0xff,0xf7,0x00,0xbc]
74 @ CHECK: it le @ encoding: [0xd8,0xbf]
75 @ CHECK: ble.w #2046 @ encoding: [0x00,0xf0,0xff,0xbb]
76 @ CHECK: it ge @ encoding: [0xa8,0xbf]
77 @ CHECK: bge.w #-1677216 @ encoding: [0x66,0xf6,0x30,0xbc]
78 @ CHECK: it lt @ encoding: [0xb8,0xbf]
79 @ CHECK: blt.w #1677214 @ encoding: [0x99,0xf1,0xcf,0xbb]
81 @------------------------------------------------------------------------------
82 @ conditional branches accept narrow suffix and encode to short encodings
83 @------------------------------------------------------------------------------
85 beq.n #-256
86 bne.n #254
88 @ CHECK: beq #-256 @ encoding: [0x80,0xd0]
89 @ CHECK: bne #254 @ encoding: [0x7f,0xd1]
91 @------------------------------------------------------------------------------
92 @ unconditional branches accept wide suffix and encode to wide encodings
93 @------------------------------------------------------------------------------
95 bl.w #256
96 it ne
97 blne.w #256
98 bmi.w #-256
99 bne.w #254
100 blt.w #-1048576
101 bge.w #1048574
103 @ CHECK: bl #256 @ encoding: [0x00,0xf0,0x80,0xf8]
104 @ CHECK: it ne @ encoding: [0x18,0xbf]
105 @ CHECK: blne #256 @ encoding: [0x00,0xf0,0x80,0xf8]
106 @ CHECK: bmi.w #-256 @ encoding: [0x3f,0xf5,0x80,0xaf]
107 @ CHECK: bne.w #254 @ encoding: [0x40,0xf0,0x7f,0x80]
108 @ CHECK: blt.w #-1048576 @ encoding: [0xc0,0xf6,0x00,0x80]
109 @ CHECK: bge.w #1048574 @ encoding: [0xbf,0xf2,0xff,0xaf]
111 @------------------------------------------------------------------------------
112 @ unconditional branches without width suffix encode depending of offset size
113 @------------------------------------------------------------------------------
115 bne #-256
116 bgt #254
117 bne #-258
118 bgt #256
119 bne #-1048576
120 bgt #1048574
122 @ CHECK: bne #-256 @ encoding: [0x80,0xd1]
123 @ CHECK: bgt #254 @ encoding: [0x7f,0xdc]
124 @ CHECK: bne.w #-258 @ encoding: [0x7f,0xf4,0x7f,0xaf]
125 @ CHECK: bgt.w #256 @ encoding: [0x00,0xf3,0x80,0x80]
126 @ CHECK: bne.w #-1048576 @ encoding: [0x40,0xf4,0x00,0x80]
127 @ CHECK: bgt.w #1048574 @ encoding: [0x3f,0xf3,0xff,0xaf]
129 @------------------------------------------------------------------------------
130 @ same branch insturction encoding to conditional or unconditional depending
131 @ on whether it is in an IT block or not
132 @------------------------------------------------------------------------------
134 it eq
135 addeq r0, r1
136 bne #128
138 @ CHECK: it eq @ encoding: [0x08,0xbf]
139 @ CHECK: addeq r0, r1 @ encoding: [0x08,0x44]
140 @ CHECK: bne #128 @ encoding: [0x40,0xd1]
142 ite eq
143 addeq r0, r1
144 bne #128
146 @ CHECK: ite eq @ encoding: [0x0c,0xbf]
147 @ CHECK: addeq r0, r1 @ encoding: [0x08,0x44]
148 @ CHECK: bne #128 @ encoding: [0x40,0xe0]
150 @ RUN: llvm-mc -triple=thumbv7-apple-darwin -mcpu=cortex-a8 -show-encoding < %s | FileCheck %s
152 @------------------------------------------------------------------------------
153 @ unconditional branches accept narrow suffix and encode to short encodings
154 @------------------------------------------------------------------------------
156 b.n #-2048
157 b.n #2046
159 @ CHECK: b #-2048 @ encoding: [0x00,0xe4]
160 @ CHECK: b #2046 @ encoding: [0xff,0xe3]
162 @------------------------------------------------------------------------------
163 @ unconditional branches accept wide suffix and encode to wide encodings
164 @------------------------------------------------------------------------------
166 b.w #-2048
167 b.w #2046
168 b.w #-1677216
169 b.w #1677214
171 @ CHECK: b.w #-2048 @ encoding: [0xff,0xf7,0x00,0xbc]
172 @ CHECK: b.w #2046 @ encoding: [0x00,0xf0,0xff,0xbb]
173 @ CHECK: b.w #-1677216 @ encoding: [0x66,0xf6,0x30,0xbc]
174 @ CHECK: b.w #1677214 @ encoding: [0x99,0xf1,0xcf,0xbb]
176 @------------------------------------------------------------------------------
177 @ unconditional branches without width suffix encode depending of offset size
178 @------------------------------------------------------------------------------
180 b #-2048
181 b #2046
182 b #-2050
183 b #2048
184 b #-1677216
185 b #1677214
187 @ CHECK: b #-2048 @ encoding: [0x00,0xe4]
188 @ CHECK: b #2046 @ encoding: [0xff,0xe3]
189 @ CHECK: b.w #-2050 @ encoding: [0xff,0xf7,0xff,0xbb]
190 @ CHECK: b.w #2048 @ encoding: [0x00,0xf0,0x00,0xbc]
191 @ CHECK: b.w #-1677216 @ encoding: [0x66,0xf6,0x30,0xbc]
192 @ CHECK: b.w #1677214 @ encoding: [0x99,0xf1,0xcf,0xbb]
194 @------------------------------------------------------------------------------
195 @ unconditional branches with width narrow suffix in IT block
196 @------------------------------------------------------------------------------
198 it eq
199 beq.n #-2048
200 it ne
201 bne.n #-2046
203 @ CHECK: it eq @ encoding: [0x08,0xbf]
204 @ CHECK: beq #-2048 @ encoding: [0x00,0xe4]
205 @ CHECK: it ne @ encoding: [0x18,0xbf]
206 @ CHECK: bne #-2046 @ encoding: [0x01,0xe4]
208 @------------------------------------------------------------------------------
209 @ unconditional branches with wide suffix in IT block
210 @------------------------------------------------------------------------------
212 it gt
213 bgt.w #-2048
214 it le
215 ble.w #2046
216 it ge
217 bge.w #-1677216
218 it lt
219 blt.w #1677214
221 @ CHECK: it gt @ encoding: [0xc8,0xbf]
222 @ CHECK: bgt.w #-2048 @ encoding: [0xff,0xf7,0x00,0xbc]
223 @ CHECK: it le @ encoding: [0xd8,0xbf]
224 @ CHECK: ble.w #2046 @ encoding: [0x00,0xf0,0xff,0xbb]
225 @ CHECK: it ge @ encoding: [0xa8,0xbf]
226 @ CHECK: bge.w #-1677216 @ encoding: [0x66,0xf6,0x30,0xbc]
227 @ CHECK: it lt @ encoding: [0xb8,0xbf]
228 @ CHECK: blt.w #1677214 @ encoding: [0x99,0xf1,0xcf,0xbb]
230 @------------------------------------------------------------------------------
231 @ conditional branches accept narrow suffix and encode to short encodings
232 @------------------------------------------------------------------------------
234 beq.n #-256
235 bne.n #254
237 @ CHECK: beq #-256 @ encoding: [0x80,0xd0]
238 @ CHECK: bne #254 @ encoding: [0x7f,0xd1]
240 @------------------------------------------------------------------------------
241 @ unconditional branches accept wide suffix and encode to wide encodings
242 @------------------------------------------------------------------------------
244 bmi.w #-256
245 bne.w #254
246 blt.w #-1048576
247 bge.w #1048574
249 @ CHECK: bmi.w #-256 @ encoding: [0x3f,0xf5,0x80,0xaf]
250 @ CHECK: bne.w #254 @ encoding: [0x40,0xf0,0x7f,0x80]
251 @ CHECK: blt.w #-1048576 @ encoding: [0xc0,0xf6,0x00,0x80]
252 @ CHECK: bge.w #1048574 @ encoding: [0xbf,0xf2,0xff,0xaf]
254 @------------------------------------------------------------------------------
255 @ unconditional branches without width suffix encode depending of offset size
256 @------------------------------------------------------------------------------
258 bne #-256
259 bgt #254
260 bne #-258
261 bgt #256
262 bne #-1048576
263 bgt #1048574
265 @ CHECK: bne #-256 @ encoding: [0x80,0xd1]
266 @ CHECK: bgt #254 @ encoding: [0x7f,0xdc]
267 @ CHECK: bne.w #-258 @ encoding: [0x7f,0xf4,0x7f,0xaf]
268 @ CHECK: bgt.w #256 @ encoding: [0x00,0xf3,0x80,0x80]
269 @ CHECK: bne.w #-1048576 @ encoding: [0x40,0xf4,0x00,0x80]
270 @ CHECK: bgt.w #1048574 @ encoding: [0x3f,0xf3,0xff,0xaf]
272 @------------------------------------------------------------------------------
273 @ same branch insturction encoding to conditional or unconditional depending
274 @ on whether it is in an IT block or not
275 @------------------------------------------------------------------------------
277 it eq
278 addeq r0, r1
279 bne #128
281 @ CHECK: it eq @ encoding: [0x08,0xbf]
282 @ CHECK: addeq r0, r1 @ encoding: [0x08,0x44]
283 @ CHECK: bne #128 @ encoding: [0x40,0xd1]
285 ite eq
286 addeq r0, r1
287 bne #128
289 @ CHECK: ite eq @ encoding: [0x0c,0xbf]
290 @ CHECK: addeq r0, r1 @ encoding: [0x08,0x44]
291 @ CHECK: bne #128 @ encoding: [0x40,0xe0]
294 @------------------------------------------------------------------------------
295 @ Branch targets destined for ARM mode must == 0 (mod 4), otherwise (mod 2).
296 @------------------------------------------------------------------------------
298 b #2
299 bl #2
300 beq #2
301 cbz r0, #2
302 @ N.b. destination is "align(PC, 4) + imm" so imm is still 4-byte
303 @ aligned even though current PC may not and destination must be.
304 blx #4
306 @ CHECK: b #2 @ encoding: [0x01,0xe0]
307 @ CHECK: bl #2 @ encoding: [0x00,0xf0,0x01,0xf8]
308 @ CHECK: beq #2 @ encoding: [0x01,0xd0]
309 @ CHECK: cbz r0, #2 @ encoding: [0x08,0xb1]
310 @ CHECK: blx #4 @ encoding: [0x00,0xf0,0x02,0xe8]