[Hexagon] Factoring classes out of store patterns.
[oota-llvm.git] / lib / Target / Hexagon / HexagonOperands.td
1 //===- HexagonOperands.td - Hexagon immediate processing -*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illnois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // Immediate operands.
11
12 let PrintMethod = "printImmOperand" in {
13   // f32Ext type is used to identify constant extended floating point immediates.
14   def f32Ext : Operand<f32>;
15   def s32Imm : Operand<i32>;
16   def s26_6Imm : Operand<i32>;
17   def s16Imm : Operand<i32>;
18   def s12Imm : Operand<i32>;
19   def s11Imm : Operand<i32>;
20   def s11_0Imm : Operand<i32>;
21   def s11_1Imm : Operand<i32>;
22   def s11_2Imm : Operand<i32>;
23   def s11_3Imm : Operand<i32>;
24   def s10Imm : Operand<i32>;
25   def s9Imm : Operand<i32>;
26   def m9Imm : Operand<i32>;
27   def s8Imm : Operand<i32>;
28   def s8Imm64 : Operand<i64>;
29   def s6Imm : Operand<i32>;
30   def s4Imm : Operand<i32>;
31   def s4_0Imm : Operand<i32>;
32   def s4_1Imm : Operand<i32>;
33   def s4_2Imm : Operand<i32>;
34   def s4_3Imm : Operand<i32>;
35   def u64Imm : Operand<i64>;
36   def u32Imm : Operand<i32>;
37   def u26_6Imm : Operand<i32>;
38   def u16Imm : Operand<i32>;
39   def u16_0Imm : Operand<i32>;
40   def u16_1Imm : Operand<i32>;
41   def u16_2Imm : Operand<i32>;
42   def u16_3Imm : Operand<i32>;
43   def u11_3Imm : Operand<i32>;
44   def u10Imm : Operand<i32>;
45   def u9Imm : Operand<i32>;
46   def u8Imm : Operand<i32>;
47   def u7Imm : Operand<i32>;
48   def u6Imm : Operand<i32>;
49   def u6_0Imm : Operand<i32>;
50   def u6_1Imm : Operand<i32>;
51   def u6_2Imm : Operand<i32>;
52   def u6_3Imm : Operand<i32>;
53   def u5Imm : Operand<i32>;
54   def u4Imm : Operand<i32>;
55   def u3Imm : Operand<i32>;
56   def u2Imm : Operand<i32>;
57   def u1Imm : Operand<i32>;
58   def n8Imm : Operand<i32>;
59   def m6Imm : Operand<i32>;
60 }
61
62 let PrintMethod = "printNOneImmOperand" in
63 def nOneImm : Operand<i32>;
64
65 //
66 // Immediate predicates
67 //
68 def s32ImmPred  : PatLeaf<(i32 imm), [{
69   // s32ImmPred predicate - True if the immediate fits in a 32-bit sign extended
70   // field.
71   int64_t v = (int64_t)N->getSExtValue();
72   return isInt<32>(v);
73 }]>;
74
75 def s32_24ImmPred  : PatLeaf<(i32 imm), [{
76   // s32_24ImmPred predicate - True if the immediate fits in a 32-bit sign
77   // extended field that is a multiple of 0x1000000.
78   int64_t v = (int64_t)N->getSExtValue();
79   return isShiftedInt<32,24>(v);
80 }]>;
81
82 def s32_16s8ImmPred  : PatLeaf<(i32 imm), [{
83   // s32_16s8ImmPred predicate - True if the immediate fits in a 32-bit sign
84   // extended field that is a multiple of 0x10000.
85   int64_t v = (int64_t)N->getSExtValue();
86   return isShiftedInt<24,16>(v);
87 }]>;
88
89 def s26_6ImmPred  : PatLeaf<(i32 imm), [{
90   // s26_6ImmPred predicate - True if the immediate fits in a 32-bit
91   // sign extended field.
92   int64_t v = (int64_t)N->getSExtValue();
93   return isShiftedInt<26,6>(v);
94 }]>;
95
96
97 def s16ImmPred  : PatLeaf<(i32 imm), [{
98   // s16ImmPred predicate - True if the immediate fits in a 16-bit sign extended
99   // field.
100   int64_t v = (int64_t)N->getSExtValue();
101   return isInt<16>(v);
102 }]>;
103
104
105 def s13ImmPred  : PatLeaf<(i32 imm), [{
106   // s13ImmPred predicate - True if the immediate fits in a 13-bit sign extended
107   // field.
108   int64_t v = (int64_t)N->getSExtValue();
109   return isInt<13>(v);
110 }]>;
111
112
113 def s12ImmPred  : PatLeaf<(i32 imm), [{
114   // s12ImmPred predicate - True if the immediate fits in a 12-bit
115   // sign extended field.
116   int64_t v = (int64_t)N->getSExtValue();
117   return isInt<12>(v);
118 }]>;
119
120 def s11_0ImmPred  : PatLeaf<(i32 imm), [{
121   // s11_0ImmPred predicate - True if the immediate fits in a 11-bit
122   // sign extended field.
123   int64_t v = (int64_t)N->getSExtValue();
124   return isInt<11>(v);
125 }]>;
126
127
128 def s11_1ImmPred  : PatLeaf<(i32 imm), [{
129   // s11_1ImmPred predicate - True if the immediate fits in a 12-bit
130   // sign extended field and is a multiple of 2.
131   int64_t v = (int64_t)N->getSExtValue();
132   return isShiftedInt<11,1>(v);
133 }]>;
134
135
136 def s11_2ImmPred  : PatLeaf<(i32 imm), [{
137   // s11_2ImmPred predicate - True if the immediate fits in a 13-bit
138   // sign extended field and is a multiple of 4.
139   int64_t v = (int64_t)N->getSExtValue();
140   return isShiftedInt<11,2>(v);
141 }]>;
142
143
144 def s11_3ImmPred  : PatLeaf<(i32 imm), [{
145   // s11_3ImmPred predicate - True if the immediate fits in a 14-bit
146   // sign extended field and is a multiple of 8.
147   int64_t v = (int64_t)N->getSExtValue();
148   return isShiftedInt<11,3>(v);
149 }]>;
150
151
152 def s10ImmPred  : PatLeaf<(i32 imm), [{
153   // s10ImmPred predicate - True if the immediate fits in a 10-bit sign extended
154   // field.
155   int64_t v = (int64_t)N->getSExtValue();
156   return isInt<10>(v);
157 }]>;
158
159
160 def s9ImmPred  : PatLeaf<(i32 imm), [{
161   // s9ImmPred predicate - True if the immediate fits in a 9-bit sign extended
162   // field.
163   int64_t v = (int64_t)N->getSExtValue();
164   return isInt<9>(v);
165 }]>;
166
167 def m9ImmPred  : PatLeaf<(i32 imm), [{
168   // m9ImmPred predicate - True if the immediate fits in a 9-bit magnitude
169   // field. The range of m9 is -255 to 255.
170   int64_t v = (int64_t)N->getSExtValue();
171   return isInt<9>(v) && (v != -256);
172 }]>;
173
174 def s8ImmPred  : PatLeaf<(i32 imm), [{
175   // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
176   // field.
177   int64_t v = (int64_t)N->getSExtValue();
178   return isInt<8>(v);
179 }]>;
180
181
182 def s8Imm64Pred  : PatLeaf<(i64 imm), [{
183   // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
184   // field.
185   int64_t v = (int64_t)N->getSExtValue();
186   return isInt<8>(v);
187 }]>;
188
189
190 def s6ImmPred  : PatLeaf<(i32 imm), [{
191   // s6ImmPred predicate - True if the immediate fits in a 6-bit sign extended
192   // field.
193   int64_t v = (int64_t)N->getSExtValue();
194   return isInt<6>(v);
195 }]>;
196
197
198 def s4_0ImmPred  : PatLeaf<(i32 imm), [{
199   // s4_0ImmPred predicate - True if the immediate fits in a 4-bit sign extended
200   // field.
201   int64_t v = (int64_t)N->getSExtValue();
202   return isInt<4>(v);
203 }]>;
204
205
206 def s4_1ImmPred  : PatLeaf<(i32 imm), [{
207   // s4_1ImmPred predicate - True if the immediate fits in a 4-bit sign extended
208   // field of 2.
209   int64_t v = (int64_t)N->getSExtValue();
210   return isShiftedInt<4,1>(v);
211 }]>;
212
213
214 def s4_2ImmPred  : PatLeaf<(i32 imm), [{
215   // s4_2ImmPred predicate - True if the immediate fits in a 4-bit sign extended
216   // field that is a multiple of 4.
217   int64_t v = (int64_t)N->getSExtValue();
218   return isShiftedInt<4,2>(v);
219 }]>;
220
221
222 def s4_3ImmPred  : PatLeaf<(i32 imm), [{
223   // s4_3ImmPred predicate - True if the immediate fits in a 4-bit sign extended
224   // field that is a multiple of 8.
225   int64_t v = (int64_t)N->getSExtValue();
226   return isShiftedInt<4,3>(v);
227 }]>;
228
229
230 def u64ImmPred  : PatLeaf<(i64 imm), [{
231   // Adding "N ||" to suppress gcc unused warning.
232   return (N || true);
233 }]>;
234
235 def u32ImmPred  : PatLeaf<(i32 imm), [{
236   // u32ImmPred predicate - True if the immediate fits in a 32-bit field.
237   int64_t v = (int64_t)N->getSExtValue();
238   return isUInt<32>(v);
239 }]>;
240
241 def u26_6ImmPred  : PatLeaf<(i32 imm), [{
242   // u26_6ImmPred - True if the immediate fits in a 32-bit field and
243   // is a multiple of 64.
244   int64_t v = (int64_t)N->getSExtValue();
245   return isShiftedUInt<26,6>(v);
246 }]>;
247
248 def u16ImmPred  : PatLeaf<(i32 imm), [{
249   // u16ImmPred predicate - True if the immediate fits in a 16-bit unsigned
250   // field.
251   int64_t v = (int64_t)N->getSExtValue();
252   return isUInt<16>(v);
253 }]>;
254
255 def u16_s8ImmPred  : PatLeaf<(i32 imm), [{
256   // u16_s8ImmPred predicate - True if the immediate fits in a 16-bit sign
257   // extended s8 field.
258   int64_t v = (int64_t)N->getSExtValue();
259   return isShiftedUInt<16,8>(v);
260 }]>;
261
262 def u16_0ImmPred  : PatLeaf<(i32 imm), [{
263   // True if the immediate fits in a 16-bit unsigned field.
264   int64_t v = (int64_t)N->getSExtValue();
265   return isUInt<16>(v);
266 }]>;
267
268 def u11_3ImmPred : PatLeaf<(i32 imm), [{
269   // True if the immediate fits in a 14-bit unsigned field, and the lowest
270   // three bits are 0.
271   int64_t v = (int64_t)N->getSExtValue();
272   return isShiftedUInt<11,3>(v);
273 }]>;
274
275 def u9ImmPred  : PatLeaf<(i32 imm), [{
276   // u9ImmPred predicate - True if the immediate fits in a 9-bit unsigned
277   // field.
278   int64_t v = (int64_t)N->getSExtValue();
279   return isUInt<9>(v);
280 }]>;
281
282
283 def u8ImmPred  : PatLeaf<(i32 imm), [{
284   // u8ImmPred predicate - True if the immediate fits in a 8-bit unsigned
285   // field.
286   int64_t v = (int64_t)N->getSExtValue();
287   return isUInt<8>(v);
288 }]>;
289
290 def u7StrictPosImmPred : ImmLeaf<i32, [{
291   // u7StrictPosImmPred predicate - True if the immediate fits in an 7-bit
292   // unsigned field and is strictly greater than 0.
293   return isUInt<7>(Imm) && Imm > 0;
294 }]>;
295
296 def u7ImmPred  : PatLeaf<(i32 imm), [{
297   // u7ImmPred predicate - True if the immediate fits in a 7-bit unsigned
298   // field.
299   int64_t v = (int64_t)N->getSExtValue();
300   return isUInt<7>(v);
301 }]>;
302
303
304 def u6ImmPred  : PatLeaf<(i32 imm), [{
305   // u6ImmPred predicate - True if the immediate fits in a 6-bit unsigned
306   // field.
307   int64_t v = (int64_t)N->getSExtValue();
308   return isUInt<6>(v);
309 }]>;
310
311 def u6_0ImmPred  : PatLeaf<(i32 imm), [{
312   // u6_0ImmPred predicate - True if the immediate fits in a 6-bit unsigned
313   // field. Same as u6ImmPred.
314   int64_t v = (int64_t)N->getSExtValue();
315   return isUInt<6>(v);
316 }]>;
317
318 def u6_1ImmPred  : PatLeaf<(i32 imm), [{
319   // u6_1ImmPred predicate - True if the immediate fits in a 7-bit unsigned
320   // field that is 1 bit alinged - multiple of 2.
321   int64_t v = (int64_t)N->getSExtValue();
322   return isShiftedUInt<6,1>(v);
323 }]>;
324
325 def u6_2ImmPred  : PatLeaf<(i32 imm), [{
326   // u6_2ImmPred predicate - True if the immediate fits in a 8-bit unsigned
327   // field that is 2 bits alinged - multiple of 4.
328   int64_t v = (int64_t)N->getSExtValue();
329   return isShiftedUInt<6,2>(v);
330 }]>;
331
332 def u6_3ImmPred  : PatLeaf<(i32 imm), [{
333   // u6_3ImmPred predicate - True if the immediate fits in a 9-bit unsigned
334   // field that is 3 bits alinged - multiple of 8.
335   int64_t v = (int64_t)N->getSExtValue();
336   return isShiftedUInt<6,3>(v);
337 }]>;
338
339 def u5ImmPred  : PatLeaf<(i32 imm), [{
340   // u5ImmPred predicate - True if the immediate fits in a 5-bit unsigned
341   // field.
342   int64_t v = (int64_t)N->getSExtValue();
343   return isUInt<5>(v);
344 }]>;
345
346 def u4ImmPred  : PatLeaf<(i32 imm), [{
347   // u4ImmPred predicate - True if the immediate fits in a 4-bit unsigned
348   // field.
349   int64_t v = (int64_t)N->getSExtValue();
350   return isUInt<4>(v);
351 }]>;
352
353 def u3ImmPred  : PatLeaf<(i32 imm), [{
354   // u3ImmPred predicate - True if the immediate fits in a 3-bit unsigned
355   // field.
356   int64_t v = (int64_t)N->getSExtValue();
357   return isUInt<3>(v);
358 }]>;
359
360
361 def u2ImmPred  : PatLeaf<(i32 imm), [{
362   // u2ImmPred predicate - True if the immediate fits in a 2-bit unsigned
363   // field.
364   int64_t v = (int64_t)N->getSExtValue();
365   return isUInt<2>(v);
366 }]>;
367
368
369 def u1ImmPred  : PatLeaf<(i1 imm), [{
370   // u1ImmPred predicate - True if the immediate fits in a 1-bit unsigned
371   // field.
372   int64_t v = (int64_t)N->getSExtValue();
373   return isUInt<1>(v);
374 }]>;
375
376 def m5BImmPred  : PatLeaf<(i32 imm), [{
377   // m5BImmPred predicate - True if the (char) number is in range -1 .. -31
378   // and will fit in a 5 bit field when made positive, for use in memops.
379   // this is specific to the zero extending of a negative by CombineInstr
380   int8_t v = (int8_t)N->getSExtValue();
381   return (-31 <= v && v <= -1);
382 }]>;
383
384 def m5HImmPred  : PatLeaf<(i32 imm), [{
385   // m5HImmPred predicate - True if the (short) number is in range -1 .. -31
386   // and will fit in a 5 bit field when made positive, for use in memops.
387   // this is specific to the zero extending of a negative by CombineInstr
388   int16_t v = (int16_t)N->getSExtValue();
389   return (-31 <= v && v <= -1);
390 }]>;
391
392 def m5ImmPred  : PatLeaf<(i32 imm), [{
393   // m5ImmPred predicate - True if the number is in range -1 .. -31
394   // and will fit in a 5 bit field when made positive, for use in memops.
395   int64_t v = (int64_t)N->getSExtValue();
396   return (-31 <= v && v <= -1);
397 }]>;
398
399 //InN means negative integers in [-(2^N - 1), 0]
400 def n8ImmPred  : PatLeaf<(i32 imm), [{
401   // n8ImmPred predicate - True if the immediate fits in a 8-bit signed
402   // field.
403   int64_t v = (int64_t)N->getSExtValue();
404   return (-255 <= v && v <= 0);
405 }]>;
406
407 def nOneImmPred  : PatLeaf<(i32 imm), [{
408   // nOneImmPred predicate - True if the immediate is -1.
409   int64_t v = (int64_t)N->getSExtValue();
410   return (-1 == v);
411 }]>;
412
413 def Set5ImmPred : PatLeaf<(i32 imm), [{
414   // Set5ImmPred predicate - True if the number is in the series of values.
415   // [ 2^0, 2^1, ... 2^31 ]
416   // For use in setbit immediate.
417   uint32_t v = (int32_t)N->getSExtValue();
418   // Constrain to 32 bits, and then check for single bit.
419   return ImmIsSingleBit(v);
420 }]>;
421
422 def Clr5ImmPred : PatLeaf<(i32 imm), [{
423   // Clr5ImmPred predicate - True if the number is in the series of
424   // bit negated values.
425   // [ 2^0, 2^1, ... 2^31 ]
426   // For use in clrbit immediate.
427   // Note: we are bit NOTing the value.
428   uint32_t v = ~ (int32_t)N->getSExtValue();
429   // Constrain to 32 bits, and then check for single bit.
430   return ImmIsSingleBit(v);
431 }]>;
432
433 def SetClr5ImmPred : PatLeaf<(i32 imm), [{
434   // SetClr5ImmPred predicate - True if the immediate is in range 0..31.
435   int32_t v = (int32_t)N->getSExtValue();
436   return (v >= 0 && v <= 31);
437 }]>;
438
439 def Set4ImmPred : PatLeaf<(i32 imm), [{
440   // Set4ImmPred predicate - True if the number is in the series of values:
441   // [ 2^0, 2^1, ... 2^15 ].
442   // For use in setbit immediate.
443   uint16_t v = (int16_t)N->getSExtValue();
444   // Constrain to 16 bits, and then check for single bit.
445   return ImmIsSingleBit(v);
446 }]>;
447
448 def Clr4ImmPred : PatLeaf<(i32 imm), [{
449   // Clr4ImmPred predicate - True if the number is in the series of
450   // bit negated values:
451   // [ 2^0, 2^1, ... 2^15 ].
452   // For use in setbit and clrbit immediate.
453   uint16_t v = ~ (int16_t)N->getSExtValue();
454   // Constrain to 16 bits, and then check for single bit.
455   return ImmIsSingleBit(v);
456 }]>;
457
458 def SetClr4ImmPred : PatLeaf<(i32 imm), [{
459   // SetClr4ImmPred predicate - True if the immediate is in the range 0..15.
460   int16_t v = (int16_t)N->getSExtValue();
461   return (v >= 0 && v <= 15);
462 }]>;
463
464 def Set3ImmPred : PatLeaf<(i32 imm), [{
465   // Set3ImmPred predicate - True if the number is in the series of values:
466   // [ 2^0, 2^1, ... 2^7 ].
467   // For use in setbit immediate.
468   uint8_t v = (int8_t)N->getSExtValue();
469   // Constrain to 8 bits, and then check for single bit.
470   return ImmIsSingleBit(v);
471 }]>;
472
473 def Clr3ImmPred : PatLeaf<(i32 imm), [{
474   // Clr3ImmPred predicate - True if the number is in the series of
475   // bit negated values:
476   // [ 2^0, 2^1, ... 2^7 ].
477   // For use in setbit and clrbit immediate.
478   uint8_t v = ~ (int8_t)N->getSExtValue();
479   // Constrain to 8 bits, and then check for single bit.
480   return ImmIsSingleBit(v);
481 }]>;
482
483 def SetClr3ImmPred : PatLeaf<(i32 imm), [{
484   // SetClr3ImmPred predicate - True if the immediate is in the range  0..7.
485   int8_t v = (int8_t)N->getSExtValue();
486   return (v >= 0 && v <= 7);
487 }]>;
488
489
490 // Extendable immediate operands.
491
492 let PrintMethod = "printExtOperand" in {
493   def s16Ext : Operand<i32>;
494   def s12Ext : Operand<i32>;
495   def s10Ext : Operand<i32>;
496   def s9Ext : Operand<i32>;
497   def s8Ext : Operand<i32>;
498   def s6Ext : Operand<i32>;
499   def s11_0Ext : Operand<i32>;
500   def s11_1Ext : Operand<i32>;
501   def s11_2Ext : Operand<i32>;
502   def s11_3Ext : Operand<i32>;
503   def u6Ext : Operand<i32>;
504   def u7Ext : Operand<i32>;
505   def u8Ext : Operand<i32>;
506   def u9Ext : Operand<i32>;
507   def u10Ext : Operand<i32>;
508   def u6_0Ext : Operand<i32>;
509   def u6_1Ext : Operand<i32>;
510   def u6_2Ext : Operand<i32>;
511   def u6_3Ext : Operand<i32>;
512 }
513
514 let PrintMethod = "printImmOperand" in
515 def u0AlwaysExt : Operand<i32>;
516
517 // Predicates for constant extendable operands
518 def s16ExtPred  : PatLeaf<(i32 imm), [{
519   int64_t v = (int64_t)N->getSExtValue();
520   if (!Subtarget->hasV4TOps())
521     // Return true if the immediate can fit in a 16-bit sign extended field.
522     return isInt<16>(v);
523   else {
524     if (isInt<16>(v))
525       return true;
526
527     // Return true if extending this immediate is profitable and the value
528     // can fit in a 32-bit signed field.
529     return isConstExtProfitable(Node) && isInt<32>(v);
530   }
531 }]>;
532
533 def s10ExtPred  : PatLeaf<(i32 imm), [{
534   int64_t v = (int64_t)N->getSExtValue();
535   if (!Subtarget->hasV4TOps())
536     // Return true if the immediate can fit in a 10-bit sign extended field.
537     return isInt<10>(v);
538   else {
539     if (isInt<10>(v))
540       return true;
541
542     // Return true if extending this immediate is profitable and the value
543     // can fit in a 32-bit signed field.
544     return isConstExtProfitable(Node) && isInt<32>(v);
545   }
546 }]>;
547
548 def s9ExtPred  : PatLeaf<(i32 imm), [{
549   int64_t v = (int64_t)N->getSExtValue();
550   if (!Subtarget->hasV4TOps())
551     // Return true if the immediate can fit in a 9-bit sign extended field.
552     return isInt<9>(v);
553   else {
554     if (isInt<9>(v))
555       return true;
556
557     // Return true if extending this immediate is profitable and the value
558     // can fit in a 32-bit unsigned field.
559     return isConstExtProfitable(Node) && isInt<32>(v);
560   }
561 }]>;
562
563 def s8ExtPred  : PatLeaf<(i32 imm), [{
564   int64_t v = (int64_t)N->getSExtValue();
565   if (!Subtarget->hasV4TOps())
566     // Return true if the immediate can fit in a 8-bit sign extended field.
567     return isInt<8>(v);
568   else {
569     if (isInt<8>(v))
570       return true;
571
572     // Return true if extending this immediate is profitable and the value
573     // can fit in a 32-bit signed field.
574     return isConstExtProfitable(Node) && isInt<32>(v);
575   }
576 }]>;
577
578 def s8_16ExtPred  : PatLeaf<(i32 imm), [{
579   int64_t v = (int64_t)N->getSExtValue();
580   if (!Subtarget->hasV4TOps())
581     // Return true if the immediate fits in a 8-bit sign extended field.
582     return isInt<8>(v);
583   else {
584     if (isInt<8>(v))
585       return true;
586
587     // Return true if extending this immediate is profitable and the value
588     // can't fit in a 16-bit signed field. This is required to avoid
589     // unnecessary constant extenders.
590     return isConstExtProfitable(Node) && !isInt<16>(v);
591   }
592 }]>;
593
594 def s6ExtPred  : PatLeaf<(i32 imm), [{
595   int64_t v = (int64_t)N->getSExtValue();
596   if (!Subtarget->hasV4TOps())
597     // Return true if the immediate can fit in a 6-bit sign extended field.
598     return isInt<6>(v);
599   else {
600     if (isInt<6>(v))
601       return true;
602
603     // Return true if extending this immediate is profitable and the value
604     // can fit in a 32-bit unsigned field.
605     return isConstExtProfitable(Node) && isInt<32>(v);
606   }
607 }]>;
608
609 def s6_16ExtPred  : PatLeaf<(i32 imm), [{
610   int64_t v = (int64_t)N->getSExtValue();
611   if (!Subtarget->hasV4TOps())
612     // Return true if the immediate fits in a 6-bit sign extended field.
613     return isInt<6>(v);
614   else {
615     if (isInt<6>(v))
616       return true;
617
618     // Return true if extending this immediate is profitable and the value
619     // can't fit in a 16-bit signed field. This is required to avoid
620     // unnecessary constant extenders.
621     return isConstExtProfitable(Node) && !isInt<16>(v);
622   }
623 }]>;
624
625 def s6_10ExtPred  : PatLeaf<(i32 imm), [{
626   int64_t v = (int64_t)N->getSExtValue();
627   if (!Subtarget->hasV4TOps())
628     // Return true if the immediate can fit in a 6-bit sign extended field.
629     return isInt<6>(v);
630   else {
631     if (isInt<6>(v))
632       return true;
633
634     // Return true if extending this immediate is profitable and the value
635     // can't fit in a 10-bit signed field. This is required to avoid
636     // unnecessary constant extenders.
637     return isConstExtProfitable(Node) && !isInt<10>(v);
638   }
639 }]>;
640
641 def s11_0ExtPred  : PatLeaf<(i32 imm), [{
642   int64_t v = (int64_t)N->getSExtValue();
643   if (!Subtarget->hasV4TOps())
644     // Return true if the immediate can fit in a 11-bit sign extended field.
645     return isShiftedInt<11,0>(v);
646   else {
647     if (isInt<11>(v))
648       return true;
649
650     // Return true if extending this immediate is profitable and the value
651     // can fit in a 32-bit signed field.
652     return isConstExtProfitable(Node) && isInt<32>(v);
653   }
654 }]>;
655
656 def s11_1ExtPred  : PatLeaf<(i32 imm), [{
657   int64_t v = (int64_t)N->getSExtValue();
658   if (!Subtarget->hasV4TOps())
659     // Return true if the immediate can fit in a 12-bit sign extended field and
660     // is 2 byte aligned.
661     return isShiftedInt<11,1>(v);
662   else {
663     if (isInt<12>(v))
664       return isShiftedInt<11,1>(v);
665
666     // Return true if extending this immediate is profitable and the low 1 bit
667     // is zero (2-byte aligned).
668     return isConstExtProfitable(Node) && isInt<32>(v) && ((v % 2) == 0);
669   }
670 }]>;
671
672 def s11_2ExtPred  : PatLeaf<(i32 imm), [{
673   int64_t v = (int64_t)N->getSExtValue();
674   if (!Subtarget->hasV4TOps())
675     // Return true if the immediate can fit in a 13-bit sign extended field and
676     // is 4-byte aligned.
677     return isShiftedInt<11,2>(v);
678   else {
679     if (isInt<13>(v))
680       return isShiftedInt<11,2>(v);
681
682     // Return true if extending this immediate is profitable and the low 2-bits
683     // are zero (4-byte aligned).
684     return isConstExtProfitable(Node)  && isInt<32>(v) && ((v % 4) == 0);
685   }
686 }]>;
687
688 def s11_3ExtPred  : PatLeaf<(i32 imm), [{
689   int64_t v = (int64_t)N->getSExtValue();
690   if (!Subtarget->hasV4TOps())
691     // Return true if the immediate can fit in a 14-bit sign extended field and
692     // is 8-byte aligned.
693     return isShiftedInt<11,3>(v);
694   else {
695     if (isInt<14>(v))
696      return isShiftedInt<11,3>(v);
697
698     // Return true if extending this immediate is profitable and the low 3-bits
699     // are zero (8-byte aligned).
700     return isConstExtProfitable(Node)  && isInt<32>(v) && ((v % 8) == 0);
701   }
702 }]>;
703
704 def u0AlwaysExtPred : PatLeaf<(i32 imm), [{
705   // Predicate for an unsigned 32-bit value that always needs to be extended.
706   if (Subtarget->hasV4TOps()) {
707     if (isConstExtProfitable(Node)) {
708       int64_t v = (int64_t)N->getSExtValue();
709       return isUInt<32>(v);
710     }
711   }
712   return false;
713 }]>;
714
715 def u6ExtPred  : PatLeaf<(i32 imm), [{
716   int64_t v = (int64_t)N->getSExtValue();
717   if (!Subtarget->hasV4TOps())
718     // Return true if the immediate can fit in a 6-bit unsigned field.
719     return isUInt<6>(v);
720   else {
721     if (isUInt<6>(v))
722       return true;
723
724     // Return true if extending this immediate is profitable and the value
725     // can fit in a 32-bit unsigned field.
726     return isConstExtProfitable(Node) && isUInt<32>(v);
727   }
728 }]>;
729
730 def u7ExtPred  : PatLeaf<(i32 imm), [{
731   int64_t v = (int64_t)N->getSExtValue();
732   if (!Subtarget->hasV4TOps())
733     // Return true if the immediate can fit in a 7-bit unsigned field.
734     return isUInt<7>(v);
735   else {
736     if (isUInt<7>(v))
737       return true;
738
739     // Return true if extending this immediate is profitable and the value
740     // can fit in a 32-bit unsigned field.
741     return isConstExtProfitable(Node) && isUInt<32>(v);
742   }
743 }]>;
744
745 def u8ExtPred  : PatLeaf<(i32 imm), [{
746   int64_t v = (int64_t)N->getSExtValue();
747   if (!Subtarget->hasV4TOps())
748     // Return true if the immediate can fit in a 8-bit unsigned field.
749     return isUInt<8>(v);
750   else {
751     if (isUInt<8>(v))
752       return true;
753
754     // Return true if extending this immediate is profitable and the value
755     // can fit in a 32-bit unsigned field.
756     return isConstExtProfitable(Node) && isUInt<32>(v);
757   }
758 }]>;
759
760 def u9ExtPred  : PatLeaf<(i32 imm), [{
761   int64_t v = (int64_t)N->getSExtValue();
762   if (!Subtarget->hasV4TOps())
763     // Return true if the immediate can fit in a 9-bit unsigned field.
764     return isUInt<9>(v);
765   else {
766     if (isUInt<9>(v))
767       return true;
768
769     // Return true if extending this immediate is profitable and the value
770     // can fit in a 32-bit unsigned field.
771     return isConstExtProfitable(Node) && isUInt<32>(v);
772   }
773 }]>;
774
775 def u6_1ExtPred  : PatLeaf<(i32 imm), [{
776   int64_t v = (int64_t)N->getSExtValue();
777   if (!Subtarget->hasV4TOps())
778     // Return true if the immediate can fit in a 7-bit unsigned field and
779     // is 2-byte aligned.
780     return isShiftedUInt<6,1>(v);
781   else {
782     if (isUInt<7>(v))
783       return isShiftedUInt<6,1>(v);
784
785     // Return true if extending this immediate is profitable and the value
786     // can fit in a 32-bit unsigned field.
787     return isConstExtProfitable(Node) && isUInt<32>(v) && ((v % 2) == 0);
788   }
789 }]>;
790
791 def u6_2ExtPred  : PatLeaf<(i32 imm), [{
792   int64_t v = (int64_t)N->getSExtValue();
793   if (!Subtarget->hasV4TOps())
794     // Return true if the immediate can fit in a 8-bit unsigned field and
795     // is 4-byte aligned.
796     return isShiftedUInt<6,2>(v);
797   else {
798     if (isUInt<8>(v))
799       return isShiftedUInt<6,2>(v);
800
801     // Return true if extending this immediate is profitable and the value
802     // can fit in a 32-bit unsigned field.
803     return isConstExtProfitable(Node) && isUInt<32>(v) && ((v % 4) == 0);
804   }
805 }]>;
806
807 def u6_3ExtPred  : PatLeaf<(i32 imm), [{
808   int64_t v = (int64_t)N->getSExtValue();
809   if (!Subtarget->hasV4TOps())
810     // Return true if the immediate can fit in a 9-bit unsigned field and
811     // is 8-byte aligned.
812     return isShiftedUInt<6,3>(v);
813   else {
814     if (isUInt<9>(v))
815       return isShiftedUInt<6,3>(v);
816
817     // Return true if extending this immediate is profitable and the value
818     // can fit in a 32-bit unsigned field.
819     return isConstExtProfitable(Node) && isUInt<32>(v) && ((v % 8) == 0);
820   }
821 }]>;
822
823
824 // This complex pattern exists only to create a machine instruction operand
825 // of type "frame index". There doesn't seem to be a way to do that directly
826 // in the patterns.
827 def AddrFI : ComplexPattern<i32, 1, "SelectAddrFI", [frameindex], []>;
828
829 // These complex patterns are not strictly necessary, since global address
830 // folding will happen during DAG combining. For distinguishing between GA
831 // and GP, pat frags with HexagonCONST32 and HexagonCONST32_GP can be used.
832 def AddrGA : ComplexPattern<i32, 1, "SelectAddrGA", [], []>;
833 def AddrGP : ComplexPattern<i32, 1, "SelectAddrGP", [], []>;
834
835 // Addressing modes.
836
837 def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
838 def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [frameindex], []>;
839 def ADDRriS11_0 : ComplexPattern<i32, 2, "SelectADDRriS11_0", [frameindex], []>;
840 def ADDRriS11_1 : ComplexPattern<i32, 2, "SelectADDRriS11_1", [frameindex], []>;
841 def ADDRriS11_2 : ComplexPattern<i32, 2, "SelectADDRriS11_2", [frameindex], []>;
842 def ADDRriS11_3 : ComplexPattern<i32, 2, "SelectADDRriS11_3", [frameindex], []>;
843 def ADDRriU6_0 : ComplexPattern<i32, 2, "SelectADDRriU6_0", [frameindex], []>;
844 def ADDRriU6_1 : ComplexPattern<i32, 2, "SelectADDRriU6_1", [frameindex], []>;
845 def ADDRriU6_2 : ComplexPattern<i32, 2, "SelectADDRriU6_2", [frameindex], []>;
846
847 // Address operands.
848
849 def MEMrr : Operand<i32> {
850   let PrintMethod = "printMEMrrOperand";
851   let MIOperandInfo = (ops IntRegs, IntRegs);
852 }
853
854 def MEMri : Operand<i32> {
855   let PrintMethod = "printMEMriOperand";
856   let MIOperandInfo = (ops IntRegs, IntRegs);
857 }
858
859 def MEMri_s11_2 : Operand<i32>,
860   ComplexPattern<i32, 2, "SelectMEMriS11_2", []> {
861   let PrintMethod = "printMEMriOperand";
862   let MIOperandInfo = (ops IntRegs, s11Imm);
863 }
864
865 def FrameIndex : Operand<i32> {
866   let PrintMethod = "printFrameIndexOperand";
867   let MIOperandInfo = (ops IntRegs, s11Imm);
868 }
869
870 let PrintMethod = "printGlobalOperand" in {
871   def globaladdress : Operand<i32>;
872   def globaladdressExt : Operand<i32>;
873 }
874
875 let PrintMethod = "printJumpTable" in
876 def jumptablebase : Operand<i32>;
877
878 def brtarget : Operand<OtherVT>;
879 def brtargetExt : Operand<OtherVT>;
880 def calltarget : Operand<i32>;
881
882 def bblabel : Operand<i32>;
883 def bbl   : SDNode<"ISD::BasicBlock", SDTPtrLeaf   , [], "BasicBlockSDNode">;
884
885 def symbolHi32 : Operand<i32> {
886   let PrintMethod = "printSymbolHi";
887 }
888 def symbolLo32 : Operand<i32> {
889   let PrintMethod = "printSymbolLo";
890 }
891
892 // Return true if for a 32 to 64-bit sign-extended load.
893 def is_sext_i32 : PatLeaf<(i64 DoubleRegs:$src1), [{
894   LoadSDNode *LD = dyn_cast<LoadSDNode>(N);
895   if (!LD)
896     return false;
897   return LD->getExtensionType() == ISD::SEXTLOAD &&
898          LD->getMemoryVT().getScalarType() == MVT::i32;
899 }]>;