1//===-- AMDGPUInstructions.td - Common instruction defs ---*- tablegen -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file contains instruction defs that are common to all hw codegen 11// targets. 12// 13//===----------------------------------------------------------------------===// 14 15class AMDGPUInst <dag outs, dag ins, string asm = "", 16 list<dag> pattern = []> : Instruction { 17 field bit isRegisterLoad = 0; 18 field bit isRegisterStore = 0; 19 20 let Namespace = "AMDGPU"; 21 let OutOperandList = outs; 22 let InOperandList = ins; 23 let AsmString = asm; 24 let Pattern = pattern; 25 let Itinerary = NullALU; 26 27 // 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; 34 35 let TSFlags{63} = isRegisterLoad; 36 let TSFlags{62} = isRegisterStore; 37} 38 39class AMDGPUShaderInst <dag outs, dag ins, string asm = "", 40 list<dag> pattern = []> : AMDGPUInst<outs, ins, asm, pattern> { 41 42 field bits<32> Inst = 0xffffffff; 43} 44 45def FP16Denormals : Predicate<"Subtarget->hasFP16Denormals()">; 46def FP32Denormals : Predicate<"Subtarget->hasFP32Denormals()">; 47def FP64Denormals : Predicate<"Subtarget->hasFP64Denormals()">; 48def NoFP16Denormals : Predicate<"!Subtarget->hasFP16Denormals()">; 49def NoFP32Denormals : Predicate<"!Subtarget->hasFP32Denormals()">; 50def NoFP64Denormals : Predicate<"!Subtarget->hasFP64Denormals()">; 51def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">; 52 53def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>; 54def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>; 55 56def u16ImmTarget : AsmOperandClass { 57 let Name = "U16Imm"; 58 let RenderMethod = "addImmOperands"; 59} 60 61def s16ImmTarget : AsmOperandClass { 62 let Name = "S16Imm"; 63 let RenderMethod = "addImmOperands"; 64} 65 66let OperandType = "OPERAND_IMMEDIATE" in { 67 68def u32imm : Operand<i32> { 69 let PrintMethod = "printU32ImmOperand"; 70} 71 72def u16imm : Operand<i16> { 73 let PrintMethod = "printU16ImmOperand"; 74 let ParserMatchClass = u16ImmTarget; 75} 76 77def s16imm : Operand<i16> { 78 let PrintMethod = "printU16ImmOperand"; 79 let ParserMatchClass = s16ImmTarget; 80} 81 82def u8imm : Operand<i8> { 83 let PrintMethod = "printU8ImmOperand"; 84} 85 86} // End OperandType = "OPERAND_IMMEDIATE" 87 88//===--------------------------------------------------------------------===// 89// Custom Operands 90//===--------------------------------------------------------------------===// 91def brtarget : Operand<OtherVT>; 92 93//===----------------------------------------------------------------------===// 94// Misc. PatFrags 95//===----------------------------------------------------------------------===// 96 97class HasOneUseUnaryOp<SDPatternOperator op> : PatFrag< 98 (ops node:$src0), 99 (op $src0), 100 [{ return N->hasOneUse(); }] 101>; 102 103class HasOneUseBinOp<SDPatternOperator op> : PatFrag< 104 (ops node:$src0, node:$src1), 105 (op $src0, $src1), 106 [{ return N->hasOneUse(); }] 107>; 108 109class HasOneUseTernaryOp<SDPatternOperator op> : PatFrag< 110 (ops node:$src0, node:$src1, node:$src2), 111 (op $src0, $src1, $src2), 112 [{ return N->hasOneUse(); }] 113>; 114 115def trunc_oneuse : HasOneUseUnaryOp<trunc>; 116 117let Properties = [SDNPCommutative, SDNPAssociative] in { 118def smax_oneuse : HasOneUseBinOp<smax>; 119def smin_oneuse : HasOneUseBinOp<smin>; 120def umax_oneuse : HasOneUseBinOp<umax>; 121def umin_oneuse : HasOneUseBinOp<umin>; 122def fminnum_oneuse : HasOneUseBinOp<fminnum>; 123def fmaxnum_oneuse : HasOneUseBinOp<fmaxnum>; 124def and_oneuse : HasOneUseBinOp<and>; 125def or_oneuse : HasOneUseBinOp<or>; 126def xor_oneuse : HasOneUseBinOp<xor>; 127} // Properties = [SDNPCommutative, SDNPAssociative] 128 129def sub_oneuse : HasOneUseBinOp<sub>; 130 131def srl_oneuse : HasOneUseBinOp<srl>; 132def shl_oneuse : HasOneUseBinOp<shl>; 133 134def select_oneuse : HasOneUseTernaryOp<select>; 135 136//===----------------------------------------------------------------------===// 137// PatLeafs for floating-point comparisons 138//===----------------------------------------------------------------------===// 139 140def COND_OEQ : PatLeaf < 141 (cond), 142 [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}] 143>; 144 145def COND_ONE : PatLeaf < 146 (cond), 147 [{return N->get() == ISD::SETONE || N->get() == ISD::SETNE;}] 148>; 149 150def COND_OGT : PatLeaf < 151 (cond), 152 [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}] 153>; 154 155def COND_OGE : PatLeaf < 156 (cond), 157 [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}] 158>; 159 160def COND_OLT : PatLeaf < 161 (cond), 162 [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}] 163>; 164 165def COND_OLE : PatLeaf < 166 (cond), 167 [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}] 168>; 169 170 171def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>; 172def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>; 173 174//===----------------------------------------------------------------------===// 175// PatLeafs for unsigned / unordered comparisons 176//===----------------------------------------------------------------------===// 177 178def COND_UEQ : PatLeaf <(cond), [{return N->get() == ISD::SETUEQ;}]>; 179def COND_UNE : PatLeaf <(cond), [{return N->get() == ISD::SETUNE;}]>; 180def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>; 181def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>; 182def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>; 183def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>; 184 185// XXX - For some reason R600 version is preferring to use unordered 186// for setne? 187def COND_UNE_NE : PatLeaf < 188 (cond), 189 [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}] 190>; 191 192//===----------------------------------------------------------------------===// 193// PatLeafs for signed comparisons 194//===----------------------------------------------------------------------===// 195 196def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>; 197def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>; 198def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>; 199def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>; 200 201//===----------------------------------------------------------------------===// 202// PatLeafs for integer equality 203//===----------------------------------------------------------------------===// 204 205def COND_EQ : PatLeaf < 206 (cond), 207 [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}] 208>; 209 210def COND_NE : PatLeaf < 211 (cond), 212 [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}] 213>; 214 215def COND_NULL : PatLeaf < 216 (cond), 217 [{(void)N; return false;}] 218>; 219 220 221//===----------------------------------------------------------------------===// 222// Load/Store Pattern Fragments 223//===----------------------------------------------------------------------===// 224 225class Aligned8Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{ 226 return cast<MemSDNode>(N)->getAlignment() % 8 == 0; 227}]>; 228 229class LoadFrag <SDPatternOperator op> : PatFrag<(ops node:$ptr), (op node:$ptr)>; 230 231class StoreFrag<SDPatternOperator op> : PatFrag < 232 (ops node:$value, node:$ptr), (op node:$value, node:$ptr) 233>; 234 235class StoreHi16<SDPatternOperator op> : PatFrag < 236 (ops node:$value, node:$ptr), (op (srl node:$value, (i32 16)), node:$ptr) 237>; 238 239class PrivateAddress : CodePatPred<[{ 240 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.PRIVATE_ADDRESS; 241}]>; 242 243class ConstantAddress : CodePatPred<[{ 244 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.CONSTANT_ADDRESS; 245}]>; 246 247class LocalAddress : CodePatPred<[{ 248 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS; 249}]>; 250 251class GlobalAddress : CodePatPred<[{ 252 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS; 253}]>; 254 255class GlobalLoadAddress : CodePatPred<[{ 256 auto AS = cast<MemSDNode>(N)->getAddressSpace(); 257 return AS == AMDGPUASI.GLOBAL_ADDRESS || AS == AMDGPUASI.CONSTANT_ADDRESS; 258}]>; 259 260class FlatLoadAddress : CodePatPred<[{ 261 const auto AS = cast<MemSDNode>(N)->getAddressSpace(); 262 return AS == AMDGPUASI.FLAT_ADDRESS || 263 AS == AMDGPUASI.GLOBAL_ADDRESS || 264 AS == AMDGPUASI.CONSTANT_ADDRESS; 265}]>; 266 267class FlatStoreAddress : CodePatPred<[{ 268 const auto AS = cast<MemSDNode>(N)->getAddressSpace(); 269 return AS == AMDGPUASI.FLAT_ADDRESS || 270 AS == AMDGPUASI.GLOBAL_ADDRESS; 271}]>; 272 273class AZExtLoadBase <SDPatternOperator ld_node>: PatFrag<(ops node:$ptr), 274 (ld_node node:$ptr), [{ 275 LoadSDNode *L = cast<LoadSDNode>(N); 276 return L->getExtensionType() == ISD::ZEXTLOAD || 277 L->getExtensionType() == ISD::EXTLOAD; 278}]>; 279 280def az_extload : AZExtLoadBase <unindexedload>; 281 282def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{ 283 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8; 284}]>; 285 286def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{ 287 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16; 288}]>; 289 290def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{ 291 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32; 292}]>; 293 294class PrivateLoad <SDPatternOperator op> : LoadFrag <op>, PrivateAddress; 295class PrivateStore <SDPatternOperator op> : StoreFrag <op>, PrivateAddress; 296 297class LocalLoad <SDPatternOperator op> : LoadFrag <op>, LocalAddress; 298class LocalStore <SDPatternOperator op> : StoreFrag <op>, LocalAddress; 299 300class GlobalLoad <SDPatternOperator op> : LoadFrag<op>, GlobalLoadAddress; 301class GlobalStore <SDPatternOperator op> : StoreFrag<op>, GlobalAddress; 302 303class FlatLoad <SDPatternOperator op> : LoadFrag <op>, FlatLoadAddress; 304class FlatStore <SDPatternOperator op> : StoreFrag <op>, FlatStoreAddress; 305 306class ConstantLoad <SDPatternOperator op> : LoadFrag <op>, ConstantAddress; 307 308 309def load_private : PrivateLoad <load>; 310def az_extloadi8_private : PrivateLoad <az_extloadi8>; 311def sextloadi8_private : PrivateLoad <sextloadi8>; 312def az_extloadi16_private : PrivateLoad <az_extloadi16>; 313def sextloadi16_private : PrivateLoad <sextloadi16>; 314 315def store_private : PrivateStore <store>; 316def truncstorei8_private : PrivateStore<truncstorei8>; 317def truncstorei16_private : PrivateStore <truncstorei16>; 318def store_hi16_private : StoreHi16 <truncstorei16>, PrivateAddress; 319def truncstorei8_hi16_private : StoreHi16<truncstorei8>, PrivateAddress; 320 321 322def load_global : GlobalLoad <load>; 323def sextloadi8_global : GlobalLoad <sextloadi8>; 324def az_extloadi8_global : GlobalLoad <az_extloadi8>; 325def sextloadi16_global : GlobalLoad <sextloadi16>; 326def az_extloadi16_global : GlobalLoad <az_extloadi16>; 327def atomic_load_global : GlobalLoad<atomic_load>; 328 329def store_global : GlobalStore <store>; 330def truncstorei8_global : GlobalStore <truncstorei8>; 331def truncstorei16_global : GlobalStore <truncstorei16>; 332def store_atomic_global : GlobalStore<atomic_store>; 333def truncstorei8_hi16_global : StoreHi16 <truncstorei8>, GlobalAddress; 334def truncstorei16_hi16_global : StoreHi16 <truncstorei16>, GlobalAddress; 335 336def load_local : LocalLoad <load>; 337def az_extloadi8_local : LocalLoad <az_extloadi8>; 338def sextloadi8_local : LocalLoad <sextloadi8>; 339def az_extloadi16_local : LocalLoad <az_extloadi16>; 340def sextloadi16_local : LocalLoad <sextloadi16>; 341 342def store_local : LocalStore <store>; 343def truncstorei8_local : LocalStore <truncstorei8>; 344def truncstorei16_local : LocalStore <truncstorei16>; 345def store_local_hi16 : StoreHi16 <truncstorei16>, LocalAddress; 346def truncstorei8_local_hi16 : StoreHi16<truncstorei8>, LocalAddress; 347 348def load_align8_local : Aligned8Bytes < 349 (ops node:$ptr), (load_local node:$ptr) 350>; 351 352def store_align8_local : Aligned8Bytes < 353 (ops node:$val, node:$ptr), (store_local node:$val, node:$ptr) 354>; 355 356 357def load_flat : FlatLoad <load>; 358def az_extloadi8_flat : FlatLoad <az_extloadi8>; 359def sextloadi8_flat : FlatLoad <sextloadi8>; 360def az_extloadi16_flat : FlatLoad <az_extloadi16>; 361def sextloadi16_flat : FlatLoad <sextloadi16>; 362def atomic_load_flat : FlatLoad<atomic_load>; 363 364def store_flat : FlatStore <store>; 365def truncstorei8_flat : FlatStore <truncstorei8>; 366def truncstorei16_flat : FlatStore <truncstorei16>; 367def atomic_store_flat : FlatStore <atomic_store>; 368def truncstorei8_hi16_flat : StoreHi16<truncstorei8>, FlatStoreAddress; 369def truncstorei16_hi16_flat : StoreHi16<truncstorei16>, FlatStoreAddress; 370 371 372def constant_load : ConstantLoad<load>; 373def sextloadi8_constant : ConstantLoad <sextloadi8>; 374def az_extloadi8_constant : ConstantLoad <az_extloadi8>; 375def sextloadi16_constant : ConstantLoad <sextloadi16>; 376def az_extloadi16_constant : ConstantLoad <az_extloadi16>; 377 378 379class local_binary_atomic_op<SDNode atomic_op> : 380 PatFrag<(ops node:$ptr, node:$value), 381 (atomic_op node:$ptr, node:$value), [{ 382 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS; 383}]>; 384 385def atomic_swap_local : local_binary_atomic_op<atomic_swap>; 386def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>; 387def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>; 388def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>; 389def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>; 390def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>; 391def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>; 392def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>; 393def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>; 394def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>; 395def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>; 396 397def mskor_global : PatFrag<(ops node:$val, node:$ptr), 398 (AMDGPUstore_mskor node:$val, node:$ptr), [{ 399 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS; 400}]>; 401 402multiclass AtomicCmpSwapLocal <SDNode cmp_swap_node> { 403 404 def _32_local : PatFrag < 405 (ops node:$ptr, node:$cmp, node:$swap), 406 (cmp_swap_node node:$ptr, node:$cmp, node:$swap), [{ 407 AtomicSDNode *AN = cast<AtomicSDNode>(N); 408 return AN->getMemoryVT() == MVT::i32 && 409 AN->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS; 410 }]>; 411 412 def _64_local : PatFrag< 413 (ops node:$ptr, node:$cmp, node:$swap), 414 (cmp_swap_node node:$ptr, node:$cmp, node:$swap), [{ 415 AtomicSDNode *AN = cast<AtomicSDNode>(N); 416 return AN->getMemoryVT() == MVT::i64 && 417 AN->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS; 418 }]>; 419} 420 421defm atomic_cmp_swap : AtomicCmpSwapLocal <atomic_cmp_swap>; 422 423multiclass global_binary_atomic_op<SDNode atomic_op> { 424 def "" : PatFrag< 425 (ops node:$ptr, node:$value), 426 (atomic_op node:$ptr, node:$value), 427 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS;}]>; 428 429 def _noret : PatFrag< 430 (ops node:$ptr, node:$value), 431 (atomic_op node:$ptr, node:$value), 432 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (SDValue(N, 0).use_empty());}]>; 433 434 def _ret : PatFrag< 435 (ops node:$ptr, node:$value), 436 (atomic_op node:$ptr, node:$value), 437 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (!SDValue(N, 0).use_empty());}]>; 438} 439 440defm atomic_swap_global : global_binary_atomic_op<atomic_swap>; 441defm atomic_add_global : global_binary_atomic_op<atomic_load_add>; 442defm atomic_and_global : global_binary_atomic_op<atomic_load_and>; 443defm atomic_max_global : global_binary_atomic_op<atomic_load_max>; 444defm atomic_min_global : global_binary_atomic_op<atomic_load_min>; 445defm atomic_or_global : global_binary_atomic_op<atomic_load_or>; 446defm atomic_sub_global : global_binary_atomic_op<atomic_load_sub>; 447defm atomic_umax_global : global_binary_atomic_op<atomic_load_umax>; 448defm atomic_umin_global : global_binary_atomic_op<atomic_load_umin>; 449defm atomic_xor_global : global_binary_atomic_op<atomic_load_xor>; 450 451// Legacy. 452def AMDGPUatomic_cmp_swap_global : PatFrag< 453 (ops node:$ptr, node:$value), 454 (AMDGPUatomic_cmp_swap node:$ptr, node:$value)>, GlobalAddress; 455 456def atomic_cmp_swap_global : PatFrag< 457 (ops node:$ptr, node:$cmp, node:$value), 458 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value)>, GlobalAddress; 459 460 461def atomic_cmp_swap_global_noret : PatFrag< 462 (ops node:$ptr, node:$cmp, node:$value), 463 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value), 464 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (SDValue(N, 0).use_empty());}]>; 465 466def atomic_cmp_swap_global_ret : PatFrag< 467 (ops node:$ptr, node:$cmp, node:$value), 468 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value), 469 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (!SDValue(N, 0).use_empty());}]>; 470 471//===----------------------------------------------------------------------===// 472// Misc Pattern Fragments 473//===----------------------------------------------------------------------===// 474 475class Constants { 476int TWO_PI = 0x40c90fdb; 477int PI = 0x40490fdb; 478int TWO_PI_INV = 0x3e22f983; 479int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding 480int FP16_ONE = 0x3C00; 481int V2FP16_ONE = 0x3C003C00; 482int FP32_ONE = 0x3f800000; 483int FP32_NEG_ONE = 0xbf800000; 484int FP64_ONE = 0x3ff0000000000000; 485int FP64_NEG_ONE = 0xbff0000000000000; 486} 487def CONST : Constants; 488 489def FP_ZERO : PatLeaf < 490 (fpimm), 491 [{return N->getValueAPF().isZero();}] 492>; 493 494def FP_ONE : PatLeaf < 495 (fpimm), 496 [{return N->isExactlyValue(1.0);}] 497>; 498 499def FP_HALF : PatLeaf < 500 (fpimm), 501 [{return N->isExactlyValue(0.5);}] 502>; 503 504/* Generic helper patterns for intrinsics */ 505/* -------------------------------------- */ 506 507class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul> 508 : AMDGPUPat < 509 (fpow f32:$src0, f32:$src1), 510 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0))) 511>; 512 513/* Other helper patterns */ 514/* --------------------- */ 515 516/* Extract element pattern */ 517class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx, 518 SubRegIndex sub_reg> 519 : AMDGPUPat< 520 (sub_type (extractelt vec_type:$src, sub_idx)), 521 (EXTRACT_SUBREG $src, sub_reg) 522> { 523 let SubtargetPredicate = TruePredicate; 524} 525 526/* Insert element pattern */ 527class Insert_Element <ValueType elem_type, ValueType vec_type, 528 int sub_idx, SubRegIndex sub_reg> 529 : AMDGPUPat < 530 (insertelt vec_type:$vec, elem_type:$elem, sub_idx), 531 (INSERT_SUBREG $vec, $elem, sub_reg) 532> { 533 let SubtargetPredicate = TruePredicate; 534} 535 536// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer 537// can handle COPY instructions. 538// bitconvert pattern 539class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : AMDGPUPat < 540 (dt (bitconvert (st rc:$src0))), 541 (dt rc:$src0) 542>; 543 544// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer 545// can handle COPY instructions. 546class DwordAddrPat<ValueType vt, RegisterClass rc> : AMDGPUPat < 547 (vt (AMDGPUdwordaddr (vt rc:$addr))), 548 (vt rc:$addr) 549>; 550 551// BFI_INT patterns 552 553multiclass BFIPatterns <Instruction BFI_INT, 554 Instruction LoadImm32, 555 RegisterClass RC64> { 556 // Definition from ISA doc: 557 // (y & x) | (z & ~x) 558 def : AMDGPUPat < 559 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))), 560 (BFI_INT $x, $y, $z) 561 >; 562 563 // SHA-256 Ch function 564 // z ^ (x & (y ^ z)) 565 def : AMDGPUPat < 566 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))), 567 (BFI_INT $x, $y, $z) 568 >; 569 570 def : AMDGPUPat < 571 (fcopysign f32:$src0, f32:$src1), 572 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0, $src1) 573 >; 574 575 def : AMDGPUPat < 576 (f32 (fcopysign f32:$src0, f64:$src1)), 577 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0, 578 (i32 (EXTRACT_SUBREG $src1, sub1))) 579 >; 580 581 def : AMDGPUPat < 582 (f64 (fcopysign f64:$src0, f64:$src1)), 583 (REG_SEQUENCE RC64, 584 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0, 585 (BFI_INT (LoadImm32 (i32 0x7fffffff)), 586 (i32 (EXTRACT_SUBREG $src0, sub1)), 587 (i32 (EXTRACT_SUBREG $src1, sub1))), sub1) 588 >; 589 590 def : AMDGPUPat < 591 (f64 (fcopysign f64:$src0, f32:$src1)), 592 (REG_SEQUENCE RC64, 593 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0, 594 (BFI_INT (LoadImm32 (i32 0x7fffffff)), 595 (i32 (EXTRACT_SUBREG $src0, sub1)), 596 $src1), sub1) 597 >; 598} 599 600// SHA-256 Ma patterns 601 602// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y 603class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : AMDGPUPat < 604 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))), 605 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y) 606>; 607 608// Bitfield extract patterns 609 610def IMMZeroBasedBitfieldMask : PatLeaf <(imm), [{ 611 return isMask_32(N->getZExtValue()); 612}]>; 613 614def IMMPopCount : SDNodeXForm<imm, [{ 615 return CurDAG->getTargetConstant(countPopulation(N->getZExtValue()), SDLoc(N), 616 MVT::i32); 617}]>; 618 619multiclass BFEPattern <Instruction UBFE, Instruction SBFE, Instruction MOV> { 620 def : AMDGPUPat < 621 (i32 (and (i32 (srl i32:$src, i32:$rshift)), IMMZeroBasedBitfieldMask:$mask)), 622 (UBFE $src, $rshift, (MOV (i32 (IMMPopCount $mask)))) 623 >; 624 625 def : AMDGPUPat < 626 (srl (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)), 627 (UBFE $src, (i32 0), $width) 628 >; 629 630 def : AMDGPUPat < 631 (sra (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)), 632 (SBFE $src, (i32 0), $width) 633 >; 634} 635 636// rotr pattern 637class ROTRPattern <Instruction BIT_ALIGN> : AMDGPUPat < 638 (rotr i32:$src0, i32:$src1), 639 (BIT_ALIGN $src0, $src0, $src1) 640>; 641 642// This matches 16 permutations of 643// max(min(x, y), min(max(x, y), z)) 644class IntMed3Pat<Instruction med3Inst, 645 SDPatternOperator max, 646 SDPatternOperator max_oneuse, 647 SDPatternOperator min_oneuse, 648 ValueType vt = i32> : AMDGPUPat< 649 (max (min_oneuse vt:$src0, vt:$src1), 650 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)), 651 (med3Inst $src0, $src1, $src2) 652>; 653 654// Special conversion patterns 655 656def cvt_rpi_i32_f32 : PatFrag < 657 (ops node:$src), 658 (fp_to_sint (ffloor (fadd $src, FP_HALF))), 659 [{ (void) N; return TM.Options.NoNaNsFPMath; }] 660>; 661 662def cvt_flr_i32_f32 : PatFrag < 663 (ops node:$src), 664 (fp_to_sint (ffloor $src)), 665 [{ (void)N; return TM.Options.NoNaNsFPMath; }] 666>; 667 668class IMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat < 669 (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2), 670 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)), 671 (Inst $src0, $src1, $src2)) 672>; 673 674class UMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat < 675 (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2), 676 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)), 677 (Inst $src0, $src1, $src2)) 678>; 679 680class RcpPat<Instruction RcpInst, ValueType vt> : AMDGPUPat < 681 (fdiv FP_ONE, vt:$src), 682 (RcpInst $src) 683>; 684 685class RsqPat<Instruction RsqInst, ValueType vt> : AMDGPUPat < 686 (AMDGPUrcp (fsqrt vt:$src)), 687 (RsqInst $src) 688>; 689 690include "R600Instructions.td" 691include "R700Instructions.td" 692include "EvergreenInstructions.td" 693include "CaymanInstructions.td" 694 695include "SIInstrInfo.td" 696 697