blob: b4b351c7f96c9029178962d35f942e4948ff9ed3 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- 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
15class AMDGPUInst <dag outs, dag ins, string asm, list<dag> pattern> : Instruction {
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000016 field bit isRegisterLoad = 0;
17 field bit isRegisterStore = 0;
Tom Stellard75aadc22012-12-11 21:25:42 +000018
19 let Namespace = "AMDGPU";
20 let OutOperandList = outs;
21 let InOperandList = ins;
22 let AsmString = asm;
23 let Pattern = pattern;
24 let Itinerary = NullALU;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000025
26 let TSFlags{63} = isRegisterLoad;
27 let TSFlags{62} = isRegisterStore;
Tom Stellard75aadc22012-12-11 21:25:42 +000028}
29
30class 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
Matt Arsenaultf171cf22014-07-14 23:40:49 +000037def FP32Denormals : Predicate<"Subtarget.hasFP32Denormals()">;
38def FP64Denormals : Predicate<"Subtarget.hasFP64Denormals()">;
Matt Arsenault1d077742014-07-15 20:18:24 +000039def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">;
Matt Arsenaultf171cf22014-07-14 23:40:49 +000040
Tom Stellard75aadc22012-12-11 21:25:42 +000041def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
Tom Stellard81d871d2013-11-13 23:36:50 +000042def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>;
Tom Stellard75aadc22012-12-11 21:25:42 +000043
Matt Arsenault4d7d3832014-04-15 22:32:49 +000044def u32imm : Operand<i32> {
45 let PrintMethod = "printU32ImmOperand";
46}
47
48def u16imm : Operand<i16> {
49 let PrintMethod = "printU16ImmOperand";
50}
51
52def u8imm : Operand<i8> {
53 let PrintMethod = "printU8ImmOperand";
54}
55
Tom Stellardbc5b5372014-06-13 16:38:59 +000056//===--------------------------------------------------------------------===//
57// Custom Operands
58//===--------------------------------------------------------------------===//
59def brtarget : Operand<OtherVT>;
60
Tom Stellardc0845332013-11-22 23:07:58 +000061//===----------------------------------------------------------------------===//
62// PatLeafs for floating-point comparisons
63//===----------------------------------------------------------------------===//
Tom Stellard75aadc22012-12-11 21:25:42 +000064
Tom Stellard0351ea22013-09-28 02:50:50 +000065def COND_OEQ : PatLeaf <
66 (cond),
67 [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
68>;
69
Tom Stellard0351ea22013-09-28 02:50:50 +000070def COND_OGT : PatLeaf <
71 (cond),
72 [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
73>;
74
Tom Stellard0351ea22013-09-28 02:50:50 +000075def COND_OGE : PatLeaf <
76 (cond),
77 [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
78>;
79
Tom Stellardc0845332013-11-22 23:07:58 +000080def COND_OLT : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +000081 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +000082 [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
Tom Stellard75aadc22012-12-11 21:25:42 +000083>;
84
Tom Stellardc0845332013-11-22 23:07:58 +000085def COND_OLE : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +000086 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +000087 [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
88>;
89
90def COND_UNE : PatLeaf <
91 (cond),
92 [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
93>;
94
95def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
96def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
97
98//===----------------------------------------------------------------------===//
99// PatLeafs for unsigned comparisons
100//===----------------------------------------------------------------------===//
101
102def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
103def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
104def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
105def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
106
107//===----------------------------------------------------------------------===//
108// PatLeafs for signed comparisons
109//===----------------------------------------------------------------------===//
110
111def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
112def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
113def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
114def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
115
116//===----------------------------------------------------------------------===//
117// PatLeafs for integer equality
118//===----------------------------------------------------------------------===//
119
120def COND_EQ : PatLeaf <
121 (cond),
122 [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
123>;
124
125def COND_NE : PatLeaf <
126 (cond),
127 [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
Tom Stellard75aadc22012-12-11 21:25:42 +0000128>;
129
Christian Konigb19849a2013-02-21 15:17:04 +0000130def COND_NULL : PatLeaf <
131 (cond),
132 [{return false;}]
133>;
134
Tom Stellard75aadc22012-12-11 21:25:42 +0000135//===----------------------------------------------------------------------===//
136// Load/Store Pattern Fragments
137//===----------------------------------------------------------------------===//
138
Tom Stellardbc5b5372014-06-13 16:38:59 +0000139def global_store : PatFrag<(ops node:$val, node:$ptr),
140 (store node:$val, node:$ptr), [{
141 return isGlobalStore(dyn_cast<StoreSDNode>(N));
142}]>;
143
144// Global address space loads
145def global_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
146 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
147}]>;
148
149// Constant address space loads
150def constant_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
151 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
152}]>;
153
Tom Stellard31209cc2013-07-15 19:00:09 +0000154def az_extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
155 LoadSDNode *L = cast<LoadSDNode>(N);
156 return L->getExtensionType() == ISD::ZEXTLOAD ||
157 L->getExtensionType() == ISD::EXTLOAD;
158}]>;
159
Tom Stellard33dd04b2013-07-23 01:47:52 +0000160def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
161 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
162}]>;
163
Tom Stellardc6f4a292013-08-26 15:05:59 +0000164def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
165 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
166}]>;
167
Tom Stellard9f950332013-07-23 01:48:35 +0000168def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
Tom Stellard75aadc22012-12-11 21:25:42 +0000169 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
170}]>;
171
Tom Stellard33dd04b2013-07-23 01:47:52 +0000172def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
Tom Stellard9f950332013-07-23 01:48:35 +0000173 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
174}]>;
175
176def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
177 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
178}]>;
179
Tom Stellardc6f4a292013-08-26 15:05:59 +0000180def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
181 return isLocalLoad(dyn_cast<LoadSDNode>(N));
182}]>;
183
184def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
185 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellard33dd04b2013-07-23 01:47:52 +0000186}]>;
187
188def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
189 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
190}]>;
191
192def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
193 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
194}]>;
195
Tom Stellard9f950332013-07-23 01:48:35 +0000196def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
Tom Stellard07a10a32013-06-03 17:39:43 +0000197 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
198}]>;
199
Tom Stellard9f950332013-07-23 01:48:35 +0000200def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
201 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
202}]>;
203
204def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
205 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
206}]>;
207
Tom Stellardc6f4a292013-08-26 15:05:59 +0000208def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
209 return isLocalLoad(dyn_cast<LoadSDNode>(N));
210}]>;
211
212def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
213 return isLocalLoad(dyn_cast<LoadSDNode>(N));
214}]>;
215
Tom Stellard31209cc2013-07-15 19:00:09 +0000216def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
217 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
218}]>;
219
220def az_extloadi32_global : PatFrag<(ops node:$ptr),
221 (az_extloadi32 node:$ptr), [{
222 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
223}]>;
224
225def az_extloadi32_constant : PatFrag<(ops node:$ptr),
226 (az_extloadi32 node:$ptr), [{
227 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
228}]>;
229
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000230def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
231 (truncstorei8 node:$val, node:$ptr), [{
232 return isGlobalStore(dyn_cast<StoreSDNode>(N));
233}]>;
234
235def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
236 (truncstorei16 node:$val, node:$ptr), [{
237 return isGlobalStore(dyn_cast<StoreSDNode>(N));
238}]>;
239
Tom Stellardc026e8b2013-06-28 15:47:08 +0000240def local_store : PatFrag<(ops node:$val, node:$ptr),
241 (store node:$val, node:$ptr), [{
Tom Stellardf3d166a2013-08-26 15:05:49 +0000242 return isLocalStore(dyn_cast<StoreSDNode>(N));
243}]>;
244
245def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
246 (truncstorei8 node:$val, node:$ptr), [{
247 return isLocalStore(dyn_cast<StoreSDNode>(N));
248}]>;
249
250def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
251 (truncstorei16 node:$val, node:$ptr), [{
252 return isLocalStore(dyn_cast<StoreSDNode>(N));
253}]>;
254
255def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
256 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellardc026e8b2013-06-28 15:47:08 +0000257}]>;
258
Matt Arsenault72574102014-06-11 18:08:34 +0000259
260class local_binary_atomic_op<SDNode atomic_op> :
261 PatFrag<(ops node:$ptr, node:$value),
262 (atomic_op node:$ptr, node:$value), [{
263 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
Tom Stellard13c68ef2013-09-05 18:38:09 +0000264}]>;
265
Matt Arsenault72574102014-06-11 18:08:34 +0000266
267def atomic_swap_local : local_binary_atomic_op<atomic_swap>;
268def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>;
269def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>;
270def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>;
271def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>;
272def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>;
273def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>;
274def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>;
275def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>;
276def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>;
277def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>;
Aaron Watry372cecf2013-09-06 20:17:42 +0000278
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000279def mskor_global : PatFrag<(ops node:$val, node:$ptr),
280 (AMDGPUstore_mskor node:$val, node:$ptr), [{
281 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
282}]>;
283
Matt Arsenaultc793e1d2014-06-11 18:08:48 +0000284def atomic_cmp_swap_32_local :
285 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
286 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
287 AtomicSDNode *AN = cast<AtomicSDNode>(N);
288 return AN->getMemoryVT() == MVT::i32 &&
289 AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
290}]>;
291
Matt Arsenaultcaa0ec22014-06-11 18:08:54 +0000292def atomic_cmp_swap_64_local :
293 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
294 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
295 AtomicSDNode *AN = cast<AtomicSDNode>(N);
296 return AN->getMemoryVT() == MVT::i64 &&
297 AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
298}]>;
299
Matt Arsenaultc793e1d2014-06-11 18:08:48 +0000300
Tom Stellard75aadc22012-12-11 21:25:42 +0000301class Constants {
302int TWO_PI = 0x40c90fdb;
303int PI = 0x40490fdb;
304int TWO_PI_INV = 0x3e22f983;
NAKAMURA Takumi4bb85f92013-10-28 04:07:23 +0000305int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
Matt Arsenaultaeca2fa2014-05-31 06:47:42 +0000306int FP32_NEG_ONE = 0xbf800000;
307int FP32_ONE = 0x3f800000;
Tom Stellard75aadc22012-12-11 21:25:42 +0000308}
309def CONST : Constants;
310
311def FP_ZERO : PatLeaf <
312 (fpimm),
313 [{return N->getValueAPF().isZero();}]
314>;
315
316def FP_ONE : PatLeaf <
317 (fpimm),
318 [{return N->isExactlyValue(1.0);}]
319>;
320
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000321let isCodeGenOnly = 1, isPseudo = 1 in {
322
323let usesCustomInserter = 1 in {
Tom Stellard75aadc22012-12-11 21:25:42 +0000324
325class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
326 (outs rc:$dst),
327 (ins rc:$src0),
328 "CLAMP $dst, $src0",
Matt Arsenault5d47d4a2014-06-12 21:15:44 +0000329 [(set f32:$dst, (AMDGPUclamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000330>;
331
332class FABS <RegisterClass rc> : AMDGPUShaderInst <
333 (outs rc:$dst),
334 (ins rc:$src0),
335 "FABS $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000336 [(set f32:$dst, (fabs f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000337>;
338
339class FNEG <RegisterClass rc> : AMDGPUShaderInst <
340 (outs rc:$dst),
341 (ins rc:$src0),
342 "FNEG $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000343 [(set f32:$dst, (fneg f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000344>;
345
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000346} // usesCustomInserter = 1
347
348multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
349 ComplexPattern addrPat> {
Tom Stellard81d871d2013-11-13 23:36:50 +0000350let UseNamedOperandTable = 1 in {
351
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000352 def RegisterLoad : AMDGPUShaderInst <
353 (outs dstClass:$dst),
354 (ins addrClass:$addr, i32imm:$chan),
355 "RegisterLoad $dst, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000356 [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000357 > {
358 let isRegisterLoad = 1;
359 }
360
361 def RegisterStore : AMDGPUShaderInst <
362 (outs),
363 (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
364 "RegisterStore $val, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000365 [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000366 > {
367 let isRegisterStore = 1;
368 }
369}
Tom Stellard81d871d2013-11-13 23:36:50 +0000370}
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000371
372} // End isCodeGenOnly = 1, isPseudo = 1
Tom Stellard75aadc22012-12-11 21:25:42 +0000373
374/* Generic helper patterns for intrinsics */
375/* -------------------------------------- */
376
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000377class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
378 : Pat <
379 (fpow f32:$src0, f32:$src1),
380 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
Tom Stellard75aadc22012-12-11 21:25:42 +0000381>;
382
383/* Other helper patterns */
384/* --------------------- */
385
386/* Extract element pattern */
Matt Arsenault530dde42014-02-26 23:00:58 +0000387class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000388 SubRegIndex sub_reg>
389 : Pat<
390 (sub_type (vector_extract vec_type:$src, sub_idx)),
391 (EXTRACT_SUBREG $src, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000392>;
393
394/* Insert element pattern */
395class Insert_Element <ValueType elem_type, ValueType vec_type,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000396 int sub_idx, SubRegIndex sub_reg>
397 : Pat <
398 (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
399 (INSERT_SUBREG $vec, $elem, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000400>;
401
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000402// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
403// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000404// bitconvert pattern
405class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
406 (dt (bitconvert (st rc:$src0))),
407 (dt rc:$src0)
408>;
409
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000410// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
411// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000412class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
413 (vt (AMDGPUdwordaddr (vt rc:$addr))),
414 (vt rc:$addr)
415>;
416
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000417// BFI_INT patterns
418
Matt Arsenault6e439652014-06-10 19:00:20 +0000419multiclass BFIPatterns <Instruction BFI_INT, Instruction LoadImm32> {
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000420
421 // Definition from ISA doc:
422 // (y & x) | (z & ~x)
423 def : Pat <
424 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
425 (BFI_INT $x, $y, $z)
426 >;
427
428 // SHA-256 Ch function
429 // z ^ (x & (y ^ z))
430 def : Pat <
431 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
432 (BFI_INT $x, $y, $z)
433 >;
434
Matt Arsenault6e439652014-06-10 19:00:20 +0000435 def : Pat <
436 (fcopysign f32:$src0, f32:$src1),
437 (BFI_INT (LoadImm32 0x7fffffff), $src0, $src1)
438 >;
439
440 def : Pat <
441 (f64 (fcopysign f64:$src0, f64:$src1)),
442 (INSERT_SUBREG (INSERT_SUBREG (f64 (IMPLICIT_DEF)),
443 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0),
444 (BFI_INT (LoadImm32 0x7fffffff),
445 (i32 (EXTRACT_SUBREG $src0, sub1)),
446 (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
447 >;
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000448}
449
Tom Stellardeac65dd2013-05-03 17:21:20 +0000450// SHA-256 Ma patterns
451
452// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
453class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
454 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
455 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
456>;
457
Tom Stellard2b971eb2013-05-10 02:09:45 +0000458// Bitfield extract patterns
459
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000460/*
461
462XXX: The BFE pattern is not working correctly because the XForm is not being
463applied.
464
Tom Stellard2b971eb2013-05-10 02:09:45 +0000465def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
466def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
467 SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
468
469class BFEPattern <Instruction BFE> : Pat <
470 (and (srl i32:$x, legalshift32:$y), bfemask:$z),
471 (BFE $x, $y, $z)
472>;
473
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000474*/
475
Tom Stellard5643c4a2013-05-20 15:02:19 +0000476// rotr pattern
477class ROTRPattern <Instruction BIT_ALIGN> : Pat <
478 (rotr i32:$src0, i32:$src1),
479 (BIT_ALIGN $src0, $src0, $src1)
480>;
481
Tom Stellard41fc7852013-07-23 01:48:42 +0000482// 24-bit arithmetic patterns
483def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
484
485/*
486class UMUL24Pattern <Instruction UMUL24> : Pat <
487 (mul U24:$x, U24:$y),
488 (UMUL24 $x, $y)
489>;
490*/
491
Matt Arsenaulteb260202014-05-22 18:00:15 +0000492class IMad24Pat<Instruction Inst> : Pat <
493 (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
494 (Inst $src0, $src1, $src2)
495>;
496
497class UMad24Pat<Instruction Inst> : Pat <
498 (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
499 (Inst $src0, $src1, $src2)
500>;
501
Matt Arsenault493c5f12014-05-22 18:00:24 +0000502multiclass Expand24IBitOps<Instruction MulInst, Instruction AddInst> {
503 def _expand_imad24 : Pat <
504 (AMDGPUmad_i24 i32:$src0, i32:$src1, i32:$src2),
505 (AddInst (MulInst $src0, $src1), $src2)
506 >;
Matt Arsenaultf15a0562014-05-22 18:00:20 +0000507
Matt Arsenault493c5f12014-05-22 18:00:24 +0000508 def _expand_imul24 : Pat <
509 (AMDGPUmul_i24 i32:$src0, i32:$src1),
510 (MulInst $src0, $src1)
511 >;
512}
Matt Arsenaultf15a0562014-05-22 18:00:20 +0000513
Matt Arsenault493c5f12014-05-22 18:00:24 +0000514multiclass Expand24UBitOps<Instruction MulInst, Instruction AddInst> {
515 def _expand_umad24 : Pat <
516 (AMDGPUmad_u24 i32:$src0, i32:$src1, i32:$src2),
517 (AddInst (MulInst $src0, $src1), $src2)
518 >;
519
520 def _expand_umul24 : Pat <
521 (AMDGPUmul_u24 i32:$src0, i32:$src1),
522 (MulInst $src0, $src1)
523 >;
524}
Matt Arsenaulteb260202014-05-22 18:00:15 +0000525
Matt Arsenaulta0050b02014-06-19 01:19:19 +0000526class RcpPat<Instruction RcpInst, ValueType vt> : Pat <
527 (fdiv FP_ONE, vt:$src),
528 (RcpInst $src)
529>;
530
Matt Arsenault257d48d2014-06-24 22:13:39 +0000531multiclass RsqPat<Instruction RsqInst, ValueType vt> {
532 def : Pat <
533 (fdiv FP_ONE, (fsqrt vt:$src)),
534 (RsqInst $src)
535 >;
536
537 def : Pat <
538 (AMDGPUrcp (fsqrt vt:$src)),
539 (RsqInst $src)
540 >;
541}
Matt Arsenaulta0050b02014-06-19 01:19:19 +0000542
Tom Stellard75aadc22012-12-11 21:25:42 +0000543include "R600Instructions.td"
Tom Stellard2c1c9de2014-03-24 16:07:25 +0000544include "R700Instructions.td"
545include "EvergreenInstructions.td"
546include "CaymanInstructions.td"
Tom Stellard75aadc22012-12-11 21:25:42 +0000547
548include "SIInstrInfo.td"
549