blob: cd3560378e57c84b1896ab366b9708cf4984696e [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
Tom Stellardb02094e2014-07-21 15:45:01 +000044let OperandType = "OPERAND_IMMEDIATE" in {
45
Matt Arsenault4d7d3832014-04-15 22:32:49 +000046def u32imm : Operand<i32> {
47 let PrintMethod = "printU32ImmOperand";
48}
49
50def u16imm : Operand<i16> {
51 let PrintMethod = "printU16ImmOperand";
52}
53
54def u8imm : Operand<i8> {
55 let PrintMethod = "printU8ImmOperand";
56}
57
Tom Stellardb02094e2014-07-21 15:45:01 +000058} // End OperandType = "OPERAND_IMMEDIATE"
59
Tom Stellardbc5b5372014-06-13 16:38:59 +000060//===--------------------------------------------------------------------===//
61// Custom Operands
62//===--------------------------------------------------------------------===//
63def brtarget : Operand<OtherVT>;
64
Tom Stellardc0845332013-11-22 23:07:58 +000065//===----------------------------------------------------------------------===//
66// PatLeafs for floating-point comparisons
67//===----------------------------------------------------------------------===//
Tom Stellard75aadc22012-12-11 21:25:42 +000068
Tom Stellard0351ea22013-09-28 02:50:50 +000069def COND_OEQ : PatLeaf <
70 (cond),
71 [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
72>;
73
Tom Stellard0351ea22013-09-28 02:50:50 +000074def COND_OGT : PatLeaf <
75 (cond),
76 [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
77>;
78
Tom Stellard0351ea22013-09-28 02:50:50 +000079def COND_OGE : PatLeaf <
80 (cond),
81 [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
82>;
83
Tom Stellardc0845332013-11-22 23:07:58 +000084def COND_OLT : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +000085 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +000086 [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
Tom Stellard75aadc22012-12-11 21:25:42 +000087>;
88
Tom Stellardc0845332013-11-22 23:07:58 +000089def COND_OLE : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +000090 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +000091 [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
92>;
93
94def COND_UNE : PatLeaf <
95 (cond),
96 [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
97>;
98
99def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
100def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
101
102//===----------------------------------------------------------------------===//
103// PatLeafs for unsigned comparisons
104//===----------------------------------------------------------------------===//
105
106def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
107def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
108def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
109def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
110
111//===----------------------------------------------------------------------===//
112// PatLeafs for signed comparisons
113//===----------------------------------------------------------------------===//
114
115def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
116def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
117def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
118def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
119
120//===----------------------------------------------------------------------===//
121// PatLeafs for integer equality
122//===----------------------------------------------------------------------===//
123
124def COND_EQ : PatLeaf <
125 (cond),
126 [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
127>;
128
129def COND_NE : PatLeaf <
130 (cond),
131 [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
Tom Stellard75aadc22012-12-11 21:25:42 +0000132>;
133
Christian Konigb19849a2013-02-21 15:17:04 +0000134def COND_NULL : PatLeaf <
135 (cond),
136 [{return false;}]
137>;
138
Tom Stellard75aadc22012-12-11 21:25:42 +0000139//===----------------------------------------------------------------------===//
140// Load/Store Pattern Fragments
141//===----------------------------------------------------------------------===//
142
Tom Stellardb02094e2014-07-21 15:45:01 +0000143class PrivateMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
144 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
145}]>;
146
147class PrivateLoad <SDPatternOperator op> : PrivateMemOp <
148 (ops node:$ptr), (op node:$ptr)
149>;
150
151class PrivateStore <SDPatternOperator op> : PrivateMemOp <
152 (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
153>;
154
155def extloadi8_private : PrivateLoad <extloadi8>;
156def sextloadi8_private : PrivateLoad <sextloadi8>;
157def extloadi16_private : PrivateLoad <extloadi16>;
158def sextloadi16_private : PrivateLoad <sextloadi16>;
159def load_private : PrivateLoad <load>;
160
161def truncstorei8_private : PrivateStore <truncstorei8>;
162def truncstorei16_private : PrivateStore <truncstorei16>;
163def store_private : PrivateStore <store>;
164
Tom Stellardbc5b5372014-06-13 16:38:59 +0000165def 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
171def global_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
172 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
173}]>;
174
175// Constant address space loads
176def constant_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
177 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
178}]>;
179
Tom Stellard31209cc2013-07-15 19:00:09 +0000180def 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
Tom Stellard33dd04b2013-07-23 01:47:52 +0000186def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
187 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
188}]>;
189
Tom Stellardc6f4a292013-08-26 15:05:59 +0000190def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
191 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
192}]>;
193
Tom Stellard9f950332013-07-23 01:48:35 +0000194def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
Tom Stellard75aadc22012-12-11 21:25:42 +0000195 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
196}]>;
197
Tom Stellard33dd04b2013-07-23 01:47:52 +0000198def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
Tom Stellard9f950332013-07-23 01:48:35 +0000199 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
200}]>;
201
202def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
203 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
204}]>;
205
Tom Stellardc6f4a292013-08-26 15:05:59 +0000206def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
207 return isLocalLoad(dyn_cast<LoadSDNode>(N));
208}]>;
209
210def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
211 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellard33dd04b2013-07-23 01:47:52 +0000212}]>;
213
214def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
215 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
216}]>;
217
218def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
219 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
220}]>;
221
Tom Stellard9f950332013-07-23 01:48:35 +0000222def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
Tom Stellard07a10a32013-06-03 17:39:43 +0000223 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
224}]>;
225
Tom Stellard9f950332013-07-23 01:48:35 +0000226def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
227 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
228}]>;
229
230def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
231 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
232}]>;
233
Tom Stellardc6f4a292013-08-26 15:05:59 +0000234def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
235 return isLocalLoad(dyn_cast<LoadSDNode>(N));
236}]>;
237
238def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
239 return isLocalLoad(dyn_cast<LoadSDNode>(N));
240}]>;
241
Tom Stellard31209cc2013-07-15 19:00:09 +0000242def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
243 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
244}]>;
245
246def az_extloadi32_global : PatFrag<(ops node:$ptr),
247 (az_extloadi32 node:$ptr), [{
248 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
249}]>;
250
251def az_extloadi32_constant : PatFrag<(ops node:$ptr),
252 (az_extloadi32 node:$ptr), [{
253 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
254}]>;
255
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000256def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
257 (truncstorei8 node:$val, node:$ptr), [{
258 return isGlobalStore(dyn_cast<StoreSDNode>(N));
259}]>;
260
261def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
262 (truncstorei16 node:$val, node:$ptr), [{
263 return isGlobalStore(dyn_cast<StoreSDNode>(N));
264}]>;
265
Tom Stellardc026e8b2013-06-28 15:47:08 +0000266def local_store : PatFrag<(ops node:$val, node:$ptr),
267 (store node:$val, node:$ptr), [{
Tom Stellardf3d166a2013-08-26 15:05:49 +0000268 return isLocalStore(dyn_cast<StoreSDNode>(N));
269}]>;
270
271def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
272 (truncstorei8 node:$val, node:$ptr), [{
273 return isLocalStore(dyn_cast<StoreSDNode>(N));
274}]>;
275
276def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
277 (truncstorei16 node:$val, node:$ptr), [{
278 return isLocalStore(dyn_cast<StoreSDNode>(N));
279}]>;
280
281def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
282 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellardc026e8b2013-06-28 15:47:08 +0000283}]>;
284
Matt Arsenault72574102014-06-11 18:08:34 +0000285
286class local_binary_atomic_op<SDNode atomic_op> :
287 PatFrag<(ops node:$ptr, node:$value),
288 (atomic_op node:$ptr, node:$value), [{
289 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
Tom Stellard13c68ef2013-09-05 18:38:09 +0000290}]>;
291
Matt Arsenault72574102014-06-11 18:08:34 +0000292
293def atomic_swap_local : local_binary_atomic_op<atomic_swap>;
294def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>;
295def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>;
296def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>;
297def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>;
298def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>;
299def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>;
300def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>;
301def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>;
302def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>;
303def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>;
Aaron Watry372cecf2013-09-06 20:17:42 +0000304
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000305def mskor_global : PatFrag<(ops node:$val, node:$ptr),
306 (AMDGPUstore_mskor node:$val, node:$ptr), [{
307 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
308}]>;
309
Matt Arsenaultc793e1d2014-06-11 18:08:48 +0000310def atomic_cmp_swap_32_local :
311 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
312 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
313 AtomicSDNode *AN = cast<AtomicSDNode>(N);
314 return AN->getMemoryVT() == MVT::i32 &&
315 AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
316}]>;
317
Matt Arsenaultcaa0ec22014-06-11 18:08:54 +0000318def atomic_cmp_swap_64_local :
319 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
320 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
321 AtomicSDNode *AN = cast<AtomicSDNode>(N);
322 return AN->getMemoryVT() == MVT::i64 &&
323 AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
324}]>;
325
Matt Arsenaultc793e1d2014-06-11 18:08:48 +0000326
Tom Stellard75aadc22012-12-11 21:25:42 +0000327class Constants {
328int TWO_PI = 0x40c90fdb;
329int PI = 0x40490fdb;
330int TWO_PI_INV = 0x3e22f983;
NAKAMURA Takumi4bb85f92013-10-28 04:07:23 +0000331int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
Matt Arsenaultaeca2fa2014-05-31 06:47:42 +0000332int FP32_NEG_ONE = 0xbf800000;
333int FP32_ONE = 0x3f800000;
Tom Stellard75aadc22012-12-11 21:25:42 +0000334}
335def CONST : Constants;
336
337def FP_ZERO : PatLeaf <
338 (fpimm),
339 [{return N->getValueAPF().isZero();}]
340>;
341
342def FP_ONE : PatLeaf <
343 (fpimm),
344 [{return N->isExactlyValue(1.0);}]
345>;
346
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000347let isCodeGenOnly = 1, isPseudo = 1 in {
348
349let usesCustomInserter = 1 in {
Tom Stellard75aadc22012-12-11 21:25:42 +0000350
351class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
352 (outs rc:$dst),
353 (ins rc:$src0),
354 "CLAMP $dst, $src0",
Matt Arsenault5d47d4a2014-06-12 21:15:44 +0000355 [(set f32:$dst, (AMDGPUclamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000356>;
357
358class FABS <RegisterClass rc> : AMDGPUShaderInst <
359 (outs rc:$dst),
360 (ins rc:$src0),
361 "FABS $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000362 [(set f32:$dst, (fabs f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000363>;
364
365class FNEG <RegisterClass rc> : AMDGPUShaderInst <
366 (outs rc:$dst),
367 (ins rc:$src0),
368 "FNEG $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000369 [(set f32:$dst, (fneg f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000370>;
371
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000372} // usesCustomInserter = 1
373
374multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
375 ComplexPattern addrPat> {
Tom Stellard81d871d2013-11-13 23:36:50 +0000376let UseNamedOperandTable = 1 in {
377
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000378 def RegisterLoad : AMDGPUShaderInst <
379 (outs dstClass:$dst),
380 (ins addrClass:$addr, i32imm:$chan),
381 "RegisterLoad $dst, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000382 [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000383 > {
384 let isRegisterLoad = 1;
385 }
386
387 def RegisterStore : AMDGPUShaderInst <
388 (outs),
389 (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
390 "RegisterStore $val, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000391 [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000392 > {
393 let isRegisterStore = 1;
394 }
395}
Tom Stellard81d871d2013-11-13 23:36:50 +0000396}
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000397
398} // End isCodeGenOnly = 1, isPseudo = 1
Tom Stellard75aadc22012-12-11 21:25:42 +0000399
400/* Generic helper patterns for intrinsics */
401/* -------------------------------------- */
402
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000403class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
404 : Pat <
405 (fpow f32:$src0, f32:$src1),
406 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
Tom Stellard75aadc22012-12-11 21:25:42 +0000407>;
408
409/* Other helper patterns */
410/* --------------------- */
411
412/* Extract element pattern */
Matt Arsenault530dde42014-02-26 23:00:58 +0000413class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000414 SubRegIndex sub_reg>
415 : Pat<
416 (sub_type (vector_extract vec_type:$src, sub_idx)),
417 (EXTRACT_SUBREG $src, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000418>;
419
420/* Insert element pattern */
421class Insert_Element <ValueType elem_type, ValueType vec_type,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000422 int sub_idx, SubRegIndex sub_reg>
423 : Pat <
424 (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
425 (INSERT_SUBREG $vec, $elem, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000426>;
427
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000428// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
429// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000430// bitconvert pattern
431class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
432 (dt (bitconvert (st rc:$src0))),
433 (dt rc:$src0)
434>;
435
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000436// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
437// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000438class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
439 (vt (AMDGPUdwordaddr (vt rc:$addr))),
440 (vt rc:$addr)
441>;
442
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000443// BFI_INT patterns
444
Matt Arsenault6e439652014-06-10 19:00:20 +0000445multiclass BFIPatterns <Instruction BFI_INT, Instruction LoadImm32> {
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000446
447 // Definition from ISA doc:
448 // (y & x) | (z & ~x)
449 def : Pat <
450 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
451 (BFI_INT $x, $y, $z)
452 >;
453
454 // SHA-256 Ch function
455 // z ^ (x & (y ^ z))
456 def : Pat <
457 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
458 (BFI_INT $x, $y, $z)
459 >;
460
Matt Arsenault6e439652014-06-10 19:00:20 +0000461 def : Pat <
462 (fcopysign f32:$src0, f32:$src1),
463 (BFI_INT (LoadImm32 0x7fffffff), $src0, $src1)
464 >;
465
466 def : Pat <
467 (f64 (fcopysign f64:$src0, f64:$src1)),
468 (INSERT_SUBREG (INSERT_SUBREG (f64 (IMPLICIT_DEF)),
469 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0),
470 (BFI_INT (LoadImm32 0x7fffffff),
471 (i32 (EXTRACT_SUBREG $src0, sub1)),
472 (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
473 >;
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000474}
475
Tom Stellardeac65dd2013-05-03 17:21:20 +0000476// SHA-256 Ma patterns
477
478// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
479class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
480 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
481 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
482>;
483
Tom Stellard2b971eb2013-05-10 02:09:45 +0000484// Bitfield extract patterns
485
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000486/*
487
488XXX: The BFE pattern is not working correctly because the XForm is not being
489applied.
490
Tom Stellard2b971eb2013-05-10 02:09:45 +0000491def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
492def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
493 SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
494
495class BFEPattern <Instruction BFE> : Pat <
496 (and (srl i32:$x, legalshift32:$y), bfemask:$z),
497 (BFE $x, $y, $z)
498>;
499
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000500*/
501
Tom Stellard5643c4a2013-05-20 15:02:19 +0000502// rotr pattern
503class ROTRPattern <Instruction BIT_ALIGN> : Pat <
504 (rotr i32:$src0, i32:$src1),
505 (BIT_ALIGN $src0, $src0, $src1)
506>;
507
Tom Stellard41fc7852013-07-23 01:48:42 +0000508// 24-bit arithmetic patterns
509def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
510
511/*
512class UMUL24Pattern <Instruction UMUL24> : Pat <
513 (mul U24:$x, U24:$y),
514 (UMUL24 $x, $y)
515>;
516*/
517
Matt Arsenaulteb260202014-05-22 18:00:15 +0000518class IMad24Pat<Instruction Inst> : Pat <
519 (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
520 (Inst $src0, $src1, $src2)
521>;
522
523class UMad24Pat<Instruction Inst> : Pat <
524 (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
525 (Inst $src0, $src1, $src2)
526>;
527
Matt Arsenault493c5f12014-05-22 18:00:24 +0000528multiclass Expand24IBitOps<Instruction MulInst, Instruction AddInst> {
529 def _expand_imad24 : Pat <
530 (AMDGPUmad_i24 i32:$src0, i32:$src1, i32:$src2),
531 (AddInst (MulInst $src0, $src1), $src2)
532 >;
Matt Arsenaultf15a0562014-05-22 18:00:20 +0000533
Matt Arsenault493c5f12014-05-22 18:00:24 +0000534 def _expand_imul24 : Pat <
535 (AMDGPUmul_i24 i32:$src0, i32:$src1),
536 (MulInst $src0, $src1)
537 >;
538}
Matt Arsenaultf15a0562014-05-22 18:00:20 +0000539
Matt Arsenault493c5f12014-05-22 18:00:24 +0000540multiclass Expand24UBitOps<Instruction MulInst, Instruction AddInst> {
541 def _expand_umad24 : Pat <
542 (AMDGPUmad_u24 i32:$src0, i32:$src1, i32:$src2),
543 (AddInst (MulInst $src0, $src1), $src2)
544 >;
545
546 def _expand_umul24 : Pat <
547 (AMDGPUmul_u24 i32:$src0, i32:$src1),
548 (MulInst $src0, $src1)
549 >;
550}
Matt Arsenaulteb260202014-05-22 18:00:15 +0000551
Matt Arsenaulta0050b02014-06-19 01:19:19 +0000552class RcpPat<Instruction RcpInst, ValueType vt> : Pat <
553 (fdiv FP_ONE, vt:$src),
554 (RcpInst $src)
555>;
556
Matt Arsenault257d48d2014-06-24 22:13:39 +0000557multiclass RsqPat<Instruction RsqInst, ValueType vt> {
558 def : Pat <
559 (fdiv FP_ONE, (fsqrt vt:$src)),
560 (RsqInst $src)
561 >;
562
563 def : Pat <
564 (AMDGPUrcp (fsqrt vt:$src)),
565 (RsqInst $src)
566 >;
567}
Matt Arsenaulta0050b02014-06-19 01:19:19 +0000568
Tom Stellard75aadc22012-12-11 21:25:42 +0000569include "R600Instructions.td"
Tom Stellard2c1c9de2014-03-24 16:07:25 +0000570include "R700Instructions.td"
571include "EvergreenInstructions.td"
572include "CaymanInstructions.td"
Tom Stellard75aadc22012-12-11 21:25:42 +0000573
574include "SIInstrInfo.td"
575