blob: b7d1575ca898fc55254532018543dddc26ec4340 [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
Matt Arsenault648e4222016-07-14 05:23:23 +000015class AMDGPUInst <dag outs, dag ins, string asm = "",
16 list<dag> pattern = []> : Instruction {
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000017 field bit isRegisterLoad = 0;
18 field bit isRegisterStore = 0;
Tom Stellard75aadc22012-12-11 21:25:42 +000019
20 let Namespace = "AMDGPU";
21 let OutOperandList = outs;
22 let InOperandList = ins;
23 let AsmString = asm;
24 let Pattern = pattern;
25 let Itinerary = NullALU;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000026
Tom Stellarde1818af2016-02-18 03:42:32 +000027 // SoftFail is a field the disassembler can use to provide a way for
28 // instructions to not match without killing the whole decode process. It is
29 // mainly used for ARM, but Tablegen expects this field to exist or it fails
30 // to build the decode table.
31 field bits<64> SoftFail = 0;
32
33 let DecoderNamespace = Namespace;
Matt Arsenault37fefd62016-06-10 02:18:02 +000034
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000035 let TSFlags{63} = isRegisterLoad;
36 let TSFlags{62} = isRegisterStore;
Tom Stellard75aadc22012-12-11 21:25:42 +000037}
38
Matt Arsenault648e4222016-07-14 05:23:23 +000039class AMDGPUShaderInst <dag outs, dag ins, string asm = "",
40 list<dag> pattern = []> : AMDGPUInst<outs, ins, asm, pattern> {
Tom Stellard75aadc22012-12-11 21:25:42 +000041
42 field bits<32> Inst = 0xffffffff;
Tom Stellard75aadc22012-12-11 21:25:42 +000043}
44
Tom Stellardc5a154d2018-06-28 23:47:12 +000045//===---------------------------------------------------------------------===//
46// Return instruction
47//===---------------------------------------------------------------------===//
48
49class ILFormat<dag outs, dag ins, string asmstr, list<dag> pattern>
50: Instruction {
51
52 let Namespace = "AMDGPU";
53 dag OutOperandList = outs;
54 dag InOperandList = ins;
55 let Pattern = pattern;
56 let AsmString = !strconcat(asmstr, "\n");
57 let isPseudo = 1;
58 let Itinerary = NullALU;
59 bit hasIEEEFlag = 0;
60 bit hasZeroOpFlag = 0;
61 let mayLoad = 0;
62 let mayStore = 0;
63 let hasSideEffects = 0;
64 let isCodeGenOnly = 1;
65}
66
67def TruePredicate : Predicate<"true">;
68
69// Exists to help track down where SubtargetPredicate isn't set rather
70// than letting tablegen crash with an unhelpful error.
71def InvalidPred : Predicate<"predicate not set on instruction or pattern">;
72
73class PredicateControl {
74 Predicate SubtargetPredicate = InvalidPred;
75 list<Predicate> AssemblerPredicates = [];
76 Predicate AssemblerPredicate = TruePredicate;
77 list<Predicate> OtherPredicates = [];
78 list<Predicate> Predicates = !listconcat([SubtargetPredicate,
79 AssemblerPredicate],
80 AssemblerPredicates,
81 OtherPredicates);
82}
83class AMDGPUPat<dag pattern, dag result> : Pat<pattern, result>,
84 PredicateControl;
85
Stanislav Mekhanoshin06cab792017-08-30 03:03:38 +000086def FP16Denormals : Predicate<"Subtarget->hasFP16Denormals()">;
87def FP32Denormals : Predicate<"Subtarget->hasFP32Denormals()">;
88def FP64Denormals : Predicate<"Subtarget->hasFP64Denormals()">;
89def NoFP16Denormals : Predicate<"!Subtarget->hasFP16Denormals()">;
90def NoFP32Denormals : Predicate<"!Subtarget->hasFP32Denormals()">;
91def NoFP64Denormals : Predicate<"!Subtarget->hasFP64Denormals()">;
Matt Arsenault1d077742014-07-15 20:18:24 +000092def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">;
Jan Vesely39aeab42017-12-04 23:07:28 +000093def FMA : Predicate<"Subtarget->hasFMA()">;
Matt Arsenaultf171cf22014-07-14 23:40:49 +000094
Tom Stellard75aadc22012-12-11 21:25:42 +000095def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
96
Dmitry Preobrazhenskyc7d35a02017-04-26 15:34:19 +000097def u16ImmTarget : AsmOperandClass {
98 let Name = "U16Imm";
99 let RenderMethod = "addImmOperands";
100}
101
102def s16ImmTarget : AsmOperandClass {
103 let Name = "S16Imm";
104 let RenderMethod = "addImmOperands";
105}
106
Tom Stellardb02094e2014-07-21 15:45:01 +0000107let OperandType = "OPERAND_IMMEDIATE" in {
108
Matt Arsenault4d7d3832014-04-15 22:32:49 +0000109def u32imm : Operand<i32> {
110 let PrintMethod = "printU32ImmOperand";
111}
112
113def u16imm : Operand<i16> {
114 let PrintMethod = "printU16ImmOperand";
Dmitry Preobrazhenskyc7d35a02017-04-26 15:34:19 +0000115 let ParserMatchClass = u16ImmTarget;
116}
117
118def s16imm : Operand<i16> {
119 let PrintMethod = "printU16ImmOperand";
120 let ParserMatchClass = s16ImmTarget;
Matt Arsenault4d7d3832014-04-15 22:32:49 +0000121}
122
123def u8imm : Operand<i8> {
124 let PrintMethod = "printU8ImmOperand";
125}
126
Tom Stellardb02094e2014-07-21 15:45:01 +0000127} // End OperandType = "OPERAND_IMMEDIATE"
128
Tom Stellardbc5b5372014-06-13 16:38:59 +0000129//===--------------------------------------------------------------------===//
130// Custom Operands
131//===--------------------------------------------------------------------===//
132def brtarget : Operand<OtherVT>;
133
Tom Stellardc0845332013-11-22 23:07:58 +0000134//===----------------------------------------------------------------------===//
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000135// Misc. PatFrags
136//===----------------------------------------------------------------------===//
137
138class HasOneUseBinOp<SDPatternOperator op> : PatFrag<
139 (ops node:$src0, node:$src1),
140 (op $src0, $src1),
141 [{ return N->hasOneUse(); }]
142>;
143
144class HasOneUseTernaryOp<SDPatternOperator op> : PatFrag<
145 (ops node:$src0, node:$src1, node:$src2),
146 (op $src0, $src1, $src2),
147 [{ return N->hasOneUse(); }]
148>;
149
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000150let Properties = [SDNPCommutative, SDNPAssociative] in {
151def smax_oneuse : HasOneUseBinOp<smax>;
152def smin_oneuse : HasOneUseBinOp<smin>;
153def umax_oneuse : HasOneUseBinOp<umax>;
154def umin_oneuse : HasOneUseBinOp<umin>;
Matt Arsenault687ec752018-10-22 16:27:27 +0000155
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000156def fminnum_oneuse : HasOneUseBinOp<fminnum>;
157def fmaxnum_oneuse : HasOneUseBinOp<fmaxnum>;
Matt Arsenault687ec752018-10-22 16:27:27 +0000158
159def fminnum_ieee_oneuse : HasOneUseBinOp<fminnum_ieee>;
160def fmaxnum_ieee_oneuse : HasOneUseBinOp<fmaxnum_ieee>;
161
162
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000163def and_oneuse : HasOneUseBinOp<and>;
164def or_oneuse : HasOneUseBinOp<or>;
165def xor_oneuse : HasOneUseBinOp<xor>;
166} // Properties = [SDNPCommutative, SDNPAssociative]
167
Roman Lebedev9c17dad2018-06-15 09:56:39 +0000168def add_oneuse : HasOneUseBinOp<add>;
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000169def sub_oneuse : HasOneUseBinOp<sub>;
Matt Arsenaulteb522e62017-02-27 22:15:25 +0000170
171def srl_oneuse : HasOneUseBinOp<srl>;
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000172def shl_oneuse : HasOneUseBinOp<shl>;
173
174def select_oneuse : HasOneUseTernaryOp<select>;
175
Farhana Aleen3528c802018-08-21 16:21:15 +0000176def AMDGPUmul_u24_oneuse : HasOneUseBinOp<AMDGPUmul_u24>;
177def AMDGPUmul_i24_oneuse : HasOneUseBinOp<AMDGPUmul_i24>;
178
Matt Arsenaulte1cd4822017-11-13 00:22:09 +0000179def srl_16 : PatFrag<
180 (ops node:$src0), (srl_oneuse node:$src0, (i32 16))
181>;
182
183
184def hi_i16_elt : PatFrag<
185 (ops node:$src0), (i16 (trunc (i32 (srl_16 node:$src0))))
186>;
187
188
189def hi_f16_elt : PatLeaf<
190 (vt), [{
191 if (N->getOpcode() != ISD::BITCAST)
192 return false;
193 SDValue Tmp = N->getOperand(0);
194
195 if (Tmp.getOpcode() != ISD::SRL)
196 return false;
197 if (const auto *RHS = dyn_cast<ConstantSDNode>(Tmp.getOperand(1))
198 return RHS->getZExtValue() == 16;
199 return false;
200}]>;
201
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000202//===----------------------------------------------------------------------===//
Tom Stellardc0845332013-11-22 23:07:58 +0000203// PatLeafs for floating-point comparisons
204//===----------------------------------------------------------------------===//
Tom Stellard75aadc22012-12-11 21:25:42 +0000205
Tom Stellard0351ea22013-09-28 02:50:50 +0000206def COND_OEQ : PatLeaf <
207 (cond),
208 [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
209>;
210
Matt Arsenault9cded7a2014-12-11 22:15:35 +0000211def COND_ONE : PatLeaf <
212 (cond),
213 [{return N->get() == ISD::SETONE || N->get() == ISD::SETNE;}]
214>;
215
Tom Stellard0351ea22013-09-28 02:50:50 +0000216def COND_OGT : PatLeaf <
217 (cond),
218 [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
219>;
220
Tom Stellard0351ea22013-09-28 02:50:50 +0000221def COND_OGE : PatLeaf <
222 (cond),
223 [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
224>;
225
Tom Stellardc0845332013-11-22 23:07:58 +0000226def COND_OLT : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +0000227 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +0000228 [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
Tom Stellard75aadc22012-12-11 21:25:42 +0000229>;
230
Tom Stellardc0845332013-11-22 23:07:58 +0000231def COND_OLE : PatLeaf <
Tom Stellard75aadc22012-12-11 21:25:42 +0000232 (cond),
Tom Stellardc0845332013-11-22 23:07:58 +0000233 [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
234>;
235
Tom Stellardc0845332013-11-22 23:07:58 +0000236def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
237def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
238
239//===----------------------------------------------------------------------===//
Matt Arsenault8b989ef2014-12-11 22:15:39 +0000240// PatLeafs for unsigned / unordered comparisons
Tom Stellardc0845332013-11-22 23:07:58 +0000241//===----------------------------------------------------------------------===//
242
Matt Arsenault9cded7a2014-12-11 22:15:35 +0000243def COND_UEQ : PatLeaf <(cond), [{return N->get() == ISD::SETUEQ;}]>;
244def COND_UNE : PatLeaf <(cond), [{return N->get() == ISD::SETUNE;}]>;
Tom Stellardc0845332013-11-22 23:07:58 +0000245def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
246def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
247def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
248def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
249
Matt Arsenault9cded7a2014-12-11 22:15:35 +0000250// XXX - For some reason R600 version is preferring to use unordered
251// for setne?
252def COND_UNE_NE : PatLeaf <
253 (cond),
254 [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
255>;
256
Tom Stellardc0845332013-11-22 23:07:58 +0000257//===----------------------------------------------------------------------===//
258// PatLeafs for signed comparisons
259//===----------------------------------------------------------------------===//
260
261def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
262def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
263def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
264def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
265
266//===----------------------------------------------------------------------===//
267// PatLeafs for integer equality
268//===----------------------------------------------------------------------===//
269
270def COND_EQ : PatLeaf <
271 (cond),
272 [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
273>;
274
275def COND_NE : PatLeaf <
276 (cond),
277 [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
Tom Stellard75aadc22012-12-11 21:25:42 +0000278>;
279
Christian Konigb19849a2013-02-21 15:17:04 +0000280def COND_NULL : PatLeaf <
281 (cond),
Tom Stellardaa9a1a82014-08-01 02:05:57 +0000282 [{(void)N; return false;}]
Christian Konigb19849a2013-02-21 15:17:04 +0000283>;
284
Tom Stellardc5a154d2018-06-28 23:47:12 +0000285//===----------------------------------------------------------------------===//
286// PatLeafs for Texture Constants
287//===----------------------------------------------------------------------===//
288
289def TEX_ARRAY : PatLeaf<
290 (imm),
291 [{uint32_t TType = (uint32_t)N->getZExtValue();
292 return TType == 9 || TType == 10 || TType == 16;
293 }]
294>;
295
296def TEX_RECT : PatLeaf<
297 (imm),
298 [{uint32_t TType = (uint32_t)N->getZExtValue();
299 return TType == 5;
300 }]
301>;
302
303def TEX_SHADOW : PatLeaf<
304 (imm),
305 [{uint32_t TType = (uint32_t)N->getZExtValue();
306 return (TType >= 6 && TType <= 8) || TType == 13;
307 }]
308>;
309
310def TEX_SHADOW_ARRAY : PatLeaf<
311 (imm),
312 [{uint32_t TType = (uint32_t)N->getZExtValue();
313 return TType == 11 || TType == 12 || TType == 17;
314 }]
315>;
Matt Arsenaultc89f2912016-03-07 21:54:48 +0000316
317//===----------------------------------------------------------------------===//
Tom Stellard75aadc22012-12-11 21:25:42 +0000318// Load/Store Pattern Fragments
319//===----------------------------------------------------------------------===//
320
Matt Arsenaultbc683832017-09-20 03:43:35 +0000321class Aligned8Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{
322 return cast<MemSDNode>(N)->getAlignment() % 8 == 0;
323}]>;
324
Farhana Aleena7cb3112018-03-09 17:41:39 +0000325class Aligned16Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{
326 return cast<MemSDNode>(N)->getAlignment() >= 16;
327}]>;
328
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000329class LoadFrag <SDPatternOperator op> : PatFrag<(ops node:$ptr), (op node:$ptr)>;
Tom Stellardb02094e2014-07-21 15:45:01 +0000330
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000331class StoreFrag<SDPatternOperator op> : PatFrag <
Tom Stellardb02094e2014-07-21 15:45:01 +0000332 (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
333>;
334
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000335class StoreHi16<SDPatternOperator op> : PatFrag <
336 (ops node:$value, node:$ptr), (op (srl node:$value, (i32 16)), node:$ptr)
337>;
Tom Stellardb02094e2014-07-21 15:45:01 +0000338
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000339class PrivateAddress : CodePatPred<[{
Matt Arsenault0da63502018-08-31 05:49:54 +0000340 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000341}]>;
342
Matt Arsenaultbc683832017-09-20 03:43:35 +0000343class ConstantAddress : CodePatPred<[{
Matt Arsenault0da63502018-08-31 05:49:54 +0000344 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS;
Matt Arsenaultbc683832017-09-20 03:43:35 +0000345}]>;
346
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000347class LocalAddress : CodePatPred<[{
Matt Arsenault0da63502018-08-31 05:49:54 +0000348 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000349}]>;
350
351class GlobalAddress : CodePatPred<[{
Matt Arsenault0da63502018-08-31 05:49:54 +0000352 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000353}]>;
354
Matt Arsenaultb81495d2017-09-20 05:01:53 +0000355class GlobalLoadAddress : CodePatPred<[{
356 auto AS = cast<MemSDNode>(N)->getAddressSpace();
Matt Arsenault0da63502018-08-31 05:49:54 +0000357 return AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::CONSTANT_ADDRESS;
Matt Arsenaultb81495d2017-09-20 05:01:53 +0000358}]>;
359
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000360class FlatLoadAddress : CodePatPred<[{
361 const auto AS = cast<MemSDNode>(N)->getAddressSpace();
Matt Arsenault0da63502018-08-31 05:49:54 +0000362 return AS == AMDGPUAS::FLAT_ADDRESS ||
363 AS == AMDGPUAS::GLOBAL_ADDRESS ||
364 AS == AMDGPUAS::CONSTANT_ADDRESS;
Matt Arsenaultbc683832017-09-20 03:43:35 +0000365}]>;
366
367class FlatStoreAddress : CodePatPred<[{
368 const auto AS = cast<MemSDNode>(N)->getAddressSpace();
Matt Arsenault0da63502018-08-31 05:49:54 +0000369 return AS == AMDGPUAS::FLAT_ADDRESS ||
370 AS == AMDGPUAS::GLOBAL_ADDRESS;
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000371}]>;
372
Tom Stellard381a94a2015-05-12 15:00:49 +0000373class AZExtLoadBase <SDPatternOperator ld_node>: PatFrag<(ops node:$ptr),
374 (ld_node node:$ptr), [{
Tom Stellard31209cc2013-07-15 19:00:09 +0000375 LoadSDNode *L = cast<LoadSDNode>(N);
376 return L->getExtensionType() == ISD::ZEXTLOAD ||
377 L->getExtensionType() == ISD::EXTLOAD;
378}]>;
379
Tom Stellard381a94a2015-05-12 15:00:49 +0000380def az_extload : AZExtLoadBase <unindexedload>;
381
Tom Stellard33dd04b2013-07-23 01:47:52 +0000382def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
383 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
384}]>;
385
Tom Stellard33dd04b2013-07-23 01:47:52 +0000386def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
387 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
388}]>;
389
Tom Stellard31209cc2013-07-15 19:00:09 +0000390def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
391 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
392}]>;
393
Matt Arsenaultbc683832017-09-20 03:43:35 +0000394class PrivateLoad <SDPatternOperator op> : LoadFrag <op>, PrivateAddress;
395class PrivateStore <SDPatternOperator op> : StoreFrag <op>, PrivateAddress;
Tom Stellard31209cc2013-07-15 19:00:09 +0000396
Matt Arsenaultbc683832017-09-20 03:43:35 +0000397class LocalLoad <SDPatternOperator op> : LoadFrag <op>, LocalAddress;
398class LocalStore <SDPatternOperator op> : StoreFrag <op>, LocalAddress;
Matt Arsenault3f981402014-09-15 15:41:53 +0000399
Matt Arsenaultb81495d2017-09-20 05:01:53 +0000400class GlobalLoad <SDPatternOperator op> : LoadFrag<op>, GlobalLoadAddress;
Matt Arsenaultbc683832017-09-20 03:43:35 +0000401class GlobalStore <SDPatternOperator op> : StoreFrag<op>, GlobalAddress;
Tom Stellard31209cc2013-07-15 19:00:09 +0000402
Matt Arsenaultbc683832017-09-20 03:43:35 +0000403class FlatLoad <SDPatternOperator op> : LoadFrag <op>, FlatLoadAddress;
404class FlatStore <SDPatternOperator op> : StoreFrag <op>, FlatStoreAddress;
405
406class ConstantLoad <SDPatternOperator op> : LoadFrag <op>, ConstantAddress;
407
408
409def load_private : PrivateLoad <load>;
410def az_extloadi8_private : PrivateLoad <az_extloadi8>;
411def sextloadi8_private : PrivateLoad <sextloadi8>;
412def az_extloadi16_private : PrivateLoad <az_extloadi16>;
413def sextloadi16_private : PrivateLoad <sextloadi16>;
414
415def store_private : PrivateStore <store>;
416def truncstorei8_private : PrivateStore<truncstorei8>;
417def truncstorei16_private : PrivateStore <truncstorei16>;
418def store_hi16_private : StoreHi16 <truncstorei16>, PrivateAddress;
419def truncstorei8_hi16_private : StoreHi16<truncstorei8>, PrivateAddress;
420
421
422def load_global : GlobalLoad <load>;
423def sextloadi8_global : GlobalLoad <sextloadi8>;
424def az_extloadi8_global : GlobalLoad <az_extloadi8>;
425def sextloadi16_global : GlobalLoad <sextloadi16>;
426def az_extloadi16_global : GlobalLoad <az_extloadi16>;
427def atomic_load_global : GlobalLoad<atomic_load>;
428
429def store_global : GlobalStore <store>;
Tom Stellarda4b746d2016-07-05 16:10:44 +0000430def truncstorei8_global : GlobalStore <truncstorei8>;
431def truncstorei16_global : GlobalStore <truncstorei16>;
Matt Arsenaultbc683832017-09-20 03:43:35 +0000432def store_atomic_global : GlobalStore<atomic_store>;
433def truncstorei8_hi16_global : StoreHi16 <truncstorei8>, GlobalAddress;
434def truncstorei16_hi16_global : StoreHi16 <truncstorei16>, GlobalAddress;
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000435
Matt Arsenaultbc683832017-09-20 03:43:35 +0000436def load_local : LocalLoad <load>;
437def az_extloadi8_local : LocalLoad <az_extloadi8>;
438def sextloadi8_local : LocalLoad <sextloadi8>;
439def az_extloadi16_local : LocalLoad <az_extloadi16>;
440def sextloadi16_local : LocalLoad <sextloadi16>;
Matt Arsenault3f8e7a32018-06-22 08:39:52 +0000441def atomic_load_32_local : LocalLoad<atomic_load_32>;
442def atomic_load_64_local : LocalLoad<atomic_load_64>;
Matt Arsenaultfcc213f2017-09-20 03:20:09 +0000443
Matt Arsenaultbc683832017-09-20 03:43:35 +0000444def store_local : LocalStore <store>;
445def truncstorei8_local : LocalStore <truncstorei8>;
446def truncstorei16_local : LocalStore <truncstorei16>;
447def store_local_hi16 : StoreHi16 <truncstorei16>, LocalAddress;
448def truncstorei8_local_hi16 : StoreHi16<truncstorei8>, LocalAddress;
Matt Arsenault3f8e7a32018-06-22 08:39:52 +0000449def atomic_store_local : LocalStore <atomic_store>;
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000450
Matt Arsenaultbc683832017-09-20 03:43:35 +0000451def load_align8_local : Aligned8Bytes <
452 (ops node:$ptr), (load_local node:$ptr)
Tom Stellardf3fc5552014-08-22 18:49:35 +0000453>;
454
Farhana Aleena7cb3112018-03-09 17:41:39 +0000455def load_align16_local : Aligned16Bytes <
456 (ops node:$ptr), (load_local node:$ptr)
457>;
458
Matt Arsenaultbc683832017-09-20 03:43:35 +0000459def store_align8_local : Aligned8Bytes <
460 (ops node:$val, node:$ptr), (store_local node:$val, node:$ptr)
Tom Stellardf3fc5552014-08-22 18:49:35 +0000461>;
Matt Arsenault72574102014-06-11 18:08:34 +0000462
Farhana Aleenc6c9dc82018-03-16 18:12:00 +0000463def store_align16_local : Aligned16Bytes <
464 (ops node:$val, node:$ptr), (store_local node:$val, node:$ptr)
465>;
Matt Arsenaultbc683832017-09-20 03:43:35 +0000466
467def load_flat : FlatLoad <load>;
468def az_extloadi8_flat : FlatLoad <az_extloadi8>;
469def sextloadi8_flat : FlatLoad <sextloadi8>;
470def az_extloadi16_flat : FlatLoad <az_extloadi16>;
471def sextloadi16_flat : FlatLoad <sextloadi16>;
472def atomic_load_flat : FlatLoad<atomic_load>;
473
474def store_flat : FlatStore <store>;
475def truncstorei8_flat : FlatStore <truncstorei8>;
476def truncstorei16_flat : FlatStore <truncstorei16>;
477def atomic_store_flat : FlatStore <atomic_store>;
478def truncstorei8_hi16_flat : StoreHi16<truncstorei8>, FlatStoreAddress;
479def truncstorei16_hi16_flat : StoreHi16<truncstorei16>, FlatStoreAddress;
480
481
482def constant_load : ConstantLoad<load>;
483def sextloadi8_constant : ConstantLoad <sextloadi8>;
484def az_extloadi8_constant : ConstantLoad <az_extloadi8>;
485def sextloadi16_constant : ConstantLoad <sextloadi16>;
486def az_extloadi16_constant : ConstantLoad <az_extloadi16>;
487
488
Matt Arsenault72574102014-06-11 18:08:34 +0000489class local_binary_atomic_op<SDNode atomic_op> :
490 PatFrag<(ops node:$ptr, node:$value),
491 (atomic_op node:$ptr, node:$value), [{
Matt Arsenault0da63502018-08-31 05:49:54 +0000492 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
Tom Stellard13c68ef2013-09-05 18:38:09 +0000493}]>;
494
Matt Arsenault72574102014-06-11 18:08:34 +0000495def atomic_swap_local : local_binary_atomic_op<atomic_swap>;
496def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>;
497def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>;
498def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>;
499def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>;
500def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>;
501def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>;
502def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>;
503def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>;
504def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>;
505def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>;
Aaron Watry372cecf2013-09-06 20:17:42 +0000506
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000507def mskor_global : PatFrag<(ops node:$val, node:$ptr),
508 (AMDGPUstore_mskor node:$val, node:$ptr), [{
Matt Arsenault0da63502018-08-31 05:49:54 +0000509 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000510}]>;
511
Matt Arsenaulta030e262017-10-23 17:16:43 +0000512class AtomicCmpSwapLocal <SDNode cmp_swap_node> : PatFrag<
Tom Stellard381a94a2015-05-12 15:00:49 +0000513 (ops node:$ptr, node:$cmp, node:$swap),
514 (cmp_swap_node node:$ptr, node:$cmp, node:$swap), [{
515 AtomicSDNode *AN = cast<AtomicSDNode>(N);
Matt Arsenault0da63502018-08-31 05:49:54 +0000516 return AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
Matt Arsenaulta030e262017-10-23 17:16:43 +0000517}]>;
Matt Arsenaultc793e1d2014-06-11 18:08:48 +0000518
Matt Arsenaulta030e262017-10-23 17:16:43 +0000519def atomic_cmp_swap_local : AtomicCmpSwapLocal <atomic_cmp_swap>;
Matt Arsenaultcaa0ec22014-06-11 18:08:54 +0000520
Jan Vesely206a5102016-12-23 15:34:51 +0000521multiclass global_binary_atomic_op<SDNode atomic_op> {
522 def "" : PatFrag<
523 (ops node:$ptr, node:$value),
524 (atomic_op node:$ptr, node:$value),
Matt Arsenault0da63502018-08-31 05:49:54 +0000525 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;}]>;
Tom Stellard7980fc82014-09-25 18:30:26 +0000526
Jan Vesely206a5102016-12-23 15:34:51 +0000527 def _noret : PatFrag<
528 (ops node:$ptr, node:$value),
529 (atomic_op node:$ptr, node:$value),
Matt Arsenault0da63502018-08-31 05:49:54 +0000530 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS && (SDValue(N, 0).use_empty());}]>;
Tom Stellard7980fc82014-09-25 18:30:26 +0000531
Jan Vesely206a5102016-12-23 15:34:51 +0000532 def _ret : PatFrag<
533 (ops node:$ptr, node:$value),
534 (atomic_op node:$ptr, node:$value),
Matt Arsenault0da63502018-08-31 05:49:54 +0000535 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS && (!SDValue(N, 0).use_empty());}]>;
Jan Vesely206a5102016-12-23 15:34:51 +0000536}
537
538defm atomic_swap_global : global_binary_atomic_op<atomic_swap>;
539defm atomic_add_global : global_binary_atomic_op<atomic_load_add>;
540defm atomic_and_global : global_binary_atomic_op<atomic_load_and>;
541defm atomic_max_global : global_binary_atomic_op<atomic_load_max>;
542defm atomic_min_global : global_binary_atomic_op<atomic_load_min>;
543defm atomic_or_global : global_binary_atomic_op<atomic_load_or>;
544defm atomic_sub_global : global_binary_atomic_op<atomic_load_sub>;
545defm atomic_umax_global : global_binary_atomic_op<atomic_load_umax>;
546defm atomic_umin_global : global_binary_atomic_op<atomic_load_umin>;
547defm atomic_xor_global : global_binary_atomic_op<atomic_load_xor>;
548
Matt Arsenaultbc683832017-09-20 03:43:35 +0000549// Legacy.
Jan Vesely206a5102016-12-23 15:34:51 +0000550def AMDGPUatomic_cmp_swap_global : PatFrag<
Matt Arsenaultbc683832017-09-20 03:43:35 +0000551 (ops node:$ptr, node:$value),
552 (AMDGPUatomic_cmp_swap node:$ptr, node:$value)>, GlobalAddress;
Jan Vesely206a5102016-12-23 15:34:51 +0000553
554def atomic_cmp_swap_global : PatFrag<
Matt Arsenaultbc683832017-09-20 03:43:35 +0000555 (ops node:$ptr, node:$cmp, node:$value),
556 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value)>, GlobalAddress;
557
Jan Vesely206a5102016-12-23 15:34:51 +0000558
559def atomic_cmp_swap_global_noret : PatFrag<
Matt Arsenaultbc683832017-09-20 03:43:35 +0000560 (ops node:$ptr, node:$cmp, node:$value),
561 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value),
Matt Arsenault0da63502018-08-31 05:49:54 +0000562 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS && (SDValue(N, 0).use_empty());}]>;
Jan Vesely206a5102016-12-23 15:34:51 +0000563
564def atomic_cmp_swap_global_ret : PatFrag<
Matt Arsenaultbc683832017-09-20 03:43:35 +0000565 (ops node:$ptr, node:$cmp, node:$value),
566 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value),
Matt Arsenault0da63502018-08-31 05:49:54 +0000567 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS && (!SDValue(N, 0).use_empty());}]>;
Tom Stellard354a43c2016-04-01 18:27:37 +0000568
Tom Stellardb4a313a2014-08-01 00:32:39 +0000569//===----------------------------------------------------------------------===//
570// Misc Pattern Fragments
571//===----------------------------------------------------------------------===//
572
Tom Stellard75aadc22012-12-11 21:25:42 +0000573class Constants {
574int TWO_PI = 0x40c90fdb;
575int PI = 0x40490fdb;
576int TWO_PI_INV = 0x3e22f983;
NAKAMURA Takumi4bb85f92013-10-28 04:07:23 +0000577int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
Matt Arsenaultce841302016-12-22 03:05:37 +0000578int FP16_ONE = 0x3C00;
Matt Arsenaultde496c322018-07-30 12:16:58 +0000579int FP16_NEG_ONE = 0xBC00;
Matt Arsenaulteb522e62017-02-27 22:15:25 +0000580int V2FP16_ONE = 0x3C003C00;
Matt Arsenaultaeca2fa2014-05-31 06:47:42 +0000581int FP32_ONE = 0x3f800000;
Matt Arsenault7fb961f2016-07-22 17:01:21 +0000582int FP32_NEG_ONE = 0xbf800000;
Matt Arsenault9cd90712016-04-14 01:42:16 +0000583int FP64_ONE = 0x3ff0000000000000;
Matt Arsenault7fb961f2016-07-22 17:01:21 +0000584int FP64_NEG_ONE = 0xbff0000000000000;
Tom Stellard75aadc22012-12-11 21:25:42 +0000585}
586def CONST : Constants;
587
588def FP_ZERO : PatLeaf <
589 (fpimm),
590 [{return N->getValueAPF().isZero();}]
591>;
592
593def FP_ONE : PatLeaf <
594 (fpimm),
595 [{return N->isExactlyValue(1.0);}]
596>;
597
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000598def FP_HALF : PatLeaf <
599 (fpimm),
600 [{return N->isExactlyValue(0.5);}]
601>;
602
Tom Stellard75aadc22012-12-11 21:25:42 +0000603/* Generic helper patterns for intrinsics */
604/* -------------------------------------- */
605
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000606class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
Matt Arsenault90c75932017-10-03 00:06:41 +0000607 : AMDGPUPat <
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000608 (fpow f32:$src0, f32:$src1),
609 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
Tom Stellard75aadc22012-12-11 21:25:42 +0000610>;
611
612/* Other helper patterns */
613/* --------------------- */
614
615/* Extract element pattern */
Matt Arsenault530dde42014-02-26 23:00:58 +0000616class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000617 SubRegIndex sub_reg>
Matt Arsenault90c75932017-10-03 00:06:41 +0000618 : AMDGPUPat<
Matt Arsenaultfbd9bbf2015-12-11 19:20:16 +0000619 (sub_type (extractelt vec_type:$src, sub_idx)),
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000620 (EXTRACT_SUBREG $src, sub_reg)
Matt Arsenault90c75932017-10-03 00:06:41 +0000621> {
622 let SubtargetPredicate = TruePredicate;
623}
Tom Stellard75aadc22012-12-11 21:25:42 +0000624
625/* Insert element pattern */
626class Insert_Element <ValueType elem_type, ValueType vec_type,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000627 int sub_idx, SubRegIndex sub_reg>
Matt Arsenault90c75932017-10-03 00:06:41 +0000628 : AMDGPUPat <
Matt Arsenaultfbd9bbf2015-12-11 19:20:16 +0000629 (insertelt vec_type:$vec, elem_type:$elem, sub_idx),
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000630 (INSERT_SUBREG $vec, $elem, sub_reg)
Matt Arsenault90c75932017-10-03 00:06:41 +0000631> {
632 let SubtargetPredicate = TruePredicate;
633}
Tom Stellard75aadc22012-12-11 21:25:42 +0000634
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000635// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
636// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000637// bitconvert pattern
Matt Arsenault90c75932017-10-03 00:06:41 +0000638class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : AMDGPUPat <
Tom Stellard75aadc22012-12-11 21:25:42 +0000639 (dt (bitconvert (st rc:$src0))),
640 (dt rc:$src0)
641>;
642
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000643// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
644// can handle COPY instructions.
Matt Arsenault90c75932017-10-03 00:06:41 +0000645class DwordAddrPat<ValueType vt, RegisterClass rc> : AMDGPUPat <
Tom Stellard75aadc22012-12-11 21:25:42 +0000646 (vt (AMDGPUdwordaddr (vt rc:$addr))),
647 (vt rc:$addr)
648>;
649
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000650// BFI_INT patterns
651
Matt Arsenault7d858d82014-11-02 23:46:54 +0000652multiclass BFIPatterns <Instruction BFI_INT,
653 Instruction LoadImm32,
654 RegisterClass RC64> {
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000655 // Definition from ISA doc:
656 // (y & x) | (z & ~x)
Matt Arsenault90c75932017-10-03 00:06:41 +0000657 def : AMDGPUPat <
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000658 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
659 (BFI_INT $x, $y, $z)
660 >;
661
Matt Arsenaulta18b3bc2018-02-07 00:21:34 +0000662 // 64-bit version
663 def : AMDGPUPat <
664 (or (and i64:$y, i64:$x), (and i64:$z, (not i64:$x))),
665 (REG_SEQUENCE RC64,
666 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub0)),
667 (i32 (EXTRACT_SUBREG $y, sub0)),
668 (i32 (EXTRACT_SUBREG $z, sub0))), sub0,
669 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub1)),
670 (i32 (EXTRACT_SUBREG $y, sub1)),
671 (i32 (EXTRACT_SUBREG $z, sub1))), sub1)
672 >;
673
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000674 // SHA-256 Ch function
675 // z ^ (x & (y ^ z))
Matt Arsenault90c75932017-10-03 00:06:41 +0000676 def : AMDGPUPat <
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000677 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
678 (BFI_INT $x, $y, $z)
679 >;
680
Matt Arsenaulta18b3bc2018-02-07 00:21:34 +0000681 // 64-bit version
682 def : AMDGPUPat <
683 (xor i64:$z, (and i64:$x, (xor i64:$y, i64:$z))),
684 (REG_SEQUENCE RC64,
685 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub0)),
686 (i32 (EXTRACT_SUBREG $y, sub0)),
687 (i32 (EXTRACT_SUBREG $z, sub0))), sub0,
688 (BFI_INT (i32 (EXTRACT_SUBREG $x, sub1)),
689 (i32 (EXTRACT_SUBREG $y, sub1)),
690 (i32 (EXTRACT_SUBREG $z, sub1))), sub1)
691 >;
692
Matt Arsenault90c75932017-10-03 00:06:41 +0000693 def : AMDGPUPat <
Matt Arsenault6e439652014-06-10 19:00:20 +0000694 (fcopysign f32:$src0, f32:$src1),
Tom Stellard115a6152016-11-10 16:02:37 +0000695 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0, $src1)
Matt Arsenault6e439652014-06-10 19:00:20 +0000696 >;
697
Matt Arsenault90c75932017-10-03 00:06:41 +0000698 def : AMDGPUPat <
Konstantin Zhuravlyov7d882752017-01-13 19:49:25 +0000699 (f32 (fcopysign f32:$src0, f64:$src1)),
700 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0,
701 (i32 (EXTRACT_SUBREG $src1, sub1)))
702 >;
703
Matt Arsenault90c75932017-10-03 00:06:41 +0000704 def : AMDGPUPat <
Matt Arsenault6e439652014-06-10 19:00:20 +0000705 (f64 (fcopysign f64:$src0, f64:$src1)),
Matt Arsenault7d858d82014-11-02 23:46:54 +0000706 (REG_SEQUENCE RC64,
707 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
Tom Stellard115a6152016-11-10 16:02:37 +0000708 (BFI_INT (LoadImm32 (i32 0x7fffffff)),
Matt Arsenault6e439652014-06-10 19:00:20 +0000709 (i32 (EXTRACT_SUBREG $src0, sub1)),
710 (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
711 >;
Valery Pykhtine55fd412016-10-20 16:17:54 +0000712
Matt Arsenault90c75932017-10-03 00:06:41 +0000713 def : AMDGPUPat <
Valery Pykhtine55fd412016-10-20 16:17:54 +0000714 (f64 (fcopysign f64:$src0, f32:$src1)),
715 (REG_SEQUENCE RC64,
716 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
Tom Stellard115a6152016-11-10 16:02:37 +0000717 (BFI_INT (LoadImm32 (i32 0x7fffffff)),
Valery Pykhtine55fd412016-10-20 16:17:54 +0000718 (i32 (EXTRACT_SUBREG $src0, sub1)),
719 $src1), sub1)
720 >;
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000721}
722
Tom Stellardeac65dd2013-05-03 17:21:20 +0000723// SHA-256 Ma patterns
724
725// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
Matt Arsenaulta18b3bc2018-02-07 00:21:34 +0000726multiclass SHA256MaPattern <Instruction BFI_INT, Instruction XOR, RegisterClass RC64> {
727 def : AMDGPUPat <
728 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
729 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
730 >;
731
732 def : AMDGPUPat <
733 (or (and i64:$x, i64:$z), (and i64:$y, (or i64:$x, i64:$z))),
734 (REG_SEQUENCE RC64,
735 (BFI_INT (XOR (i32 (EXTRACT_SUBREG $x, sub0)),
736 (i32 (EXTRACT_SUBREG $y, sub0))),
737 (i32 (EXTRACT_SUBREG $z, sub0)),
738 (i32 (EXTRACT_SUBREG $y, sub0))), sub0,
739 (BFI_INT (XOR (i32 (EXTRACT_SUBREG $x, sub1)),
740 (i32 (EXTRACT_SUBREG $y, sub1))),
741 (i32 (EXTRACT_SUBREG $z, sub1)),
742 (i32 (EXTRACT_SUBREG $y, sub1))), sub1)
743 >;
744}
Tom Stellardeac65dd2013-05-03 17:21:20 +0000745
Tom Stellard2b971eb2013-05-10 02:09:45 +0000746// Bitfield extract patterns
747
Marek Olsak949f5da2015-03-24 13:40:34 +0000748def IMMZeroBasedBitfieldMask : PatLeaf <(imm), [{
749 return isMask_32(N->getZExtValue());
750}]>;
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000751
Marek Olsak949f5da2015-03-24 13:40:34 +0000752def IMMPopCount : SDNodeXForm<imm, [{
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000753 return CurDAG->getTargetConstant(countPopulation(N->getZExtValue()), SDLoc(N),
Marek Olsak949f5da2015-03-24 13:40:34 +0000754 MVT::i32);
755}]>;
Tom Stellarda2a4b8e2014-01-23 18:49:33 +0000756
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000757multiclass BFEPattern <Instruction UBFE, Instruction SBFE, Instruction MOV> {
Matt Arsenault90c75932017-10-03 00:06:41 +0000758 def : AMDGPUPat <
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000759 (i32 (and (i32 (srl i32:$src, i32:$rshift)), IMMZeroBasedBitfieldMask:$mask)),
760 (UBFE $src, $rshift, (MOV (i32 (IMMPopCount $mask))))
761 >;
762
Roman Lebedev9c17dad2018-06-15 09:56:39 +0000763 // x & ((1 << y) - 1)
764 def : AMDGPUPat <
765 (and i32:$src, (add_oneuse (shl_oneuse 1, i32:$width), -1)),
Jan Vesely6ff58ed2018-07-27 15:00:13 +0000766 (UBFE $src, (MOV (i32 0)), $width)
Roman Lebedev9c17dad2018-06-15 09:56:39 +0000767 >;
768
Roman Lebedevdec562c2018-06-15 09:56:45 +0000769 // x & ~(-1 << y)
770 def : AMDGPUPat <
771 (and i32:$src, (xor_oneuse (shl_oneuse -1, i32:$width), -1)),
Jan Vesely6ff58ed2018-07-27 15:00:13 +0000772 (UBFE $src, (MOV (i32 0)), $width)
Roman Lebedevdec562c2018-06-15 09:56:45 +0000773 >;
774
Roman Lebedevaa8587d2018-06-15 09:56:31 +0000775 // x & (-1 >> (bitwidth - y))
776 def : AMDGPUPat <
777 (and i32:$src, (srl_oneuse -1, (sub 32, i32:$width))),
Jan Vesely6ff58ed2018-07-27 15:00:13 +0000778 (UBFE $src, (MOV (i32 0)), $width)
Roman Lebedevaa8587d2018-06-15 09:56:31 +0000779 >;
780
781 // x << (bitwidth - y) >> (bitwidth - y)
Matt Arsenault90c75932017-10-03 00:06:41 +0000782 def : AMDGPUPat <
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000783 (srl (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)),
Jan Vesely6ff58ed2018-07-27 15:00:13 +0000784 (UBFE $src, (MOV (i32 0)), $width)
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000785 >;
786
Matt Arsenault90c75932017-10-03 00:06:41 +0000787 def : AMDGPUPat <
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000788 (sra (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)),
Jan Vesely6ff58ed2018-07-27 15:00:13 +0000789 (SBFE $src, (MOV (i32 0)), $width)
Matt Arsenaulta9e16e62017-02-23 00:23:43 +0000790 >;
791}
Tom Stellard2b971eb2013-05-10 02:09:45 +0000792
Tom Stellard5643c4a2013-05-20 15:02:19 +0000793// rotr pattern
Matt Arsenault90c75932017-10-03 00:06:41 +0000794class ROTRPattern <Instruction BIT_ALIGN> : AMDGPUPat <
Tom Stellard5643c4a2013-05-20 15:02:19 +0000795 (rotr i32:$src0, i32:$src1),
796 (BIT_ALIGN $src0, $src0, $src1)
797>;
798
Matt Arsenaultc89f2912016-03-07 21:54:48 +0000799// This matches 16 permutations of
800// max(min(x, y), min(max(x, y), z))
801class IntMed3Pat<Instruction med3Inst,
802 SDPatternOperator max,
803 SDPatternOperator max_oneuse,
Matt Arsenault10268f92017-02-27 22:40:39 +0000804 SDPatternOperator min_oneuse,
Matt Arsenault90c75932017-10-03 00:06:41 +0000805 ValueType vt = i32> : AMDGPUPat<
Matt Arsenault10268f92017-02-27 22:40:39 +0000806 (max (min_oneuse vt:$src0, vt:$src1),
807 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)),
Matt Arsenaultc89f2912016-03-07 21:54:48 +0000808 (med3Inst $src0, $src1, $src2)
809>;
810
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000811// Special conversion patterns
812
813def cvt_rpi_i32_f32 : PatFrag <
814 (ops node:$src),
Matt Arsenault08ad3282015-01-31 21:28:13 +0000815 (fp_to_sint (ffloor (fadd $src, FP_HALF))),
816 [{ (void) N; return TM.Options.NoNaNsFPMath; }]
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000817>;
818
819def cvt_flr_i32_f32 : PatFrag <
820 (ops node:$src),
Matt Arsenault08ad3282015-01-31 21:28:13 +0000821 (fp_to_sint (ffloor $src)),
822 [{ (void)N; return TM.Options.NoNaNsFPMath; }]
Matt Arsenaulteeb2a7e2015-01-15 23:58:35 +0000823>;
824
Matt Arsenault90c75932017-10-03 00:06:41 +0000825class IMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat <
Matt Arsenaulteb260202014-05-22 18:00:15 +0000826 (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000827 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)),
828 (Inst $src0, $src1, $src2))
Matt Arsenaulteb260202014-05-22 18:00:15 +0000829>;
830
Matt Arsenault90c75932017-10-03 00:06:41 +0000831class UMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat <
Matt Arsenaulteb260202014-05-22 18:00:15 +0000832 (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000833 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)),
834 (Inst $src0, $src1, $src2))
Matt Arsenaulteb260202014-05-22 18:00:15 +0000835>;
836
Matt Arsenault90c75932017-10-03 00:06:41 +0000837class RcpPat<Instruction RcpInst, ValueType vt> : AMDGPUPat <
Matt Arsenaulta0050b02014-06-19 01:19:19 +0000838 (fdiv FP_ONE, vt:$src),
839 (RcpInst $src)
840>;
841
Matt Arsenault90c75932017-10-03 00:06:41 +0000842class RsqPat<Instruction RsqInst, ValueType vt> : AMDGPUPat <
Matt Arsenault0bbcd8b2015-02-14 04:30:08 +0000843 (AMDGPUrcp (fsqrt vt:$src)),
844 (RsqInst $src)
845>;
Matt Arsenault687ec752018-10-22 16:27:27 +0000846
847// Instructions which select to the same v_min_f*
848def fminnum_like : PatFrags<(ops node:$src0, node:$src1),
849 [(fminnum_ieee node:$src0, node:$src1),
850 (fminnum node:$src0, node:$src1)]
851>;
852
853// Instructions which select to the same v_max_f*
854def fmaxnum_like : PatFrags<(ops node:$src0, node:$src1),
855 [(fmaxnum_ieee node:$src0, node:$src1),
856 (fmaxnum node:$src0, node:$src1)]
857>;
858
859def fminnum_like_oneuse : PatFrags<(ops node:$src0, node:$src1),
860 [(fminnum_ieee_oneuse node:$src0, node:$src1),
861 (fminnum_oneuse node:$src0, node:$src1)]
862>;
863
864def fmaxnum_like_oneuse : PatFrags<(ops node:$src0, node:$src1),
865 [(fmaxnum_ieee_oneuse node:$src0, node:$src1),
866 (fmaxnum_oneuse node:$src0, node:$src1)]
867>;