R600/SI: Use REG_SEQUENCE instead of INSERT_SUBREGs
[oota-llvm.git] / lib / Target / R600 / AMDGPUInstructions.td
1 //===-- AMDGPUInstructions.td - Common instruction defs ---*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains instruction defs that are common to all hw codegen
11 // targets.
12 //
13 //===----------------------------------------------------------------------===//
14
15 class AMDGPUInst <dag outs, dag ins, string asm, list<dag> pattern> : Instruction {
16   field bit isRegisterLoad = 0;
17   field bit isRegisterStore = 0;
18
19   let Namespace = "AMDGPU";
20   let OutOperandList = outs;
21   let InOperandList = ins;
22   let AsmString = asm;
23   let Pattern = pattern;
24   let Itinerary = NullALU;
25
26   let TSFlags{63} = isRegisterLoad;
27   let TSFlags{62} = isRegisterStore;
28 }
29
30 class AMDGPUShaderInst <dag outs, dag ins, string asm, list<dag> pattern>
31     : AMDGPUInst<outs, ins, asm, pattern> {
32
33   field bits<32> Inst = 0xffffffff;
34
35 }
36
37 def FP32Denormals : Predicate<"Subtarget.hasFP32Denormals()">;
38 def FP64Denormals : Predicate<"Subtarget.hasFP64Denormals()">;
39 def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">;
40
41 def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
42 def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>;
43
44 let OperandType = "OPERAND_IMMEDIATE" in {
45
46 def u32imm : Operand<i32> {
47   let PrintMethod = "printU32ImmOperand";
48 }
49
50 def u16imm : Operand<i16> {
51   let PrintMethod = "printU16ImmOperand";
52 }
53
54 def u8imm : Operand<i8> {
55   let PrintMethod = "printU8ImmOperand";
56 }
57
58 } // End OperandType = "OPERAND_IMMEDIATE"
59
60 //===--------------------------------------------------------------------===//
61 // Custom Operands
62 //===--------------------------------------------------------------------===//
63 def brtarget   : Operand<OtherVT>;
64
65 //===----------------------------------------------------------------------===//
66 // PatLeafs for floating-point comparisons
67 //===----------------------------------------------------------------------===//
68
69 def COND_OEQ : PatLeaf <
70   (cond),
71   [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
72 >;
73
74 def COND_OGT : PatLeaf <
75   (cond),
76   [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
77 >;
78
79 def COND_OGE : PatLeaf <
80   (cond),
81   [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
82 >;
83
84 def COND_OLT : PatLeaf <
85   (cond),
86   [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
87 >;
88
89 def COND_OLE : PatLeaf <
90   (cond),
91   [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
92 >;
93
94 def COND_UNE : PatLeaf <
95   (cond),
96   [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
97 >;
98
99 def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
100 def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
101
102 //===----------------------------------------------------------------------===//
103 // PatLeafs for unsigned comparisons
104 //===----------------------------------------------------------------------===//
105
106 def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
107 def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
108 def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
109 def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
110
111 //===----------------------------------------------------------------------===//
112 // PatLeafs for signed comparisons
113 //===----------------------------------------------------------------------===//
114
115 def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
116 def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
117 def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
118 def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
119
120 //===----------------------------------------------------------------------===//
121 // PatLeafs for integer equality
122 //===----------------------------------------------------------------------===//
123
124 def COND_EQ : PatLeaf <
125   (cond),
126   [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
127 >;
128
129 def COND_NE : PatLeaf <
130   (cond),
131   [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
132 >;
133
134 def COND_NULL : PatLeaf <
135   (cond),
136   [{(void)N; return false;}]
137 >;
138
139 //===----------------------------------------------------------------------===//
140 // Load/Store Pattern Fragments
141 //===----------------------------------------------------------------------===//
142
143 class PrivateMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
144   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
145 }]>;
146
147 class PrivateLoad <SDPatternOperator op> : PrivateMemOp <
148   (ops node:$ptr), (op node:$ptr)
149 >;
150
151 class PrivateStore <SDPatternOperator op> : PrivateMemOp <
152   (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
153 >;
154
155 def extloadi8_private : PrivateLoad <extloadi8>;
156 def sextloadi8_private : PrivateLoad <sextloadi8>;
157 def extloadi16_private : PrivateLoad <extloadi16>;
158 def sextloadi16_private : PrivateLoad <sextloadi16>;
159 def load_private : PrivateLoad <load>;
160
161 def truncstorei8_private : PrivateStore <truncstorei8>;
162 def truncstorei16_private : PrivateStore <truncstorei16>;
163 def store_private : PrivateStore <store>;
164
165 def global_store : PatFrag<(ops node:$val, node:$ptr),
166     (store node:$val, node:$ptr), [{
167         return isGlobalStore(dyn_cast<StoreSDNode>(N));
168 }]>;
169
170 // Global address space loads
171 def global_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
172     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
173 }]>;
174
175 // Constant address space loads
176 def constant_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
177     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
178 }]>;
179
180 def az_extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
181   LoadSDNode *L = cast<LoadSDNode>(N);
182   return L->getExtensionType() == ISD::ZEXTLOAD ||
183          L->getExtensionType() == ISD::EXTLOAD;
184 }]>;
185
186 def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
187   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
188 }]>;
189
190 def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
191     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
192 }]>;
193
194 def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
195     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
196 }]>;
197
198 def az_extloadi8_flat : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
199     return isFlatLoad(dyn_cast<LoadSDNode>(N));
200 }]>;
201
202 def sextloadi8_flat : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
203     return isFlatLoad(dyn_cast<LoadSDNode>(N));
204 }]>;
205
206 def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
207     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
208 }]>;
209
210 def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
211     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
212 }]>;
213
214 def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
215     return isLocalLoad(dyn_cast<LoadSDNode>(N));
216 }]>;
217
218 def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
219     return isLocalLoad(dyn_cast<LoadSDNode>(N));
220 }]>;
221
222 def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
223   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
224 }]>;
225
226 def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
227     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
228 }]>;
229
230 def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
231     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
232 }]>;
233
234 def az_extloadi16_flat : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
235     return isFlatLoad(dyn_cast<LoadSDNode>(N));
236 }]>;
237
238 def sextloadi16_flat : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
239     return isFlatLoad(dyn_cast<LoadSDNode>(N));
240 }]>;
241
242 def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
243     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
244 }]>;
245
246 def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
247     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
248 }]>;
249
250 def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
251     return isLocalLoad(dyn_cast<LoadSDNode>(N));
252 }]>;
253
254 def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
255     return isLocalLoad(dyn_cast<LoadSDNode>(N));
256 }]>;
257
258 def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
259   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
260 }]>;
261
262 def az_extloadi32_global : PatFrag<(ops node:$ptr),
263                                    (az_extloadi32 node:$ptr), [{
264   return isGlobalLoad(dyn_cast<LoadSDNode>(N));
265 }]>;
266
267 def az_extloadi32_flat : PatFrag<(ops node:$ptr),
268                                    (az_extloadi32 node:$ptr), [{
269   return isFlatLoad(dyn_cast<LoadSDNode>(N));
270 }]>;
271
272 def az_extloadi32_constant : PatFrag<(ops node:$ptr),
273                                      (az_extloadi32 node:$ptr), [{
274   return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
275 }]>;
276
277 def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
278                                   (truncstorei8 node:$val, node:$ptr), [{
279   return isGlobalStore(dyn_cast<StoreSDNode>(N));
280 }]>;
281
282 def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
283                                   (truncstorei16 node:$val, node:$ptr), [{
284   return isGlobalStore(dyn_cast<StoreSDNode>(N));
285 }]>;
286
287 def truncstorei8_flat : PatFrag<(ops node:$val, node:$ptr),
288                                   (truncstorei8 node:$val, node:$ptr), [{
289   return isFlatStore(dyn_cast<StoreSDNode>(N));
290 }]>;
291
292 def truncstorei16_flat : PatFrag<(ops node:$val, node:$ptr),
293                                   (truncstorei16 node:$val, node:$ptr), [{
294   return isFlatStore(dyn_cast<StoreSDNode>(N));
295 }]>;
296
297 def local_store : PatFrag<(ops node:$val, node:$ptr),
298                              (store node:$val, node:$ptr), [{
299   return isLocalStore(dyn_cast<StoreSDNode>(N));
300 }]>;
301
302 def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
303                                   (truncstorei8 node:$val, node:$ptr), [{
304   return isLocalStore(dyn_cast<StoreSDNode>(N));
305 }]>;
306
307 def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
308                                   (truncstorei16 node:$val, node:$ptr), [{
309   return isLocalStore(dyn_cast<StoreSDNode>(N));
310 }]>;
311
312 def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
313     return isLocalLoad(dyn_cast<LoadSDNode>(N));
314 }]>;
315
316 class Aligned8Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{
317     return cast<MemSDNode>(N)->getAlignment() % 8 == 0;
318 }]>;
319
320 def local_load_aligned8bytes : Aligned8Bytes <
321   (ops node:$ptr), (local_load node:$ptr)
322 >;
323
324 def local_store_aligned8bytes : Aligned8Bytes <
325   (ops node:$val, node:$ptr), (local_store node:$val, node:$ptr)
326 >;
327
328 class local_binary_atomic_op<SDNode atomic_op> :
329   PatFrag<(ops node:$ptr, node:$value),
330     (atomic_op node:$ptr, node:$value), [{
331   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
332 }]>;
333
334
335 def atomic_swap_local : local_binary_atomic_op<atomic_swap>;
336 def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>;
337 def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>;
338 def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>;
339 def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>;
340 def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>;
341 def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>;
342 def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>;
343 def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>;
344 def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>;
345 def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>;
346
347 def mskor_global : PatFrag<(ops node:$val, node:$ptr),
348                             (AMDGPUstore_mskor node:$val, node:$ptr), [{
349   return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
350 }]>;
351
352
353 def atomic_cmp_swap_32_local :
354   PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
355           (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
356   AtomicSDNode *AN = cast<AtomicSDNode>(N);
357   return AN->getMemoryVT() == MVT::i32 &&
358          AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
359 }]>;
360
361 def atomic_cmp_swap_64_local :
362   PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
363           (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
364   AtomicSDNode *AN = cast<AtomicSDNode>(N);
365   return AN->getMemoryVT() == MVT::i64 &&
366          AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
367 }]>;
368
369 def flat_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
370     return isFlatLoad(dyn_cast<LoadSDNode>(N));
371 }]>;
372
373 def flat_store : PatFrag<(ops node:$val, node:$ptr),
374                          (store node:$val, node:$ptr), [{
375   return isFlatStore(dyn_cast<StoreSDNode>(N));
376 }]>;
377
378 def mskor_flat : PatFrag<(ops node:$val, node:$ptr),
379                             (AMDGPUstore_mskor node:$val, node:$ptr), [{
380   return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::FLAT_ADDRESS;
381 }]>;
382
383 class global_binary_atomic_op<SDNode atomic_op> : PatFrag<
384   (ops node:$ptr, node:$value),
385   (atomic_op node:$ptr, node:$value),
386   [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;}]
387 >;
388
389 def atomic_swap_global : global_binary_atomic_op<atomic_swap>;
390 def atomic_add_global : global_binary_atomic_op<atomic_load_add>;
391 def atomic_and_global : global_binary_atomic_op<atomic_load_and>;
392 def atomic_max_global : global_binary_atomic_op<atomic_load_max>;
393 def atomic_min_global : global_binary_atomic_op<atomic_load_min>;
394 def atomic_or_global : global_binary_atomic_op<atomic_load_or>;
395 def atomic_sub_global : global_binary_atomic_op<atomic_load_sub>;
396 def atomic_umax_global : global_binary_atomic_op<atomic_load_umax>;
397 def atomic_umin_global : global_binary_atomic_op<atomic_load_umin>;
398 def atomic_xor_global : global_binary_atomic_op<atomic_load_xor>;
399
400 //===----------------------------------------------------------------------===//
401 // Misc Pattern Fragments
402 //===----------------------------------------------------------------------===//
403
404 def fmad : PatFrag <
405   (ops node:$src0, node:$src1, node:$src2),
406   (fadd (fmul node:$src0, node:$src1), node:$src2)
407 >;
408
409 class Constants {
410 int TWO_PI = 0x40c90fdb;
411 int PI = 0x40490fdb;
412 int TWO_PI_INV = 0x3e22f983;
413 int FP_UINT_MAX_PLUS_1 = 0x4f800000;    // 1 << 32 in floating point encoding
414 int FP32_NEG_ONE = 0xbf800000;
415 int FP32_ONE = 0x3f800000;
416 }
417 def CONST : Constants;
418
419 def FP_ZERO : PatLeaf <
420   (fpimm),
421   [{return N->getValueAPF().isZero();}]
422 >;
423
424 def FP_ONE : PatLeaf <
425   (fpimm),
426   [{return N->isExactlyValue(1.0);}]
427 >;
428
429 let isCodeGenOnly = 1, isPseudo = 1 in {
430
431 let usesCustomInserter = 1  in {
432
433 class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
434   (outs rc:$dst),
435   (ins rc:$src0),
436   "CLAMP $dst, $src0",
437   [(set f32:$dst, (AMDGPUclamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
438 >;
439
440 class FABS <RegisterClass rc> : AMDGPUShaderInst <
441   (outs rc:$dst),
442   (ins rc:$src0),
443   "FABS $dst, $src0",
444   [(set f32:$dst, (fabs f32:$src0))]
445 >;
446
447 class FNEG <RegisterClass rc> : AMDGPUShaderInst <
448   (outs rc:$dst),
449   (ins rc:$src0),
450   "FNEG $dst, $src0",
451   [(set f32:$dst, (fneg f32:$src0))]
452 >;
453
454 } // usesCustomInserter = 1
455
456 multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
457                     ComplexPattern addrPat> {
458 let UseNamedOperandTable = 1 in {
459
460   def RegisterLoad : AMDGPUShaderInst <
461     (outs dstClass:$dst),
462     (ins addrClass:$addr, i32imm:$chan),
463     "RegisterLoad $dst, $addr",
464     [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
465   > {
466     let isRegisterLoad = 1;
467   }
468
469   def RegisterStore : AMDGPUShaderInst <
470     (outs),
471     (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
472     "RegisterStore $val, $addr",
473     [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
474   > {
475     let isRegisterStore = 1;
476   }
477 }
478 }
479
480 } // End isCodeGenOnly = 1, isPseudo = 1
481
482 /* Generic helper patterns for intrinsics */
483 /* -------------------------------------- */
484
485 class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
486   : Pat <
487   (fpow f32:$src0, f32:$src1),
488   (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
489 >;
490
491 /* Other helper patterns */
492 /* --------------------- */
493
494 /* Extract element pattern */
495 class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
496                        SubRegIndex sub_reg>
497   : Pat<
498   (sub_type (vector_extract vec_type:$src, sub_idx)),
499   (EXTRACT_SUBREG $src, sub_reg)
500 >;
501
502 /* Insert element pattern */
503 class Insert_Element <ValueType elem_type, ValueType vec_type,
504                       int sub_idx, SubRegIndex sub_reg>
505   : Pat <
506   (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
507   (INSERT_SUBREG $vec, $elem, sub_reg)
508 >;
509
510 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
511 // can handle COPY instructions.
512 // bitconvert pattern
513 class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
514   (dt (bitconvert (st rc:$src0))),
515   (dt rc:$src0)
516 >;
517
518 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
519 // can handle COPY instructions.
520 class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
521   (vt (AMDGPUdwordaddr (vt rc:$addr))),
522   (vt rc:$addr)
523 >;
524
525 // BFI_INT patterns
526
527 multiclass BFIPatterns <Instruction BFI_INT,
528                         Instruction LoadImm32,
529                         RegisterClass RC64> {
530   // Definition from ISA doc:
531   // (y & x) | (z & ~x)
532   def : Pat <
533     (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
534     (BFI_INT $x, $y, $z)
535   >;
536
537   // SHA-256 Ch function
538   // z ^ (x & (y ^ z))
539   def : Pat <
540     (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
541     (BFI_INT $x, $y, $z)
542   >;
543
544   def : Pat <
545     (fcopysign f32:$src0, f32:$src1),
546     (BFI_INT (LoadImm32 0x7fffffff), $src0, $src1)
547   >;
548
549   def : Pat <
550     (f64 (fcopysign f64:$src0, f64:$src1)),
551     (REG_SEQUENCE RC64,
552       (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
553       (BFI_INT (LoadImm32 0x7fffffff),
554                (i32 (EXTRACT_SUBREG $src0, sub1)),
555                (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
556   >;
557 }
558
559 // SHA-256 Ma patterns
560
561 // ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
562 class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
563   (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
564   (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
565 >;
566
567 // Bitfield extract patterns
568
569 /*
570
571 XXX: The BFE pattern is not working correctly because the XForm is not being
572 applied.
573
574 def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
575 def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
576                             SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
577
578 class BFEPattern <Instruction BFE> : Pat <
579   (and (srl i32:$x, legalshift32:$y), bfemask:$z),
580   (BFE $x, $y, $z)
581 >;
582
583 */
584
585 // rotr pattern
586 class ROTRPattern <Instruction BIT_ALIGN> : Pat <
587   (rotr i32:$src0, i32:$src1),
588   (BIT_ALIGN $src0, $src0, $src1)
589 >;
590
591 // 24-bit arithmetic patterns
592 def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
593
594 /*
595 class UMUL24Pattern <Instruction UMUL24> : Pat <
596   (mul U24:$x, U24:$y),
597   (UMUL24 $x, $y)
598 >;
599 */
600
601 class IMad24Pat<Instruction Inst> : Pat <
602   (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
603   (Inst $src0, $src1, $src2)
604 >;
605
606 class UMad24Pat<Instruction Inst> : Pat <
607   (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
608   (Inst $src0, $src1, $src2)
609 >;
610
611 multiclass Expand24IBitOps<Instruction MulInst, Instruction AddInst> {
612   def _expand_imad24 : Pat <
613     (AMDGPUmad_i24 i32:$src0, i32:$src1, i32:$src2),
614     (AddInst (MulInst $src0, $src1), $src2)
615   >;
616
617   def _expand_imul24 : Pat <
618     (AMDGPUmul_i24 i32:$src0, i32:$src1),
619     (MulInst $src0, $src1)
620   >;
621 }
622
623 multiclass Expand24UBitOps<Instruction MulInst, Instruction AddInst> {
624   def _expand_umad24 : Pat <
625     (AMDGPUmad_u24 i32:$src0, i32:$src1, i32:$src2),
626     (AddInst (MulInst $src0, $src1), $src2)
627   >;
628
629   def _expand_umul24 : Pat <
630     (AMDGPUmul_u24 i32:$src0, i32:$src1),
631     (MulInst $src0, $src1)
632   >;
633 }
634
635 class RcpPat<Instruction RcpInst, ValueType vt> : Pat <
636   (fdiv FP_ONE, vt:$src),
637   (RcpInst $src)
638 >;
639
640 multiclass RsqPat<Instruction RsqInst, ValueType vt> {
641   def : Pat <
642     (fdiv FP_ONE, (fsqrt vt:$src)),
643     (RsqInst $src)
644   >;
645
646   def : Pat <
647     (AMDGPUrcp (fsqrt vt:$src)),
648     (RsqInst $src)
649   >;
650 }
651
652 include "R600Instructions.td"
653 include "R700Instructions.td"
654 include "EvergreenInstructions.td"
655 include "CaymanInstructions.td"
656
657 include "SIInstrInfo.td"
658