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 170def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>; 171def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>; 172 173//===----------------------------------------------------------------------===// 174// PatLeafs for unsigned / unordered comparisons 175//===----------------------------------------------------------------------===// 176 177def COND_UEQ : PatLeaf <(cond), [{return N->get() == ISD::SETUEQ;}]>; 178def COND_UNE : PatLeaf <(cond), [{return N->get() == ISD::SETUNE;}]>; 179def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>; 180def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>; 181def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>; 182def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>; 183 184// XXX - For some reason R600 version is preferring to use unordered 185// for setne? 186def COND_UNE_NE : PatLeaf < 187 (cond), 188 [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}] 189>; 190 191//===----------------------------------------------------------------------===// 192// PatLeafs for signed comparisons 193//===----------------------------------------------------------------------===// 194 195def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>; 196def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>; 197def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>; 198def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>; 199 200//===----------------------------------------------------------------------===// 201// PatLeafs for integer equality 202//===----------------------------------------------------------------------===// 203 204def COND_EQ : PatLeaf < 205 (cond), 206 [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}] 207>; 208 209def COND_NE : PatLeaf < 210 (cond), 211 [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}] 212>; 213 214def COND_NULL : PatLeaf < 215 (cond), 216 [{(void)N; return false;}] 217>; 218 219 220//===----------------------------------------------------------------------===// 221// Load/Store Pattern Fragments 222//===----------------------------------------------------------------------===// 223 224class Aligned8Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{ 225 return cast<MemSDNode>(N)->getAlignment() % 8 == 0; 226}]>; 227 228class LoadFrag <SDPatternOperator op> : PatFrag<(ops node:$ptr), (op node:$ptr)>; 229 230class StoreFrag<SDPatternOperator op> : PatFrag < 231 (ops node:$value, node:$ptr), (op node:$value, node:$ptr) 232>; 233 234class StoreHi16<SDPatternOperator op> : PatFrag < 235 (ops node:$value, node:$ptr), (op (srl node:$value, (i32 16)), node:$ptr) 236>; 237 238class PrivateAddress : CodePatPred<[{ 239 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.PRIVATE_ADDRESS; 240}]>; 241 242class ConstantAddress : CodePatPred<[{ 243 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.CONSTANT_ADDRESS; 244}]>; 245 246class LocalAddress : CodePatPred<[{ 247 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS; 248}]>; 249 250class GlobalAddress : CodePatPred<[{ 251 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS; 252}]>; 253 254class GlobalLoadAddress : CodePatPred<[{ 255 auto AS = cast<MemSDNode>(N)->getAddressSpace(); 256 return AS == AMDGPUASI.GLOBAL_ADDRESS || AS == AMDGPUASI.CONSTANT_ADDRESS; 257}]>; 258 259class FlatLoadAddress : CodePatPred<[{ 260 const auto AS = cast<MemSDNode>(N)->getAddressSpace(); 261 return AS == AMDGPUASI.FLAT_ADDRESS || 262 AS == AMDGPUASI.GLOBAL_ADDRESS || 263 AS == AMDGPUASI.CONSTANT_ADDRESS; 264}]>; 265 266class FlatStoreAddress : CodePatPred<[{ 267 const auto AS = cast<MemSDNode>(N)->getAddressSpace(); 268 return AS == AMDGPUASI.FLAT_ADDRESS || 269 AS == AMDGPUASI.GLOBAL_ADDRESS; 270}]>; 271 272class AZExtLoadBase <SDPatternOperator ld_node>: PatFrag<(ops node:$ptr), 273 (ld_node node:$ptr), [{ 274 LoadSDNode *L = cast<LoadSDNode>(N); 275 return L->getExtensionType() == ISD::ZEXTLOAD || 276 L->getExtensionType() == ISD::EXTLOAD; 277}]>; 278 279def az_extload : AZExtLoadBase <unindexedload>; 280 281def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{ 282 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8; 283}]>; 284 285def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{ 286 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16; 287}]>; 288 289def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{ 290 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32; 291}]>; 292 293class PrivateLoad <SDPatternOperator op> : LoadFrag <op>, PrivateAddress; 294class PrivateStore <SDPatternOperator op> : StoreFrag <op>, PrivateAddress; 295 296class LocalLoad <SDPatternOperator op> : LoadFrag <op>, LocalAddress; 297class LocalStore <SDPatternOperator op> : StoreFrag <op>, LocalAddress; 298 299class GlobalLoad <SDPatternOperator op> : LoadFrag<op>, GlobalLoadAddress; 300class GlobalStore <SDPatternOperator op> : StoreFrag<op>, GlobalAddress; 301 302class FlatLoad <SDPatternOperator op> : LoadFrag <op>, FlatLoadAddress; 303class FlatStore <SDPatternOperator op> : StoreFrag <op>, FlatStoreAddress; 304 305class ConstantLoad <SDPatternOperator op> : LoadFrag <op>, ConstantAddress; 306 307 308def load_private : PrivateLoad <load>; 309def az_extloadi8_private : PrivateLoad <az_extloadi8>; 310def sextloadi8_private : PrivateLoad <sextloadi8>; 311def az_extloadi16_private : PrivateLoad <az_extloadi16>; 312def sextloadi16_private : PrivateLoad <sextloadi16>; 313 314def store_private : PrivateStore <store>; 315def truncstorei8_private : PrivateStore<truncstorei8>; 316def truncstorei16_private : PrivateStore <truncstorei16>; 317def store_hi16_private : StoreHi16 <truncstorei16>, PrivateAddress; 318def truncstorei8_hi16_private : StoreHi16<truncstorei8>, PrivateAddress; 319 320 321def load_global : GlobalLoad <load>; 322def sextloadi8_global : GlobalLoad <sextloadi8>; 323def az_extloadi8_global : GlobalLoad <az_extloadi8>; 324def sextloadi16_global : GlobalLoad <sextloadi16>; 325def az_extloadi16_global : GlobalLoad <az_extloadi16>; 326def atomic_load_global : GlobalLoad<atomic_load>; 327 328def store_global : GlobalStore <store>; 329def truncstorei8_global : GlobalStore <truncstorei8>; 330def truncstorei16_global : GlobalStore <truncstorei16>; 331def store_atomic_global : GlobalStore<atomic_store>; 332def truncstorei8_hi16_global : StoreHi16 <truncstorei8>, GlobalAddress; 333def truncstorei16_hi16_global : StoreHi16 <truncstorei16>, GlobalAddress; 334 335def load_local : LocalLoad <load>; 336def az_extloadi8_local : LocalLoad <az_extloadi8>; 337def sextloadi8_local : LocalLoad <sextloadi8>; 338def az_extloadi16_local : LocalLoad <az_extloadi16>; 339def sextloadi16_local : LocalLoad <sextloadi16>; 340 341def store_local : LocalStore <store>; 342def truncstorei8_local : LocalStore <truncstorei8>; 343def truncstorei16_local : LocalStore <truncstorei16>; 344def store_local_hi16 : StoreHi16 <truncstorei16>, LocalAddress; 345def truncstorei8_local_hi16 : StoreHi16<truncstorei8>, LocalAddress; 346 347def load_align8_local : Aligned8Bytes < 348 (ops node:$ptr), (load_local node:$ptr) 349>; 350 351def store_align8_local : Aligned8Bytes < 352 (ops node:$val, node:$ptr), (store_local node:$val, node:$ptr) 353>; 354 355 356def load_flat : FlatLoad <load>; 357def az_extloadi8_flat : FlatLoad <az_extloadi8>; 358def sextloadi8_flat : FlatLoad <sextloadi8>; 359def az_extloadi16_flat : FlatLoad <az_extloadi16>; 360def sextloadi16_flat : FlatLoad <sextloadi16>; 361def atomic_load_flat : FlatLoad<atomic_load>; 362 363def store_flat : FlatStore <store>; 364def truncstorei8_flat : FlatStore <truncstorei8>; 365def truncstorei16_flat : FlatStore <truncstorei16>; 366def atomic_store_flat : FlatStore <atomic_store>; 367def truncstorei8_hi16_flat : StoreHi16<truncstorei8>, FlatStoreAddress; 368def truncstorei16_hi16_flat : StoreHi16<truncstorei16>, FlatStoreAddress; 369 370 371def constant_load : ConstantLoad<load>; 372def sextloadi8_constant : ConstantLoad <sextloadi8>; 373def az_extloadi8_constant : ConstantLoad <az_extloadi8>; 374def sextloadi16_constant : ConstantLoad <sextloadi16>; 375def az_extloadi16_constant : ConstantLoad <az_extloadi16>; 376 377 378class local_binary_atomic_op<SDNode atomic_op> : 379 PatFrag<(ops node:$ptr, node:$value), 380 (atomic_op node:$ptr, node:$value), [{ 381 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS; 382}]>; 383 384def atomic_swap_local : local_binary_atomic_op<atomic_swap>; 385def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>; 386def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>; 387def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>; 388def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>; 389def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>; 390def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>; 391def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>; 392def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>; 393def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>; 394def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>; 395 396def mskor_global : PatFrag<(ops node:$val, node:$ptr), 397 (AMDGPUstore_mskor node:$val, node:$ptr), [{ 398 return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS; 399}]>; 400 401class AtomicCmpSwapLocal <SDNode cmp_swap_node> : PatFrag< 402 (ops node:$ptr, node:$cmp, node:$swap), 403 (cmp_swap_node node:$ptr, node:$cmp, node:$swap), [{ 404 AtomicSDNode *AN = cast<AtomicSDNode>(N); 405 return AN->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS; 406}]>; 407 408def atomic_cmp_swap_local : AtomicCmpSwapLocal <atomic_cmp_swap>; 409 410multiclass global_binary_atomic_op<SDNode atomic_op> { 411 def "" : PatFrag< 412 (ops node:$ptr, node:$value), 413 (atomic_op node:$ptr, node:$value), 414 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS;}]>; 415 416 def _noret : PatFrag< 417 (ops node:$ptr, node:$value), 418 (atomic_op node:$ptr, node:$value), 419 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (SDValue(N, 0).use_empty());}]>; 420 421 def _ret : PatFrag< 422 (ops node:$ptr, node:$value), 423 (atomic_op node:$ptr, node:$value), 424 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (!SDValue(N, 0).use_empty());}]>; 425} 426 427defm atomic_swap_global : global_binary_atomic_op<atomic_swap>; 428defm atomic_add_global : global_binary_atomic_op<atomic_load_add>; 429defm atomic_and_global : global_binary_atomic_op<atomic_load_and>; 430defm atomic_max_global : global_binary_atomic_op<atomic_load_max>; 431defm atomic_min_global : global_binary_atomic_op<atomic_load_min>; 432defm atomic_or_global : global_binary_atomic_op<atomic_load_or>; 433defm atomic_sub_global : global_binary_atomic_op<atomic_load_sub>; 434defm atomic_umax_global : global_binary_atomic_op<atomic_load_umax>; 435defm atomic_umin_global : global_binary_atomic_op<atomic_load_umin>; 436defm atomic_xor_global : global_binary_atomic_op<atomic_load_xor>; 437 438// Legacy. 439def AMDGPUatomic_cmp_swap_global : PatFrag< 440 (ops node:$ptr, node:$value), 441 (AMDGPUatomic_cmp_swap node:$ptr, node:$value)>, GlobalAddress; 442 443def atomic_cmp_swap_global : PatFrag< 444 (ops node:$ptr, node:$cmp, node:$value), 445 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value)>, GlobalAddress; 446 447 448def atomic_cmp_swap_global_noret : PatFrag< 449 (ops node:$ptr, node:$cmp, node:$value), 450 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value), 451 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (SDValue(N, 0).use_empty());}]>; 452 453def atomic_cmp_swap_global_ret : PatFrag< 454 (ops node:$ptr, node:$cmp, node:$value), 455 (atomic_cmp_swap node:$ptr, node:$cmp, node:$value), 456 [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUASI.GLOBAL_ADDRESS && (!SDValue(N, 0).use_empty());}]>; 457 458//===----------------------------------------------------------------------===// 459// Misc Pattern Fragments 460//===----------------------------------------------------------------------===// 461 462class Constants { 463int TWO_PI = 0x40c90fdb; 464int PI = 0x40490fdb; 465int TWO_PI_INV = 0x3e22f983; 466int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding 467int FP16_ONE = 0x3C00; 468int V2FP16_ONE = 0x3C003C00; 469int FP32_ONE = 0x3f800000; 470int FP32_NEG_ONE = 0xbf800000; 471int FP64_ONE = 0x3ff0000000000000; 472int FP64_NEG_ONE = 0xbff0000000000000; 473} 474def CONST : Constants; 475 476def FP_ZERO : PatLeaf < 477 (fpimm), 478 [{return N->getValueAPF().isZero();}] 479>; 480 481def FP_ONE : PatLeaf < 482 (fpimm), 483 [{return N->isExactlyValue(1.0);}] 484>; 485 486def FP_HALF : PatLeaf < 487 (fpimm), 488 [{return N->isExactlyValue(0.5);}] 489>; 490 491/* Generic helper patterns for intrinsics */ 492/* -------------------------------------- */ 493 494class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul> 495 : AMDGPUPat < 496 (fpow f32:$src0, f32:$src1), 497 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0))) 498>; 499 500/* Other helper patterns */ 501/* --------------------- */ 502 503/* Extract element pattern */ 504class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx, 505 SubRegIndex sub_reg> 506 : AMDGPUPat< 507 (sub_type (extractelt vec_type:$src, sub_idx)), 508 (EXTRACT_SUBREG $src, sub_reg) 509> { 510 let SubtargetPredicate = TruePredicate; 511} 512 513/* Insert element pattern */ 514class Insert_Element <ValueType elem_type, ValueType vec_type, 515 int sub_idx, SubRegIndex sub_reg> 516 : AMDGPUPat < 517 (insertelt vec_type:$vec, elem_type:$elem, sub_idx), 518 (INSERT_SUBREG $vec, $elem, sub_reg) 519> { 520 let SubtargetPredicate = TruePredicate; 521} 522 523// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer 524// can handle COPY instructions. 525// bitconvert pattern 526class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : AMDGPUPat < 527 (dt (bitconvert (st rc:$src0))), 528 (dt rc:$src0) 529>; 530 531// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer 532// can handle COPY instructions. 533class DwordAddrPat<ValueType vt, RegisterClass rc> : AMDGPUPat < 534 (vt (AMDGPUdwordaddr (vt rc:$addr))), 535 (vt rc:$addr) 536>; 537 538// BFI_INT patterns 539 540multiclass BFIPatterns <Instruction BFI_INT, 541 Instruction LoadImm32, 542 RegisterClass RC64> { 543 // Definition from ISA doc: 544 // (y & x) | (z & ~x) 545 def : AMDGPUPat < 546 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))), 547 (BFI_INT $x, $y, $z) 548 >; 549 550 // SHA-256 Ch function 551 // z ^ (x & (y ^ z)) 552 def : AMDGPUPat < 553 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))), 554 (BFI_INT $x, $y, $z) 555 >; 556 557 def : AMDGPUPat < 558 (fcopysign f32:$src0, f32:$src1), 559 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0, $src1) 560 >; 561 562 def : AMDGPUPat < 563 (f32 (fcopysign f32:$src0, f64:$src1)), 564 (BFI_INT (LoadImm32 (i32 0x7fffffff)), $src0, 565 (i32 (EXTRACT_SUBREG $src1, sub1))) 566 >; 567 568 def : AMDGPUPat < 569 (f64 (fcopysign f64:$src0, f64:$src1)), 570 (REG_SEQUENCE RC64, 571 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0, 572 (BFI_INT (LoadImm32 (i32 0x7fffffff)), 573 (i32 (EXTRACT_SUBREG $src0, sub1)), 574 (i32 (EXTRACT_SUBREG $src1, sub1))), sub1) 575 >; 576 577 def : AMDGPUPat < 578 (f64 (fcopysign f64:$src0, f32:$src1)), 579 (REG_SEQUENCE RC64, 580 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0, 581 (BFI_INT (LoadImm32 (i32 0x7fffffff)), 582 (i32 (EXTRACT_SUBREG $src0, sub1)), 583 $src1), sub1) 584 >; 585} 586 587// SHA-256 Ma patterns 588 589// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y 590class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : AMDGPUPat < 591 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))), 592 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y) 593>; 594 595// Bitfield extract patterns 596 597def IMMZeroBasedBitfieldMask : PatLeaf <(imm), [{ 598 return isMask_32(N->getZExtValue()); 599}]>; 600 601def IMMPopCount : SDNodeXForm<imm, [{ 602 return CurDAG->getTargetConstant(countPopulation(N->getZExtValue()), SDLoc(N), 603 MVT::i32); 604}]>; 605 606multiclass BFEPattern <Instruction UBFE, Instruction SBFE, Instruction MOV> { 607 def : AMDGPUPat < 608 (i32 (and (i32 (srl i32:$src, i32:$rshift)), IMMZeroBasedBitfieldMask:$mask)), 609 (UBFE $src, $rshift, (MOV (i32 (IMMPopCount $mask)))) 610 >; 611 612 def : AMDGPUPat < 613 (srl (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)), 614 (UBFE $src, (i32 0), $width) 615 >; 616 617 def : AMDGPUPat < 618 (sra (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)), 619 (SBFE $src, (i32 0), $width) 620 >; 621} 622 623// rotr pattern 624class ROTRPattern <Instruction BIT_ALIGN> : AMDGPUPat < 625 (rotr i32:$src0, i32:$src1), 626 (BIT_ALIGN $src0, $src0, $src1) 627>; 628 629// This matches 16 permutations of 630// max(min(x, y), min(max(x, y), z)) 631class IntMed3Pat<Instruction med3Inst, 632 SDPatternOperator max, 633 SDPatternOperator max_oneuse, 634 SDPatternOperator min_oneuse, 635 ValueType vt = i32> : AMDGPUPat< 636 (max (min_oneuse vt:$src0, vt:$src1), 637 (min_oneuse (max_oneuse vt:$src0, vt:$src1), vt:$src2)), 638 (med3Inst $src0, $src1, $src2) 639>; 640 641// Special conversion patterns 642 643def cvt_rpi_i32_f32 : PatFrag < 644 (ops node:$src), 645 (fp_to_sint (ffloor (fadd $src, FP_HALF))), 646 [{ (void) N; return TM.Options.NoNaNsFPMath; }] 647>; 648 649def cvt_flr_i32_f32 : PatFrag < 650 (ops node:$src), 651 (fp_to_sint (ffloor $src)), 652 [{ (void)N; return TM.Options.NoNaNsFPMath; }] 653>; 654 655class IMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat < 656 (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2), 657 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)), 658 (Inst $src0, $src1, $src2)) 659>; 660 661class UMad24Pat<Instruction Inst, bit HasClamp = 0> : AMDGPUPat < 662 (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2), 663 !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)), 664 (Inst $src0, $src1, $src2)) 665>; 666 667class RcpPat<Instruction RcpInst, ValueType vt> : AMDGPUPat < 668 (fdiv FP_ONE, vt:$src), 669 (RcpInst $src) 670>; 671 672class RsqPat<Instruction RsqInst, ValueType vt> : AMDGPUPat < 673 (AMDGPUrcp (fsqrt vt:$src)), 674 (RsqInst $src) 675>; 676 677include "R600Instructions.td" 678include "R700Instructions.td" 679include "EvergreenInstructions.td" 680include "CaymanInstructions.td" 681 682include "SIInstrInfo.td" 683 684