blob: 6e56b0b05027626637f39647d11aa47dbdee67e8 [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
Tom Stellarde1818af2016-02-18 03:42:32 +000026 // SoftFail is a field the disassembler can use to provide a way for
27 // instructions to not match without killing the whole decode process. It is
28 // mainly used for ARM, but Tablegen expects this field to exist or it fails
29 // to build the decode table.
30 field bits<64> SoftFail = 0;
31
32 let DecoderNamespace = Namespace;
33
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000034 let TSFlags{63} = isRegisterLoad;
35 let TSFlags{62} = isRegisterStore;
Tom Stellard75aadc22012-12-11 21:25:42 +000036}
37
38class AMDGPUShaderInst <dag outs, dag ins, string asm, list<dag> pattern>
39 : AMDGPUInst<outs, ins, asm, pattern> {
40
41 field bits<32> Inst = 0xffffffff;
42
43}
44
Matt Arsenaultf171cf22014-07-14 23:40:49 +000045def FP32Denormals : Predicate<"Subtarget.hasFP32Denormals()">;
46def FP64Denormals : Predicate<"Subtarget.hasFP64Denormals()">;
Matt Arsenault1d077742014-07-15 20:18:24 +000047def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">;
Matt Arsenaultf171cf22014-07-14 23:40:49 +000048
Tom Stellard75aadc22012-12-11 21:25:42 +000049def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
Tom Stellard81d871d2013-11-13 23:36:50 +000050def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>;
Tom Stellard75aadc22012-12-11 21:25:42 +000051
Tom Stellardb02094e2014-07-21 15:45:01 +000052let OperandType = "OPERAND_IMMEDIATE" in {
53
Matt Arsenault4d7d3832014-04-15 22:32:49 +000054def u32imm : Operand<i32> {
55 let PrintMethod = "printU32ImmOperand";
56}
57
58def u16imm : Operand<i16> {
59 let PrintMethod = "printU16ImmOperand";
60}
61
62def u8imm : Operand<i8> {
63 let PrintMethod = "printU8ImmOperand";
64}
65
Tom Stellardb02094e2014-07-21 15:45:01 +000066} // End OperandType = "OPERAND_IMMEDIATE"
67
Tom Stellardbc5b5372014-06-13 16:38:59 +000068//===--------------------------------------------------------------------===//
69// Custom Operands
70//===--------------------------------------------------------------------===//
71def brtarget : Operand<OtherVT>;
72
Tom Stellardc0845332013-11-22 23:07:58 +000073//===----------------------------------------------------------------------===//
74// PatLeafs for floating-point comparisons
75//===----------------------------------------------------------------------===//
Tom Stellard75aadc22012-12-11 21:25:42 +000076
Tom Stellard0351ea22013-09-28 02:50:50 +000077def COND_OEQ : PatLeaf <
78 (cond),
79 [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
80>;
81
Matt Arsenault9cded7a2014-12-11 22:15:35 +000082def COND_ONE : PatLeaf <
83 (cond),
84 [{return N->get() == ISD::SETONE || N->get() == ISD::SETNE;}]
85>;
86
Tom Stellard0351ea22013-09-28 02:50:50 +000087def COND_OGT : PatLeaf <
88 (cond),
89 [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
90>;
91
Tom Stellard0351ea22013-09-28 02:50:50 +000092def COND_OGE : PatLeaf <
93 (cond),
94 [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
95>;
96
Tom Stellardc0845332013-11-22 23:07:58 +000097def COND_OLT : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +000098 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +000099 [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
Tom Stellard75aadc22012-12-11 21:25:42 +0000100>;
101
Tom Stellardc0845332013-11-22 23:07:58 +0000102def COND_OLE : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +0000103 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +0000104 [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
105>;
106
Tom Stellardc0845332013-11-22 23:07:58 +0000107
108def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
109def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
110
111//===----------------------------------------------------------------------===//
Matt Arsenault8b989ef2014-12-11 22:15:39 +0000112// PatLeafs for unsigned / unordered comparisons
Tom Stellardc0845332013-11-22 23:07:58 +0000113//===----------------------------------------------------------------------===//
114
Matt Arsenault9cded7a2014-12-11 22:15:35 +0000115def COND_UEQ : PatLeaf <(cond), [{return N->get() == ISD::SETUEQ;}]>;
116def COND_UNE : PatLeaf <(cond), [{return N->get() == ISD::SETUNE;}]>;
Tom Stellardc0845332013-11-22 23:07:58 +0000117def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
118def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
119def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
120def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
121
Matt Arsenault9cded7a2014-12-11 22:15:35 +0000122// XXX - For some reason R600 version is preferring to use unordered
123// for setne?
124def COND_UNE_NE : PatLeaf <
125 (cond),
126 [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
127>;
128
Tom Stellardc0845332013-11-22 23:07:58 +0000129//===----------------------------------------------------------------------===//
130// PatLeafs for signed comparisons
131//===----------------------------------------------------------------------===//
132
133def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
134def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
135def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
136def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
137
138//===----------------------------------------------------------------------===//
139// PatLeafs for integer equality
140//===----------------------------------------------------------------------===//
141
142def COND_EQ : PatLeaf <
143 (cond),
144 [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
145>;
146
147def COND_NE : PatLeaf <
148 (cond),
149 [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
Tom Stellard75aadc22012-12-11 21:25:42 +0000150>;
151
Christian Konigb19849a2013-02-21 15:17:04 +0000152def COND_NULL : PatLeaf <
153 (cond),
Tom Stellardaa9a1a82014-08-01 02:05:57 +0000154 [{(void)N; return false;}]
Christian Konigb19849a2013-02-21 15:17:04 +0000155>;
156
Matt Arsenaultc89f2912016-03-07 21:54:48 +0000157
158//===----------------------------------------------------------------------===//
159// Misc. PatFrags
160//===----------------------------------------------------------------------===//
161
162class HasOneUseBinOp<SDPatternOperator op> : PatFrag<
163 (ops node:$src0, node:$src1),
164 (op $src0, $src1),
165 [{ return N->hasOneUse(); }]
166>;
167
Tom Stellard75aadc22012-12-11 21:25:42 +0000168//===----------------------------------------------------------------------===//
169// Load/Store Pattern Fragments
170//===----------------------------------------------------------------------===//
171
Tom Stellardb02094e2014-07-21 15:45:01 +0000172class PrivateMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
173 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
174}]>;
175
176class PrivateLoad <SDPatternOperator op> : PrivateMemOp <
177 (ops node:$ptr), (op node:$ptr)
178>;
179
180class PrivateStore <SDPatternOperator op> : PrivateMemOp <
181 (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
182>;
183
Tom Stellardb02094e2014-07-21 15:45:01 +0000184def load_private : PrivateLoad <load>;
185
186def truncstorei8_private : PrivateStore <truncstorei8>;
187def truncstorei16_private : PrivateStore <truncstorei16>;
188def store_private : PrivateStore <store>;
189
Tom Stellardbc5b5372014-06-13 16:38:59 +0000190def global_store : PatFrag<(ops node:$val, node:$ptr),
191 (store node:$val, node:$ptr), [{
192 return isGlobalStore(dyn_cast<StoreSDNode>(N));
193}]>;
194
Jan Vesely43b7b5b2016-04-07 19:23:11 +0000195def global_store_atomic : PatFrag<(ops node:$val, node:$ptr),
196 (atomic_store node:$val, node:$ptr), [{
197 return isGlobalStore(dyn_cast<MemSDNode>(N));
198}]>;
199
Tom Stellardbc5b5372014-06-13 16:38:59 +0000200// Global address space loads
201def global_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
202 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
203}]>;
204
205// Constant address space loads
206def constant_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
207 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
208}]>;
209
Tom Stellard381a94a2015-05-12 15:00:49 +0000210class AZExtLoadBase <SDPatternOperator ld_node>: PatFrag<(ops node:$ptr),
211 (ld_node node:$ptr), [{
Tom Stellard31209cc2013-07-15 19:00:09 +0000212 LoadSDNode *L = cast<LoadSDNode>(N);
213 return L->getExtensionType() == ISD::ZEXTLOAD ||
214 L->getExtensionType() == ISD::EXTLOAD;
215}]>;
216
Tom Stellard381a94a2015-05-12 15:00:49 +0000217def az_extload : AZExtLoadBase <unindexedload>;
218
Tom Stellard33dd04b2013-07-23 01:47:52 +0000219def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
220 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
221}]>;
222
Tom Stellardc6f4a292013-08-26 15:05:59 +0000223def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
224 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
225}]>;
226
Tom Stellard9f950332013-07-23 01:48:35 +0000227def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
Tom Stellard75aadc22012-12-11 21:25:42 +0000228 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
229}]>;
230
Tom Stellard33dd04b2013-07-23 01:47:52 +0000231def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
Tom Stellard9f950332013-07-23 01:48:35 +0000232 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
233}]>;
234
235def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
236 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
237}]>;
238
Tom Stellardc6f4a292013-08-26 15:05:59 +0000239def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
240 return isLocalLoad(dyn_cast<LoadSDNode>(N));
241}]>;
242
243def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
244 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellard33dd04b2013-07-23 01:47:52 +0000245}]>;
246
Tom Stellardbc377682015-02-17 16:36:00 +0000247def extloadi8_private : PrivateLoad <az_extloadi8>;
248def sextloadi8_private : PrivateLoad <sextloadi8>;
249
Tom Stellard33dd04b2013-07-23 01:47:52 +0000250def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
251 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
252}]>;
253
254def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
255 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
256}]>;
257
Tom Stellard9f950332013-07-23 01:48:35 +0000258def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
Tom Stellard07a10a32013-06-03 17:39:43 +0000259 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
260}]>;
261
Tom Stellard9f950332013-07-23 01:48:35 +0000262def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
263 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
264}]>;
265
266def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
267 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
268}]>;
269
Tom Stellardc6f4a292013-08-26 15:05:59 +0000270def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
271 return isLocalLoad(dyn_cast<LoadSDNode>(N));
272}]>;
273
274def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
275 return isLocalLoad(dyn_cast<LoadSDNode>(N));
276}]>;
277
Tom Stellardbc377682015-02-17 16:36:00 +0000278def extloadi16_private : PrivateLoad <az_extloadi16>;
279def sextloadi16_private : PrivateLoad <sextloadi16>;
280
Tom Stellard31209cc2013-07-15 19:00:09 +0000281def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
282 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
283}]>;
284
285def az_extloadi32_global : PatFrag<(ops node:$ptr),
286 (az_extloadi32 node:$ptr), [{
287 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
288}]>;
289
Matt Arsenault3f981402014-09-15 15:41:53 +0000290def az_extloadi32_flat : PatFrag<(ops node:$ptr),
291 (az_extloadi32 node:$ptr), [{
292 return isFlatLoad(dyn_cast<LoadSDNode>(N));
293}]>;
294
Tom Stellard31209cc2013-07-15 19:00:09 +0000295def az_extloadi32_constant : PatFrag<(ops node:$ptr),
296 (az_extloadi32 node:$ptr), [{
297 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
298}]>;
299
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000300def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
301 (truncstorei8 node:$val, node:$ptr), [{
302 return isGlobalStore(dyn_cast<StoreSDNode>(N));
303}]>;
304
305def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
306 (truncstorei16 node:$val, node:$ptr), [{
307 return isGlobalStore(dyn_cast<StoreSDNode>(N));
308}]>;
309
Tom Stellardc026e8b2013-06-28 15:47:08 +0000310def local_store : PatFrag<(ops node:$val, node:$ptr),
311 (store node:$val, node:$ptr), [{
Tom Stellardf3d166a2013-08-26 15:05:49 +0000312 return isLocalStore(dyn_cast<StoreSDNode>(N));
313}]>;
314
315def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
316 (truncstorei8 node:$val, node:$ptr), [{
317 return isLocalStore(dyn_cast<StoreSDNode>(N));
318}]>;
319
320def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
321 (truncstorei16 node:$val, node:$ptr), [{
322 return isLocalStore(dyn_cast<StoreSDNode>(N));
323}]>;
324
325def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
326 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellardc026e8b2013-06-28 15:47:08 +0000327}]>;
328
Tom Stellardf3fc5552014-08-22 18:49:35 +0000329class Aligned8Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{
330 return cast<MemSDNode>(N)->getAlignment() % 8 == 0;
331}]>;
332
333def local_load_aligned8bytes : Aligned8Bytes <
334 (ops node:$ptr), (local_load node:$ptr)
335>;
336
337def local_store_aligned8bytes : Aligned8Bytes <
338 (ops node:$val, node:$ptr), (local_store node:$val, node:$ptr)
339>;
Matt Arsenault72574102014-06-11 18:08:34 +0000340
341class local_binary_atomic_op<SDNode atomic_op> :
342 PatFrag<(ops node:$ptr, node:$value),
343 (atomic_op node:$ptr, node:$value), [{
344 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
Tom Stellard13c68ef2013-09-05 18:38:09 +0000345}]>;
346
Matt Arsenault72574102014-06-11 18:08:34 +0000347
348def atomic_swap_local : local_binary_atomic_op<atomic_swap>;
349def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>;
350def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>;
351def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>;
352def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>;
353def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>;
354def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>;
355def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>;
356def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>;
357def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>;
358def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>;
Aaron Watry372cecf2013-09-06 20:17:42 +0000359
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000360def mskor_global : PatFrag<(ops node:$val, node:$ptr),
361 (AMDGPUstore_mskor node:$val, node:$ptr), [{
Benjamin Kramer619c4e52015-04-10 11:24:51 +0000362 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000363}]>;
364
Tom Stellard381a94a2015-05-12 15:00:49 +0000365multiclass AtomicCmpSwapLocal <SDNode cmp_swap_node> {
Matt Arsenault3f981402014-09-15 15:41:53 +0000366
Tom Stellard381a94a2015-05-12 15:00:49 +0000367 def _32_local : PatFrag <
368 (ops node:$ptr, node:$cmp, node:$swap),
369 (cmp_swap_node 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 }]>;
Matt Arsenaultc793e1d2014-06-11 18:08:48 +0000374
Tom Stellard381a94a2015-05-12 15:00:49 +0000375 def _64_local : PatFrag<
376 (ops node:$ptr, node:$cmp, node:$swap),
377 (cmp_swap_node 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
384defm atomic_cmp_swap : AtomicCmpSwapLocal <atomic_cmp_swap>;
Matt Arsenaultcaa0ec22014-06-11 18:08:54 +0000385
Matt Arsenault3f981402014-09-15 15:41:53 +0000386def mskor_flat : PatFrag<(ops node:$val, node:$ptr),
387 (AMDGPUstore_mskor node:$val, node:$ptr), [{
Benjamin Kramer619c4e52015-04-10 11:24:51 +0000388 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::FLAT_ADDRESS;
Matt Arsenault3f981402014-09-15 15:41:53 +0000389}]>;
390
Tom Stellard7980fc82014-09-25 18:30:26 +0000391class global_binary_atomic_op<SDNode atomic_op> : PatFrag<
392 (ops node:$ptr, node:$value),
393 (atomic_op node:$ptr, node:$value),
394 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;}]
395>;
396
Aaron Watry81144372014-10-17 23:33:03 +0000397def atomic_swap_global : global_binary_atomic_op<atomic_swap>;
Tom Stellard7980fc82014-09-25 18:30:26 +0000398def atomic_add_global : global_binary_atomic_op<atomic_load_add>;
Aaron Watry62127802014-10-17 23:32:54 +0000399def atomic_and_global : global_binary_atomic_op<atomic_load_and>;
Aaron Watry29f295d2014-10-17 23:32:56 +0000400def atomic_max_global : global_binary_atomic_op<atomic_load_max>;
Aaron Watry58c99922014-10-17 23:32:57 +0000401def atomic_min_global : global_binary_atomic_op<atomic_load_min>;
Aaron Watry8a911e62014-10-17 23:32:59 +0000402def atomic_or_global : global_binary_atomic_op<atomic_load_or>;
Aaron Watry328f1ba2014-10-17 23:32:52 +0000403def atomic_sub_global : global_binary_atomic_op<atomic_load_sub>;
Aaron Watry29f295d2014-10-17 23:32:56 +0000404def atomic_umax_global : global_binary_atomic_op<atomic_load_umax>;
Aaron Watry58c99922014-10-17 23:32:57 +0000405def atomic_umin_global : global_binary_atomic_op<atomic_load_umin>;
Aaron Watryd672ee22014-10-17 23:33:01 +0000406def atomic_xor_global : global_binary_atomic_op<atomic_load_xor>;
Tom Stellard7980fc82014-09-25 18:30:26 +0000407
Tom Stellard354a43c2016-04-01 18:27:37 +0000408def atomic_cmp_swap_global : global_binary_atomic_op<AMDGPUatomic_cmp_swap>;
409def atomic_cmp_swap_global_nortn : PatFrag<
410 (ops node:$ptr, node:$value),
411 (atomic_cmp_swap_global node:$ptr, node:$value),
412 [{ return SDValue(N, 0).use_empty(); }]
413>;
414
Tom Stellardb4a313a2014-08-01 00:32:39 +0000415//===----------------------------------------------------------------------===//
416// Misc Pattern Fragments
417//===----------------------------------------------------------------------===//
418
Tom Stellard75aadc22012-12-11 21:25:42 +0000419class Constants {
420int TWO_PI = 0x40c90fdb;
421int PI = 0x40490fdb;
422int TWO_PI_INV = 0x3e22f983;
NAKAMURA Takumi4bb85f92013-10-28 04:07:23 +0000423int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
Matt Arsenaultaeca2fa2014-05-31 06:47:42 +0000424int FP32_NEG_ONE = 0xbf800000;
425int FP32_ONE = 0x3f800000;
Tom Stellard75aadc22012-12-11 21:25:42 +0000426}
427def CONST : Constants;
428
429def FP_ZERO : PatLeaf <
430 (fpimm),
431 [{return N->getValueAPF().isZero();}]
432>;
433
434def FP_ONE : PatLeaf <
435 (fpimm),
436 [{return N->isExactlyValue(1.0);}]
437>;
438
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000439def FP_HALF : PatLeaf <
440 (fpimm),
441 [{return N->isExactlyValue(0.5);}]
442>;
443
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000444let isCodeGenOnly = 1, isPseudo = 1 in {
445
446let usesCustomInserter = 1 in {
Tom Stellard75aadc22012-12-11 21:25:42 +0000447
448class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
449 (outs rc:$dst),
450 (ins rc:$src0),
451 "CLAMP $dst, $src0",
Matt Arsenault5d47d4a2014-06-12 21:15:44 +0000452 [(set f32:$dst, (AMDGPUclamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000453>;
454
455class FABS <RegisterClass rc> : AMDGPUShaderInst <
456 (outs rc:$dst),
457 (ins rc:$src0),
458 "FABS $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000459 [(set f32:$dst, (fabs f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000460>;
461
462class FNEG <RegisterClass rc> : AMDGPUShaderInst <
463 (outs rc:$dst),
464 (ins rc:$src0),
465 "FNEG $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000466 [(set f32:$dst, (fneg f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000467>;
468
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000469} // usesCustomInserter = 1
470
471multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
472 ComplexPattern addrPat> {
Tom Stellard81d871d2013-11-13 23:36:50 +0000473let UseNamedOperandTable = 1 in {
474
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000475 def RegisterLoad : AMDGPUShaderInst <
476 (outs dstClass:$dst),
477 (ins addrClass:$addr, i32imm:$chan),
478 "RegisterLoad $dst, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000479 [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000480 > {
481 let isRegisterLoad = 1;
482 }
483
484 def RegisterStore : AMDGPUShaderInst <
485 (outs),
486 (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
487 "RegisterStore $val, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000488 [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000489 > {
490 let isRegisterStore = 1;
491 }
492}
Tom Stellard81d871d2013-11-13 23:36:50 +0000493}
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000494
495} // End isCodeGenOnly = 1, isPseudo = 1
Tom Stellard75aadc22012-12-11 21:25:42 +0000496
497/* Generic helper patterns for intrinsics */
498/* -------------------------------------- */
499
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000500class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
501 : Pat <
502 (fpow f32:$src0, f32:$src1),
503 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
Tom Stellard75aadc22012-12-11 21:25:42 +0000504>;
505
506/* Other helper patterns */
507/* --------------------- */
508
509/* Extract element pattern */
Matt Arsenault530dde42014-02-26 23:00:58 +0000510class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000511 SubRegIndex sub_reg>
512 : Pat<
Matt Arsenaultfbd9bbf2015-12-11 19:20:16 +0000513 (sub_type (extractelt vec_type:$src, sub_idx)),
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000514 (EXTRACT_SUBREG $src, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000515>;
516
517/* Insert element pattern */
518class Insert_Element <ValueType elem_type, ValueType vec_type,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000519 int sub_idx, SubRegIndex sub_reg>
520 : Pat <
Matt Arsenaultfbd9bbf2015-12-11 19:20:16 +0000521 (insertelt vec_type:$vec, elem_type:$elem, sub_idx),
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000522 (INSERT_SUBREG $vec, $elem, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000523>;
524
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000525// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
526// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000527// bitconvert pattern
528class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
529 (dt (bitconvert (st rc:$src0))),
530 (dt rc:$src0)
531>;
532
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000533// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
534// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000535class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
536 (vt (AMDGPUdwordaddr (vt rc:$addr))),
537 (vt rc:$addr)
538>;
539
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000540// BFI_INT patterns
541
Matt Arsenault7d858d82014-11-02 23:46:54 +0000542multiclass BFIPatterns <Instruction BFI_INT,
543 Instruction LoadImm32,
544 RegisterClass RC64> {
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000545 // Definition from ISA doc:
546 // (y & x) | (z & ~x)
547 def : Pat <
548 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
549 (BFI_INT $x, $y, $z)
550 >;
551
552 // SHA-256 Ch function
553 // z ^ (x & (y ^ z))
554 def : Pat <
555 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
556 (BFI_INT $x, $y, $z)
557 >;
558
Matt Arsenault6e439652014-06-10 19:00:20 +0000559 def : Pat <
560 (fcopysign f32:$src0, f32:$src1),
561 (BFI_INT (LoadImm32 0x7fffffff), $src0, $src1)
562 >;
563
564 def : Pat <
565 (f64 (fcopysign f64:$src0, f64:$src1)),
Matt Arsenault7d858d82014-11-02 23:46:54 +0000566 (REG_SEQUENCE RC64,
567 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
Matt Arsenault6e439652014-06-10 19:00:20 +0000568 (BFI_INT (LoadImm32 0x7fffffff),
569 (i32 (EXTRACT_SUBREG $src0, sub1)),
570 (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
571 >;
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000572}
573
Tom Stellardeac65dd2013-05-03 17:21:20 +0000574// SHA-256 Ma patterns
575
576// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
577class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
578 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
579 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
580>;
581
Tom Stellard2b971eb2013-05-10 02:09:45 +0000582// Bitfield extract patterns
583
Marek Olsak949f5da2015-03-24 13:40:34 +0000584def IMMZeroBasedBitfieldMask : PatLeaf <(imm), [{
585 return isMask_32(N->getZExtValue());
586}]>;
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000587
Marek Olsak949f5da2015-03-24 13:40:34 +0000588def IMMPopCount : SDNodeXForm<imm, [{
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000589 return CurDAG->getTargetConstant(countPopulation(N->getZExtValue()), SDLoc(N),
Marek Olsak949f5da2015-03-24 13:40:34 +0000590 MVT::i32);
591}]>;
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000592
Marek Olsak949f5da2015-03-24 13:40:34 +0000593class BFEPattern <Instruction BFE, Instruction MOV> : Pat <
594 (i32 (and (i32 (srl i32:$src, i32:$rshift)), IMMZeroBasedBitfieldMask:$mask)),
595 (BFE $src, $rshift, (MOV (i32 (IMMPopCount $mask))))
Tom Stellard2b971eb2013-05-10 02:09:45 +0000596>;
597
Tom Stellard5643c4a2013-05-20 15:02:19 +0000598// rotr pattern
599class ROTRPattern <Instruction BIT_ALIGN> : Pat <
600 (rotr i32:$src0, i32:$src1),
601 (BIT_ALIGN $src0, $src0, $src1)
602>;
603
Matt Arsenaultc89f2912016-03-07 21:54:48 +0000604// This matches 16 permutations of
605// max(min(x, y), min(max(x, y), z))
606class IntMed3Pat<Instruction med3Inst,
607 SDPatternOperator max,
608 SDPatternOperator max_oneuse,
609 SDPatternOperator min_oneuse> : Pat<
610 (max (min_oneuse i32:$src0, i32:$src1),
611 (min_oneuse (max_oneuse i32:$src0, i32:$src1), i32:$src2)),
612 (med3Inst $src0, $src1, $src2)
613>;
614
615let Properties = [SDNPCommutative, SDNPAssociative] in {
616def smax_oneuse : HasOneUseBinOp<smax>;
617def smin_oneuse : HasOneUseBinOp<smin>;
618def umax_oneuse : HasOneUseBinOp<umax>;
619def umin_oneuse : HasOneUseBinOp<umin>;
620} // Properties = [SDNPCommutative, SDNPAssociative]
621
622
Tom Stellard41fc7852013-07-23 01:48:42 +0000623// 24-bit arithmetic patterns
624def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
625
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000626// Special conversion patterns
627
628def cvt_rpi_i32_f32 : PatFrag <
629 (ops node:$src),
Matt Arsenault08ad3282015-01-31 21:28:13 +0000630 (fp_to_sint (ffloor (fadd $src, FP_HALF))),
631 [{ (void) N; return TM.Options.NoNaNsFPMath; }]
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000632>;
633
634def cvt_flr_i32_f32 : PatFrag <
635 (ops node:$src),
Matt Arsenault08ad3282015-01-31 21:28:13 +0000636 (fp_to_sint (ffloor $src)),
637 [{ (void)N; return TM.Options.NoNaNsFPMath; }]
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000638>;
639
Matt Arsenaulteb260202014-05-22 18:00:15 +0000640class IMad24Pat<Instruction Inst> : Pat <
641 (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
642 (Inst $src0, $src1, $src2)
643>;
644
645class UMad24Pat<Instruction Inst> : Pat <
646 (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
647 (Inst $src0, $src1, $src2)
648>;
649
Matt Arsenaulta0050b02014-06-19 01:19:19 +0000650class RcpPat<Instruction RcpInst, ValueType vt> : Pat <
651 (fdiv FP_ONE, vt:$src),
652 (RcpInst $src)
653>;
654
Matt Arsenault0bbcd8b2015-02-14 04:30:08 +0000655class RsqPat<Instruction RsqInst, ValueType vt> : Pat <
656 (AMDGPUrcp (fsqrt vt:$src)),
657 (RsqInst $src)
658>;
Matt Arsenaulta0050b02014-06-19 01:19:19 +0000659
Tom Stellard75aadc22012-12-11 21:25:42 +0000660include "R600Instructions.td"
Tom Stellard2c1c9de2014-03-24 16:07:25 +0000661include "R700Instructions.td"
662include "EvergreenInstructions.td"
663include "CaymanInstructions.td"
Tom Stellard75aadc22012-12-11 21:25:42 +0000664
665include "SIInstrInfo.td"
666