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