1//===-- SIInstructions.td - SI Instruction Defintions ---------------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// This file was originally auto-generated from a GPU register header file and 9// all the instruction definitions were originally commented out. Instructions 10// that are not yet supported remain commented out. 11//===----------------------------------------------------------------------===// 12 13class GCNPat<dag pattern, dag result> : Pat<pattern, result>, GCNPredicateControl { 14 15} 16 17include "SOPInstructions.td" 18include "VOPInstructions.td" 19include "SMInstructions.td" 20include "FLATInstructions.td" 21include "BUFInstructions.td" 22 23//===----------------------------------------------------------------------===// 24// EXP Instructions 25//===----------------------------------------------------------------------===// 26 27defm EXP : EXP_m<0, AMDGPUexport>; 28defm EXP_DONE : EXP_m<1, AMDGPUexport_done>; 29 30//===----------------------------------------------------------------------===// 31// VINTRP Instructions 32//===----------------------------------------------------------------------===// 33 34// Used to inject printing of "_e32" suffix for VI (there are "_e64" variants for VI) 35def VINTRPDst : VINTRPDstOperand <VGPR_32>; 36 37let Uses = [M0, EXEC] in { 38 39// FIXME: Specify SchedRW for VINTRP insturctions. 40 41multiclass V_INTERP_P1_F32_m : VINTRP_m < 42 0x00000000, 43 (outs VINTRPDst:$vdst), 44 (ins VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan), 45 "v_interp_p1_f32$vdst, $vsrc, $attr$attrchan", 46 [(set f32:$vdst, (int_amdgcn_interp_p1 f32:$vsrc, 47 (i32 timm:$attrchan), (i32 timm:$attr), M0))] 48>; 49 50let OtherPredicates = [has32BankLDS] in { 51 52defm V_INTERP_P1_F32 : V_INTERP_P1_F32_m; 53 54} // End OtherPredicates = [has32BankLDS] 55 56let OtherPredicates = [has16BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1 in { 57 58defm V_INTERP_P1_F32_16bank : V_INTERP_P1_F32_m; 59 60} // End OtherPredicates = [has32BankLDS], Constraints = "@earlyclobber $vdst", isAsmParserOnly=1 61 62let DisableEncoding = "$src0", Constraints = "$src0 = $vdst" in { 63 64defm V_INTERP_P2_F32 : VINTRP_m < 65 0x00000001, 66 (outs VINTRPDst:$vdst), 67 (ins VGPR_32:$src0, VGPR_32:$vsrc, Attr:$attr, AttrChan:$attrchan), 68 "v_interp_p2_f32$vdst, $vsrc, $attr$attrchan", 69 [(set f32:$vdst, (int_amdgcn_interp_p2 f32:$src0, f32:$vsrc, 70 (i32 timm:$attrchan), (i32 timm:$attr), M0))]>; 71 72} // End DisableEncoding = "$src0", Constraints = "$src0 = $vdst" 73 74defm V_INTERP_MOV_F32 : VINTRP_m < 75 0x00000002, 76 (outs VINTRPDst:$vdst), 77 (ins InterpSlot:$vsrc, Attr:$attr, AttrChan:$attrchan), 78 "v_interp_mov_f32$vdst, $vsrc, $attr$attrchan", 79 [(set f32:$vdst, (int_amdgcn_interp_mov (i32 imm:$vsrc), 80 (i32 timm:$attrchan), (i32 timm:$attr), M0))]>; 81 82} // End Uses = [M0, EXEC] 83 84//===----------------------------------------------------------------------===// 85// Pseudo Instructions 86//===----------------------------------------------------------------------===// 87def ATOMIC_FENCE : SPseudoInstSI< 88 (outs), (ins i32imm:$ordering, i32imm:$scope), 89 [(atomic_fence (i32 timm:$ordering), (i32 timm:$scope))], 90 "ATOMIC_FENCE $ordering, $scope"> { 91 let hasSideEffects = 1; 92 let maybeAtomic = 1; 93} 94 95def VOP_I64_I64_DPP : VOPProfile <[i64, i64, untyped, untyped]> { 96 let HasExt = 1; 97 let HasExtDPP = 1; 98} 99 100let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in { 101 102// For use in patterns 103def V_CNDMASK_B64_PSEUDO : VOP3Common <(outs VReg_64:$vdst), 104 (ins VSrc_b64:$src0, VSrc_b64:$src1, SSrc_b64:$src2), "", []> { 105 let isPseudo = 1; 106 let isCodeGenOnly = 1; 107 let usesCustomInserter = 1; 108} 109 110// 64-bit vector move instruction. This is mainly used by the 111// SIFoldOperands pass to enable folding of inline immediates. 112def V_MOV_B64_PSEUDO : VPseudoInstSI <(outs VReg_64:$vdst), 113 (ins VSrc_b64:$src0)>; 114 115// 64-bit vector move with dpp. Expanded post-RA. 116def V_MOV_B64_DPP_PSEUDO : VOP_DPP_Pseudo <"v_mov_b64_dpp", VOP_I64_I64_DPP> { 117 let Size = 16; // Requires two 8-byte v_mov_b32_dpp to complete. 118} 119 120// Pseudoinstruction for @llvm.amdgcn.wqm. It is turned into a copy after the 121// WQM pass processes it. 122def WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>; 123 124// Pseudoinstruction for @llvm.amdgcn.softwqm. Like @llvm.amdgcn.wqm it is 125// turned into a copy by WQM pass, but does not seed WQM requirements. 126def SOFT_WQM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>; 127 128// Pseudoinstruction for @llvm.amdgcn.wwm. It is turned into a copy post-RA, so 129// that the @earlyclobber is respected. The @earlyclobber is to make sure that 130// the instruction that defines $src0 (which is run in WWM) doesn't 131// accidentally clobber inactive channels of $vdst. 132let Constraints = "@earlyclobber $vdst" in { 133def WWM : PseudoInstSI <(outs unknown:$vdst), (ins unknown:$src0)>; 134} 135 136} // End let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] 137 138def ENTER_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins i64imm:$src0)> { 139 let Defs = [EXEC]; 140 let hasSideEffects = 0; 141 let mayLoad = 0; 142 let mayStore = 0; 143} 144 145def EXIT_WWM : SPseudoInstSI <(outs SReg_1:$sdst), (ins SReg_1:$src0)> { 146 let hasSideEffects = 0; 147 let mayLoad = 0; 148 let mayStore = 0; 149} 150 151// Invert the exec mask and overwrite the inactive lanes of dst with inactive, 152// restoring it after we're done. 153def V_SET_INACTIVE_B32 : VPseudoInstSI <(outs VGPR_32:$vdst), 154 (ins VGPR_32: $src, VSrc_b32:$inactive), 155 [(set i32:$vdst, (int_amdgcn_set_inactive i32:$src, i32:$inactive))]> { 156 let Constraints = "$src = $vdst"; 157} 158 159def V_SET_INACTIVE_B64 : VPseudoInstSI <(outs VReg_64:$vdst), 160 (ins VReg_64: $src, VSrc_b64:$inactive), 161 [(set i64:$vdst, (int_amdgcn_set_inactive i64:$src, i64:$inactive))]> { 162 let Constraints = "$src = $vdst"; 163} 164 165 166let usesCustomInserter = 1, Defs = [SCC] in { 167def S_ADD_U64_PSEUDO : SPseudoInstSI < 168 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1), 169 [(set SReg_64:$vdst, (add i64:$src0, i64:$src1))] 170>; 171 172def S_SUB_U64_PSEUDO : SPseudoInstSI < 173 (outs SReg_64:$vdst), (ins SSrc_b64:$src0, SSrc_b64:$src1), 174 [(set SReg_64:$vdst, (sub i64:$src0, i64:$src1))] 175>; 176 177def S_ADD_U64_CO_PSEUDO : SPseudoInstSI < 178 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1) 179>; 180 181def S_SUB_U64_CO_PSEUDO : SPseudoInstSI < 182 (outs SReg_64:$vdst, VOPDstS64orS32:$sdst), (ins SSrc_b64:$src0, SSrc_b64:$src1) 183>; 184} // End usesCustomInserter = 1, Defs = [SCC] 185 186let usesCustomInserter = 1 in { 187def GET_GROUPSTATICSIZE : SPseudoInstSI <(outs SReg_32:$sdst), (ins), 188 [(set SReg_32:$sdst, (int_amdgcn_groupstaticsize))]>; 189} // End let usesCustomInserter = 1, SALU = 1 190 191// Wrap an instruction by duplicating it, except for setting isTerminator. 192class WrapTerminatorInst<SOP_Pseudo base_inst> : SPseudoInstSI< 193 base_inst.OutOperandList, 194 base_inst.InOperandList> { 195 let Uses = base_inst.Uses; 196 let Defs = base_inst.Defs; 197 let isTerminator = 1; 198 let isAsCheapAsAMove = base_inst.isAsCheapAsAMove; 199 let hasSideEffects = base_inst.hasSideEffects; 200 let UseNamedOperandTable = base_inst.UseNamedOperandTable; 201 let CodeSize = base_inst.CodeSize; 202} 203 204let WaveSizePredicate = isWave64 in { 205def S_MOV_B64_term : WrapTerminatorInst<S_MOV_B64>; 206def S_XOR_B64_term : WrapTerminatorInst<S_XOR_B64>; 207def S_ANDN2_B64_term : WrapTerminatorInst<S_ANDN2_B64>; 208} 209 210let WaveSizePredicate = isWave32 in { 211def S_MOV_B32_term : WrapTerminatorInst<S_MOV_B32>; 212def S_XOR_B32_term : WrapTerminatorInst<S_XOR_B32>; 213def S_OR_B32_term : WrapTerminatorInst<S_OR_B32>; 214def S_ANDN2_B32_term : WrapTerminatorInst<S_ANDN2_B32>; 215} 216 217def WAVE_BARRIER : SPseudoInstSI<(outs), (ins), 218 [(int_amdgcn_wave_barrier)]> { 219 let SchedRW = []; 220 let hasNoSchedulingInfo = 1; 221 let hasSideEffects = 1; 222 let mayLoad = 1; 223 let mayStore = 1; 224 let isConvergent = 1; 225 let FixedSize = 1; 226 let Size = 0; 227} 228 229// SI pseudo instructions. These are used by the CFG structurizer pass 230// and should be lowered to ISA instructions prior to codegen. 231 232// Dummy terminator instruction to use after control flow instructions 233// replaced with exec mask operations. 234def SI_MASK_BRANCH : VPseudoInstSI < 235 (outs), (ins brtarget:$target)> { 236 let isBranch = 0; 237 let isTerminator = 1; 238 let isBarrier = 0; 239 let SchedRW = []; 240 let hasNoSchedulingInfo = 1; 241 let FixedSize = 1; 242 let Size = 0; 243} 244 245let isTerminator = 1 in { 246 247let OtherPredicates = [EnableLateCFGStructurize] in { 248 def SI_NON_UNIFORM_BRCOND_PSEUDO : CFPseudoInstSI < 249 (outs), 250 (ins SReg_1:$vcc, brtarget:$target), 251 [(brcond i1:$vcc, bb:$target)]> { 252 let Size = 12; 253} 254} 255 256def SI_IF: CFPseudoInstSI < 257 (outs SReg_1:$dst), (ins SReg_1:$vcc, brtarget:$target), 258 [(set i1:$dst, (AMDGPUif i1:$vcc, bb:$target))], 1, 1> { 259 let Constraints = ""; 260 let Size = 12; 261 let hasSideEffects = 1; 262} 263 264def SI_ELSE : CFPseudoInstSI < 265 (outs SReg_1:$dst), 266 (ins SReg_1:$src, brtarget:$target, i1imm:$execfix), [], 1, 1> { 267 let Size = 12; 268 let hasSideEffects = 1; 269} 270 271def SI_LOOP : CFPseudoInstSI < 272 (outs), (ins SReg_1:$saved, brtarget:$target), 273 [(AMDGPUloop i1:$saved, bb:$target)], 1, 1> { 274 let Size = 8; 275 let isBranch = 1; 276 let hasSideEffects = 1; 277} 278 279} // End isTerminator = 1 280 281def SI_END_CF : CFPseudoInstSI < 282 (outs), (ins SReg_1:$saved), [], 1, 1> { 283 let Size = 4; 284 let isAsCheapAsAMove = 1; 285 let isReMaterializable = 1; 286 let hasSideEffects = 1; 287 let mayLoad = 1; // FIXME: Should not need memory flags 288 let mayStore = 1; 289} 290 291def SI_IF_BREAK : CFPseudoInstSI < 292 (outs SReg_1:$dst), (ins SReg_1:$vcc, SReg_1:$src), []> { 293 let Size = 4; 294 let isAsCheapAsAMove = 1; 295 let isReMaterializable = 1; 296} 297 298let Uses = [EXEC] in { 299 300multiclass PseudoInstKill <dag ins> { 301 // Even though this pseudo can usually be expanded without an SCC def, we 302 // conservatively assume that it has an SCC def, both because it is sometimes 303 // required in degenerate cases (when V_CMPX cannot be used due to constant 304 // bus limitations) and because it allows us to avoid having to track SCC 305 // liveness across basic blocks. 306 let Defs = [EXEC,VCC,SCC] in 307 def _PSEUDO : PseudoInstSI <(outs), ins> { 308 let isConvergent = 1; 309 let usesCustomInserter = 1; 310 } 311 312 let Defs = [EXEC,VCC,SCC] in 313 def _TERMINATOR : SPseudoInstSI <(outs), ins> { 314 let isTerminator = 1; 315 } 316} 317 318defm SI_KILL_I1 : PseudoInstKill <(ins SCSrc_i1:$src, i1imm:$killvalue)>; 319defm SI_KILL_F32_COND_IMM : PseudoInstKill <(ins VSrc_b32:$src0, i32imm:$src1, i32imm:$cond)>; 320 321let Defs = [EXEC,VCC] in 322def SI_ILLEGAL_COPY : SPseudoInstSI < 323 (outs unknown:$dst), (ins unknown:$src), 324 [], " ; illegal copy $src to $dst">; 325 326} // End Uses = [EXEC], Defs = [EXEC,VCC] 327 328// Branch on undef scc. Used to avoid intermediate copy from 329// IMPLICIT_DEF to SCC. 330def SI_BR_UNDEF : SPseudoInstSI <(outs), (ins sopp_brtarget:$simm16)> { 331 let isTerminator = 1; 332 let usesCustomInserter = 1; 333 let isBranch = 1; 334} 335 336def SI_PS_LIVE : PseudoInstSI < 337 (outs SReg_1:$dst), (ins), 338 [(set i1:$dst, (int_amdgcn_ps_live))]> { 339 let SALU = 1; 340} 341 342def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins), 343 [(int_amdgcn_unreachable)], 344 "; divergent unreachable"> { 345 let Size = 0; 346 let hasNoSchedulingInfo = 1; 347 let FixedSize = 1; 348} 349 350// Used as an isel pseudo to directly emit initialization with an 351// s_mov_b32 rather than a copy of another initialized 352// register. MachineCSE skips copies, and we don't want to have to 353// fold operands before it runs. 354def SI_INIT_M0 : SPseudoInstSI <(outs), (ins SSrc_b32:$src)> { 355 let Defs = [M0]; 356 let usesCustomInserter = 1; 357 let isAsCheapAsAMove = 1; 358 let isReMaterializable = 1; 359} 360 361def SI_INIT_EXEC : SPseudoInstSI < 362 (outs), (ins i64imm:$src), 363 [(int_amdgcn_init_exec (i64 timm:$src))]> { 364 let Defs = [EXEC]; 365 let usesCustomInserter = 1; 366 let isAsCheapAsAMove = 1; 367 let WaveSizePredicate = isWave64; 368} 369 370// FIXME: Intrinsic should be mangled for wave size. 371def SI_INIT_EXEC_LO : SPseudoInstSI < 372 (outs), (ins i32imm:$src), []> { 373 let Defs = [EXEC_LO]; 374 let usesCustomInserter = 1; 375 let isAsCheapAsAMove = 1; 376 let WaveSizePredicate = isWave32; 377} 378 379// FIXME: Wave32 version 380def SI_INIT_EXEC_FROM_INPUT : SPseudoInstSI < 381 (outs), (ins SSrc_b32:$input, i32imm:$shift), 382 [(int_amdgcn_init_exec_from_input i32:$input, (i32 timm:$shift))]> { 383 let Defs = [EXEC]; 384 let usesCustomInserter = 1; 385} 386 387def : GCNPat < 388 (int_amdgcn_init_exec timm:$src), 389 (SI_INIT_EXEC_LO (as_i32imm imm:$src))> { 390 let WaveSizePredicate = isWave32; 391} 392 393// Return for returning shaders to a shader variant epilog. 394def SI_RETURN_TO_EPILOG : SPseudoInstSI < 395 (outs), (ins variable_ops), [(AMDGPUreturn_to_epilog)]> { 396 let isTerminator = 1; 397 let isBarrier = 1; 398 let isReturn = 1; 399 let hasNoSchedulingInfo = 1; 400 let DisableWQM = 1; 401 let FixedSize = 1; 402} 403 404// Return for returning function calls. 405def SI_RETURN : SPseudoInstSI < 406 (outs), (ins), [], 407 "; return"> { 408 let isTerminator = 1; 409 let isBarrier = 1; 410 let isReturn = 1; 411 let SchedRW = [WriteBranch]; 412} 413 414// Return for returning function calls without output register. 415// 416// This version is only needed so we can fill in the output regiter in 417// the custom inserter. 418def SI_CALL_ISEL : SPseudoInstSI < 419 (outs), (ins SSrc_b64:$src0, unknown:$callee), 420 [(AMDGPUcall i64:$src0, tglobaladdr:$callee)]> { 421 let Size = 4; 422 let isCall = 1; 423 let SchedRW = [WriteBranch]; 424 let usesCustomInserter = 1; 425 // TODO: Should really base this on the call target 426 let isConvergent = 1; 427} 428 429// Wrapper around s_swappc_b64 with extra $callee parameter to track 430// the called function after regalloc. 431def SI_CALL : SPseudoInstSI < 432 (outs SReg_64:$dst), (ins SSrc_b64:$src0, unknown:$callee)> { 433 let Size = 4; 434 let isCall = 1; 435 let UseNamedOperandTable = 1; 436 let SchedRW = [WriteBranch]; 437 // TODO: Should really base this on the call target 438 let isConvergent = 1; 439} 440 441// Tail call handling pseudo 442def SI_TCRETURN : SPseudoInstSI <(outs), 443 (ins SSrc_b64:$src0, unknown:$callee, i32imm:$fpdiff), 444 [(AMDGPUtc_return i64:$src0, tglobaladdr:$callee, i32:$fpdiff)]> { 445 let Size = 4; 446 let isCall = 1; 447 let isTerminator = 1; 448 let isReturn = 1; 449 let isBarrier = 1; 450 let UseNamedOperandTable = 1; 451 let SchedRW = [WriteBranch]; 452 // TODO: Should really base this on the call target 453 let isConvergent = 1; 454} 455 456 457def ADJCALLSTACKUP : SPseudoInstSI< 458 (outs), (ins i32imm:$amt0, i32imm:$amt1), 459 [(callseq_start timm:$amt0, timm:$amt1)], 460 "; adjcallstackup $amt0 $amt1"> { 461 let Size = 8; // Worst case. (s_add_u32 + constant) 462 let FixedSize = 1; 463 let hasSideEffects = 1; 464 let usesCustomInserter = 1; 465 let SchedRW = [WriteSALU]; 466 let Defs = [SCC]; 467} 468 469def ADJCALLSTACKDOWN : SPseudoInstSI< 470 (outs), (ins i32imm:$amt1, i32imm:$amt2), 471 [(callseq_end timm:$amt1, timm:$amt2)], 472 "; adjcallstackdown $amt1"> { 473 let Size = 8; // Worst case. (s_add_u32 + constant) 474 let hasSideEffects = 1; 475 let usesCustomInserter = 1; 476 let SchedRW = [WriteSALU]; 477 let Defs = [SCC]; 478} 479 480let Defs = [M0, EXEC, SCC], 481 UseNamedOperandTable = 1 in { 482 483class SI_INDIRECT_SRC<RegisterClass rc> : VPseudoInstSI < 484 (outs VGPR_32:$vdst), 485 (ins rc:$src, VS_32:$idx, i32imm:$offset)> { 486 let usesCustomInserter = 1; 487} 488 489class SI_INDIRECT_DST<RegisterClass rc> : VPseudoInstSI < 490 (outs rc:$vdst), 491 (ins rc:$src, VS_32:$idx, i32imm:$offset, VGPR_32:$val)> { 492 let Constraints = "$src = $vdst"; 493 let usesCustomInserter = 1; 494} 495 496// TODO: We can support indirect SGPR access. 497def SI_INDIRECT_SRC_V1 : SI_INDIRECT_SRC<VGPR_32>; 498def SI_INDIRECT_SRC_V2 : SI_INDIRECT_SRC<VReg_64>; 499def SI_INDIRECT_SRC_V4 : SI_INDIRECT_SRC<VReg_128>; 500def SI_INDIRECT_SRC_V8 : SI_INDIRECT_SRC<VReg_256>; 501def SI_INDIRECT_SRC_V16 : SI_INDIRECT_SRC<VReg_512>; 502 503def SI_INDIRECT_DST_V1 : SI_INDIRECT_DST<VGPR_32>; 504def SI_INDIRECT_DST_V2 : SI_INDIRECT_DST<VReg_64>; 505def SI_INDIRECT_DST_V4 : SI_INDIRECT_DST<VReg_128>; 506def SI_INDIRECT_DST_V8 : SI_INDIRECT_DST<VReg_256>; 507def SI_INDIRECT_DST_V16 : SI_INDIRECT_DST<VReg_512>; 508 509} // End Uses = [EXEC], Defs = [M0, EXEC] 510 511multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> { 512 let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in { 513 def _SAVE : PseudoInstSI < 514 (outs), 515 (ins sgpr_class:$data, i32imm:$addr)> { 516 let mayStore = 1; 517 let mayLoad = 0; 518 } 519 520 def _RESTORE : PseudoInstSI < 521 (outs sgpr_class:$data), 522 (ins i32imm:$addr)> { 523 let mayStore = 0; 524 let mayLoad = 1; 525 } 526 } // End UseNamedOperandTable = 1 527} 528 529// You cannot use M0 as the output of v_readlane_b32 instructions or 530// use it in the sdata operand of SMEM instructions. We still need to 531// be able to spill the physical register m0, so allow it for 532// SI_SPILL_32_* instructions. 533defm SI_SPILL_S32 : SI_SPILL_SGPR <SReg_32>; 534defm SI_SPILL_S64 : SI_SPILL_SGPR <SReg_64>; 535defm SI_SPILL_S96 : SI_SPILL_SGPR <SReg_96>; 536defm SI_SPILL_S128 : SI_SPILL_SGPR <SReg_128>; 537defm SI_SPILL_S160 : SI_SPILL_SGPR <SReg_160>; 538defm SI_SPILL_S256 : SI_SPILL_SGPR <SReg_256>; 539defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>; 540defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>; 541 542multiclass SI_SPILL_VGPR <RegisterClass vgpr_class> { 543 let UseNamedOperandTable = 1, VGPRSpill = 1, 544 SchedRW = [WriteVMEM] in { 545 def _SAVE : VPseudoInstSI < 546 (outs), 547 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc, 548 SReg_32:$soffset, i32imm:$offset)> { 549 let mayStore = 1; 550 let mayLoad = 0; 551 // (2 * 4) + (8 * num_subregs) bytes maximum 552 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8); 553 // Size field is unsigned char and cannot fit more. 554 let Size = !if(!le(MaxSize, 256), MaxSize, 252); 555 } 556 557 def _RESTORE : VPseudoInstSI < 558 (outs vgpr_class:$vdata), 559 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset, 560 i32imm:$offset)> { 561 let mayStore = 0; 562 let mayLoad = 1; 563 564 // (2 * 4) + (8 * num_subregs) bytes maximum 565 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 3), 8); 566 // Size field is unsigned char and cannot fit more. 567 let Size = !if(!le(MaxSize, 256), MaxSize, 252); 568 } 569 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM] 570} 571 572defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>; 573defm SI_SPILL_V64 : SI_SPILL_VGPR <VReg_64>; 574defm SI_SPILL_V96 : SI_SPILL_VGPR <VReg_96>; 575defm SI_SPILL_V128 : SI_SPILL_VGPR <VReg_128>; 576defm SI_SPILL_V160 : SI_SPILL_VGPR <VReg_160>; 577defm SI_SPILL_V256 : SI_SPILL_VGPR <VReg_256>; 578defm SI_SPILL_V512 : SI_SPILL_VGPR <VReg_512>; 579defm SI_SPILL_V1024 : SI_SPILL_VGPR <VReg_1024>; 580 581multiclass SI_SPILL_AGPR <RegisterClass vgpr_class> { 582 let UseNamedOperandTable = 1, VGPRSpill = 1, 583 Constraints = "@earlyclobber $tmp", 584 SchedRW = [WriteVMEM] in { 585 def _SAVE : VPseudoInstSI < 586 (outs VGPR_32:$tmp), 587 (ins vgpr_class:$vdata, i32imm:$vaddr, SReg_128:$srsrc, 588 SReg_32:$soffset, i32imm:$offset)> { 589 let mayStore = 1; 590 let mayLoad = 0; 591 // (2 * 4) + (16 * num_subregs) bytes maximum 592 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8); 593 // Size field is unsigned char and cannot fit more. 594 let Size = !if(!le(MaxSize, 256), MaxSize, 252); 595 } 596 597 def _RESTORE : VPseudoInstSI < 598 (outs vgpr_class:$vdata, VGPR_32:$tmp), 599 (ins i32imm:$vaddr, SReg_128:$srsrc, SReg_32:$soffset, 600 i32imm:$offset)> { 601 let mayStore = 0; 602 let mayLoad = 1; 603 604 // (2 * 4) + (16 * num_subregs) bytes maximum 605 int MaxSize = !add(!shl(!srl(vgpr_class.Size, 5), 4), 8); 606 // Size field is unsigned char and cannot fit more. 607 let Size = !if(!le(MaxSize, 256), MaxSize, 252); 608 } 609 } // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM] 610} 611 612defm SI_SPILL_A32 : SI_SPILL_AGPR <AGPR_32>; 613defm SI_SPILL_A64 : SI_SPILL_AGPR <AReg_64>; 614defm SI_SPILL_A128 : SI_SPILL_AGPR <AReg_128>; 615defm SI_SPILL_A512 : SI_SPILL_AGPR <AReg_512>; 616defm SI_SPILL_A1024 : SI_SPILL_AGPR <AReg_1024>; 617 618def SI_PC_ADD_REL_OFFSET : SPseudoInstSI < 619 (outs SReg_64:$dst), 620 (ins si_ga:$ptr_lo, si_ga:$ptr_hi), 621 [(set SReg_64:$dst, 622 (i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> { 623 let Defs = [SCC]; 624} 625 626def : GCNPat < 627 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0), 628 (SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0)) 629>; 630 631def : GCNPat< 632 (AMDGPUtrap timm:$trapid), 633 (S_TRAP $trapid) 634>; 635 636def : GCNPat< 637 (AMDGPUelse i1:$src, bb:$target), 638 (SI_ELSE $src, $target, 0) 639>; 640 641def : Pat < 642 // -1.0 as i32 (LowerINTRINSIC_VOID converts all other constants to -1.0) 643 (AMDGPUkill (i32 -1082130432)), 644 (SI_KILL_I1_PSEUDO (i1 0), 0) 645>; 646 647def : Pat < 648 (int_amdgcn_kill i1:$src), 649 (SI_KILL_I1_PSEUDO SCSrc_i1:$src, 0) 650>; 651 652def : Pat < 653 (int_amdgcn_kill (i1 (not i1:$src))), 654 (SI_KILL_I1_PSEUDO SCSrc_i1:$src, -1) 655>; 656 657def : Pat < 658 (AMDGPUkill i32:$src), 659 (SI_KILL_F32_COND_IMM_PSEUDO VSrc_b32:$src, 0, 3) // 3 means SETOGE 660>; 661 662def : Pat < 663 (int_amdgcn_kill (i1 (setcc f32:$src, InlineImmFP32:$imm, cond:$cond))), 664 (SI_KILL_F32_COND_IMM_PSEUDO VSrc_b32:$src, (bitcast_fpimm_to_i32 $imm), (cond_as_i32imm $cond)) 665>; 666 667 // TODO: we could add more variants for other types of conditionals 668 669def : Pat < 670 (i64 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))), 671 (COPY $src) // Return the SGPRs representing i1 src 672>; 673 674def : Pat < 675 (i32 (int_amdgcn_icmp i1:$src, (i1 0), (i32 33))), 676 (COPY $src) // Return the SGPRs representing i1 src 677>; 678 679//===----------------------------------------------------------------------===// 680// VOP1 Patterns 681//===----------------------------------------------------------------------===// 682 683let OtherPredicates = [UnsafeFPMath] in { 684 685//def : RcpPat<V_RCP_F64_e32, f64>; 686//defm : RsqPat<V_RSQ_F64_e32, f64>; 687//defm : RsqPat<V_RSQ_F32_e32, f32>; 688 689def : RsqPat<V_RSQ_F32_e32, f32>; 690def : RsqPat<V_RSQ_F64_e32, f64>; 691 692// Convert (x - floor(x)) to fract(x) 693def : GCNPat < 694 (f32 (fsub (f32 (VOP3Mods f32:$x, i32:$mods)), 695 (f32 (ffloor (f32 (VOP3Mods f32:$x, i32:$mods)))))), 696 (V_FRACT_F32_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE) 697>; 698 699// Convert (x + (-floor(x))) to fract(x) 700def : GCNPat < 701 (f64 (fadd (f64 (VOP3Mods f64:$x, i32:$mods)), 702 (f64 (fneg (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))))))), 703 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE) 704>; 705 706} // End OtherPredicates = [UnsafeFPMath] 707 708 709// f16_to_fp patterns 710def : GCNPat < 711 (f32 (f16_to_fp i32:$src0)), 712 (V_CVT_F32_F16_e64 SRCMODS.NONE, $src0, DSTCLAMP.NONE, DSTOMOD.NONE) 713>; 714 715def : GCNPat < 716 (f32 (f16_to_fp (and_oneuse i32:$src0, 0x7fff))), 717 (V_CVT_F32_F16_e64 SRCMODS.ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE) 718>; 719 720def : GCNPat < 721 (f32 (f16_to_fp (i32 (srl_oneuse (and_oneuse i32:$src0, 0x7fff0000), (i32 16))))), 722 (V_CVT_F32_F16_e64 SRCMODS.ABS, (i32 (V_LSHRREV_B32_e64 (i32 16), i32:$src0)), DSTCLAMP.NONE, DSTOMOD.NONE) 723>; 724 725def : GCNPat < 726 (f32 (f16_to_fp (or_oneuse i32:$src0, 0x8000))), 727 (V_CVT_F32_F16_e64 SRCMODS.NEG_ABS, $src0, DSTCLAMP.NONE, DSTOMOD.NONE) 728>; 729 730def : GCNPat < 731 (f32 (f16_to_fp (xor_oneuse i32:$src0, 0x8000))), 732 (V_CVT_F32_F16_e64 SRCMODS.NEG, $src0, DSTCLAMP.NONE, DSTOMOD.NONE) 733>; 734 735def : GCNPat < 736 (f64 (fpextend f16:$src)), 737 (V_CVT_F64_F32_e32 (V_CVT_F32_F16_e32 $src)) 738>; 739 740// fp_to_fp16 patterns 741def : GCNPat < 742 (i32 (AMDGPUfp_to_f16 (f32 (VOP3Mods f32:$src0, i32:$src0_modifiers)))), 743 (V_CVT_F16_F32_e64 $src0_modifiers, f32:$src0, DSTCLAMP.NONE, DSTOMOD.NONE) 744>; 745 746def : GCNPat < 747 (i32 (fp_to_sint f16:$src)), 748 (V_CVT_I32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src)) 749>; 750 751def : GCNPat < 752 (i32 (fp_to_uint f16:$src)), 753 (V_CVT_U32_F32_e32 (V_CVT_F32_F16_e32 VSrc_b32:$src)) 754>; 755 756def : GCNPat < 757 (f16 (sint_to_fp i32:$src)), 758 (V_CVT_F16_F32_e32 (V_CVT_F32_I32_e32 VSrc_b32:$src)) 759>; 760 761def : GCNPat < 762 (f16 (uint_to_fp i32:$src)), 763 (V_CVT_F16_F32_e32 (V_CVT_F32_U32_e32 VSrc_b32:$src)) 764>; 765 766//===----------------------------------------------------------------------===// 767// VOP2 Patterns 768//===----------------------------------------------------------------------===// 769 770multiclass FMADPat <ValueType vt, Instruction inst> { 771 def : GCNPat < 772 (vt (fmad (VOP3NoMods vt:$src0), 773 (VOP3NoMods vt:$src1), 774 (VOP3NoMods vt:$src2))), 775 (inst SRCMODS.NONE, $src0, SRCMODS.NONE, $src1, 776 SRCMODS.NONE, $src2, DSTCLAMP.NONE, DSTOMOD.NONE) 777 >; 778} 779 780defm : FMADPat <f16, V_MAC_F16_e64>; 781defm : FMADPat <f32, V_MAC_F32_e64>; 782 783class FMADModsPat<Instruction inst, SDPatternOperator mad_opr, ValueType Ty> 784 : GCNPat< 785 (Ty (mad_opr (Ty (VOP3Mods Ty:$src0, i32:$src0_mod)), 786 (Ty (VOP3Mods Ty:$src1, i32:$src1_mod)), 787 (Ty (VOP3Mods Ty:$src2, i32:$src2_mod)))), 788 (inst $src0_mod, $src0, $src1_mod, $src1, 789 $src2_mod, $src2, DSTCLAMP.NONE, DSTOMOD.NONE) 790>; 791 792// FIXME: This should select to V_MAC_F32 793def : FMADModsPat<V_MAD_F32, AMDGPUfmad_ftz, f32>; 794def : FMADModsPat<V_MAD_F16, AMDGPUfmad_ftz, f16> { 795 let SubtargetPredicate = Has16BitInsts; 796} 797 798multiclass SelectPat <ValueType vt> { 799 def : GCNPat < 800 (vt (select i1:$src0, (VOP3Mods_f32 vt:$src1, i32:$src1_mods), 801 (VOP3Mods_f32 vt:$src2, i32:$src2_mods))), 802 (V_CNDMASK_B32_e64 $src2_mods, $src2, $src1_mods, $src1, $src0) 803 >; 804} 805 806defm : SelectPat <i16>; 807defm : SelectPat <i32>; 808defm : SelectPat <f16>; 809defm : SelectPat <f32>; 810 811let AddedComplexity = 1 in { 812def : GCNPat < 813 (i32 (add (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)), i32:$val)), 814 (V_BCNT_U32_B32_e64 $popcnt, $val) 815>; 816} 817 818def : GCNPat < 819 (i32 (ctpop i32:$popcnt)), 820 (V_BCNT_U32_B32_e64 VSrc_b32:$popcnt, (i32 0)) 821>; 822 823def : GCNPat < 824 (i16 (add (i16 (trunc (i32 (getDivergentFrag<ctpop>.ret i32:$popcnt)))), i16:$val)), 825 (V_BCNT_U32_B32_e64 $popcnt, $val) 826>; 827 828/********** ============================================ **********/ 829/********** Extraction, Insertion, Building and Casting **********/ 830/********** ============================================ **********/ 831 832foreach Index = 0-2 in { 833 def Extract_Element_v2i32_#Index : Extract_Element < 834 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index) 835 >; 836 def Insert_Element_v2i32_#Index : Insert_Element < 837 i32, v2i32, Index, !cast<SubRegIndex>(sub#Index) 838 >; 839 840 def Extract_Element_v2f32_#Index : Extract_Element < 841 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index) 842 >; 843 def Insert_Element_v2f32_#Index : Insert_Element < 844 f32, v2f32, Index, !cast<SubRegIndex>(sub#Index) 845 >; 846} 847 848foreach Index = 0-2 in { 849 def Extract_Element_v3i32_#Index : Extract_Element < 850 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index) 851 >; 852 def Insert_Element_v3i32_#Index : Insert_Element < 853 i32, v3i32, Index, !cast<SubRegIndex>(sub#Index) 854 >; 855 856 def Extract_Element_v3f32_#Index : Extract_Element < 857 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index) 858 >; 859 def Insert_Element_v3f32_#Index : Insert_Element < 860 f32, v3f32, Index, !cast<SubRegIndex>(sub#Index) 861 >; 862} 863 864foreach Index = 0-3 in { 865 def Extract_Element_v4i32_#Index : Extract_Element < 866 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index) 867 >; 868 def Insert_Element_v4i32_#Index : Insert_Element < 869 i32, v4i32, Index, !cast<SubRegIndex>(sub#Index) 870 >; 871 872 def Extract_Element_v4f32_#Index : Extract_Element < 873 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index) 874 >; 875 def Insert_Element_v4f32_#Index : Insert_Element < 876 f32, v4f32, Index, !cast<SubRegIndex>(sub#Index) 877 >; 878} 879 880foreach Index = 0-4 in { 881 def Extract_Element_v5i32_#Index : Extract_Element < 882 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index) 883 >; 884 def Insert_Element_v5i32_#Index : Insert_Element < 885 i32, v5i32, Index, !cast<SubRegIndex>(sub#Index) 886 >; 887 888 def Extract_Element_v5f32_#Index : Extract_Element < 889 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index) 890 >; 891 def Insert_Element_v5f32_#Index : Insert_Element < 892 f32, v5f32, Index, !cast<SubRegIndex>(sub#Index) 893 >; 894} 895 896foreach Index = 0-7 in { 897 def Extract_Element_v8i32_#Index : Extract_Element < 898 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index) 899 >; 900 def Insert_Element_v8i32_#Index : Insert_Element < 901 i32, v8i32, Index, !cast<SubRegIndex>(sub#Index) 902 >; 903 904 def Extract_Element_v8f32_#Index : Extract_Element < 905 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index) 906 >; 907 def Insert_Element_v8f32_#Index : Insert_Element < 908 f32, v8f32, Index, !cast<SubRegIndex>(sub#Index) 909 >; 910} 911 912foreach Index = 0-15 in { 913 def Extract_Element_v16i32_#Index : Extract_Element < 914 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index) 915 >; 916 def Insert_Element_v16i32_#Index : Insert_Element < 917 i32, v16i32, Index, !cast<SubRegIndex>(sub#Index) 918 >; 919 920 def Extract_Element_v16f32_#Index : Extract_Element < 921 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index) 922 >; 923 def Insert_Element_v16f32_#Index : Insert_Element < 924 f32, v16f32, Index, !cast<SubRegIndex>(sub#Index) 925 >; 926} 927 928 929def : Pat < 930 (extract_subvector v4i16:$vec, (i32 0)), 931 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub0)) 932>; 933 934def : Pat < 935 (extract_subvector v4i16:$vec, (i32 2)), 936 (v2i16 (EXTRACT_SUBREG v4i16:$vec, sub1)) 937>; 938 939def : Pat < 940 (extract_subvector v4f16:$vec, (i32 0)), 941 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub0)) 942>; 943 944def : Pat < 945 (extract_subvector v4f16:$vec, (i32 2)), 946 (v2f16 (EXTRACT_SUBREG v4f16:$vec, sub1)) 947>; 948 949foreach Index = 0-31 in { 950 def Extract_Element_v32i32_#Index : Extract_Element < 951 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index) 952 >; 953 954 def Insert_Element_v32i32_#Index : Insert_Element < 955 i32, v32i32, Index, !cast<SubRegIndex>(sub#Index) 956 >; 957 958 def Extract_Element_v32f32_#Index : Extract_Element < 959 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index) 960 >; 961 962 def Insert_Element_v32f32_#Index : Insert_Element < 963 f32, v32f32, Index, !cast<SubRegIndex>(sub#Index) 964 >; 965} 966 967// FIXME: Why do only some of these type combinations for SReg and 968// VReg? 969// 16-bit bitcast 970def : BitConvert <i16, f16, VGPR_32>; 971def : BitConvert <f16, i16, VGPR_32>; 972def : BitConvert <i16, f16, SReg_32>; 973def : BitConvert <f16, i16, SReg_32>; 974 975// 32-bit bitcast 976def : BitConvert <i32, f32, VGPR_32>; 977def : BitConvert <f32, i32, VGPR_32>; 978def : BitConvert <i32, f32, SReg_32>; 979def : BitConvert <f32, i32, SReg_32>; 980def : BitConvert <v2i16, i32, SReg_32>; 981def : BitConvert <i32, v2i16, SReg_32>; 982def : BitConvert <v2f16, i32, SReg_32>; 983def : BitConvert <i32, v2f16, SReg_32>; 984def : BitConvert <v2i16, v2f16, SReg_32>; 985def : BitConvert <v2f16, v2i16, SReg_32>; 986def : BitConvert <v2f16, f32, SReg_32>; 987def : BitConvert <f32, v2f16, SReg_32>; 988def : BitConvert <v2i16, f32, SReg_32>; 989def : BitConvert <f32, v2i16, SReg_32>; 990 991// 64-bit bitcast 992def : BitConvert <i64, f64, VReg_64>; 993def : BitConvert <f64, i64, VReg_64>; 994def : BitConvert <v2i32, v2f32, VReg_64>; 995def : BitConvert <v2f32, v2i32, VReg_64>; 996def : BitConvert <i64, v2i32, VReg_64>; 997def : BitConvert <v2i32, i64, VReg_64>; 998def : BitConvert <i64, v2f32, VReg_64>; 999def : BitConvert <v2f32, i64, VReg_64>; 1000def : BitConvert <f64, v2f32, VReg_64>; 1001def : BitConvert <v2f32, f64, VReg_64>; 1002def : BitConvert <f64, v2i32, VReg_64>; 1003def : BitConvert <v2i32, f64, VReg_64>; 1004def : BitConvert <v4i16, v4f16, VReg_64>; 1005def : BitConvert <v4f16, v4i16, VReg_64>; 1006 1007// FIXME: Make SGPR 1008def : BitConvert <v2i32, v4f16, VReg_64>; 1009def : BitConvert <v4f16, v2i32, VReg_64>; 1010def : BitConvert <v2i32, v4f16, VReg_64>; 1011def : BitConvert <v2i32, v4i16, VReg_64>; 1012def : BitConvert <v4i16, v2i32, VReg_64>; 1013def : BitConvert <v2f32, v4f16, VReg_64>; 1014def : BitConvert <v4f16, v2f32, VReg_64>; 1015def : BitConvert <v2f32, v4i16, VReg_64>; 1016def : BitConvert <v4i16, v2f32, VReg_64>; 1017def : BitConvert <v4i16, f64, VReg_64>; 1018def : BitConvert <v4f16, f64, VReg_64>; 1019def : BitConvert <f64, v4i16, VReg_64>; 1020def : BitConvert <f64, v4f16, VReg_64>; 1021def : BitConvert <v4i16, i64, VReg_64>; 1022def : BitConvert <v4f16, i64, VReg_64>; 1023def : BitConvert <i64, v4i16, VReg_64>; 1024def : BitConvert <i64, v4f16, VReg_64>; 1025 1026def : BitConvert <v4i32, v4f32, VReg_128>; 1027def : BitConvert <v4f32, v4i32, VReg_128>; 1028 1029// 96-bit bitcast 1030def : BitConvert <v3i32, v3f32, SGPR_96>; 1031def : BitConvert <v3f32, v3i32, SGPR_96>; 1032 1033// 128-bit bitcast 1034def : BitConvert <v2i64, v4i32, SReg_128>; 1035def : BitConvert <v4i32, v2i64, SReg_128>; 1036def : BitConvert <v2f64, v4f32, VReg_128>; 1037def : BitConvert <v2f64, v4i32, VReg_128>; 1038def : BitConvert <v4f32, v2f64, VReg_128>; 1039def : BitConvert <v4i32, v2f64, VReg_128>; 1040def : BitConvert <v2i64, v2f64, VReg_128>; 1041def : BitConvert <v2f64, v2i64, VReg_128>; 1042 1043// 160-bit bitcast 1044def : BitConvert <v5i32, v5f32, SGPR_160>; 1045def : BitConvert <v5f32, v5i32, SGPR_160>; 1046 1047// 256-bit bitcast 1048def : BitConvert <v8i32, v8f32, SReg_256>; 1049def : BitConvert <v8f32, v8i32, SReg_256>; 1050def : BitConvert <v8i32, v8f32, VReg_256>; 1051def : BitConvert <v8f32, v8i32, VReg_256>; 1052 1053// 512-bit bitcast 1054def : BitConvert <v16i32, v16f32, VReg_512>; 1055def : BitConvert <v16f32, v16i32, VReg_512>; 1056 1057// 1024-bit bitcast 1058def : BitConvert <v32i32, v32f32, VReg_1024>; 1059def : BitConvert <v32f32, v32i32, VReg_1024>; 1060 1061/********** =================== **********/ 1062/********** Src & Dst modifiers **********/ 1063/********** =================== **********/ 1064 1065 1066// If denormals are not enabled, it only impacts the compare of the 1067// inputs. The output result is not flushed. 1068class ClampPat<Instruction inst, ValueType vt> : GCNPat < 1069 (vt (AMDGPUclamp (VOP3Mods vt:$src0, i32:$src0_modifiers))), 1070 (inst i32:$src0_modifiers, vt:$src0, 1071 i32:$src0_modifiers, vt:$src0, DSTCLAMP.ENABLE, DSTOMOD.NONE) 1072>; 1073 1074def : ClampPat<V_MAX_F32_e64, f32>; 1075def : ClampPat<V_MAX_F64, f64>; 1076def : ClampPat<V_MAX_F16_e64, f16>; 1077 1078let SubtargetPredicate = HasVOP3PInsts in { 1079def : GCNPat < 1080 (v2f16 (AMDGPUclamp (VOP3PMods v2f16:$src0, i32:$src0_modifiers))), 1081 (V_PK_MAX_F16 $src0_modifiers, $src0, 1082 $src0_modifiers, $src0, DSTCLAMP.ENABLE) 1083>; 1084} 1085 1086/********** ================================ **********/ 1087/********** Floating point absolute/negative **********/ 1088/********** ================================ **********/ 1089 1090// Prevent expanding both fneg and fabs. 1091// TODO: Add IgnoredBySelectionDAG bit? 1092let AddedComplexity = 1 in { // Prefer SALU to VALU patterns for DAG 1093 1094def : GCNPat < 1095 (fneg (fabs (f32 SReg_32:$src))), 1096 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000))) // Set sign bit 1097>; 1098 1099def : GCNPat < 1100 (fabs (f32 SReg_32:$src)), 1101 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fffffff))) 1102>; 1103 1104def : GCNPat < 1105 (fneg (f32 SReg_32:$src)), 1106 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80000000))) 1107>; 1108 1109def : GCNPat < 1110 (fneg (f16 SReg_32:$src)), 1111 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000))) 1112>; 1113 1114def : GCNPat < 1115 (fneg (f16 VGPR_32:$src)), 1116 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src) 1117>; 1118 1119def : GCNPat < 1120 (fabs (f16 SReg_32:$src)), 1121 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00007fff))) 1122>; 1123 1124def : GCNPat < 1125 (fneg (fabs (f16 SReg_32:$src))), 1126 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x00008000))) // Set sign bit 1127>; 1128 1129def : GCNPat < 1130 (fneg (fabs (f16 VGPR_32:$src))), 1131 (V_OR_B32_e32 (S_MOV_B32 (i32 0x00008000)), VGPR_32:$src) // Set sign bit 1132>; 1133 1134def : GCNPat < 1135 (fneg (v2f16 SReg_32:$src)), 1136 (S_XOR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) 1137>; 1138 1139def : GCNPat < 1140 (fabs (v2f16 SReg_32:$src)), 1141 (S_AND_B32 SReg_32:$src, (S_MOV_B32 (i32 0x7fff7fff))) 1142>; 1143 1144// This is really (fneg (fabs v2f16:$src)) 1145// 1146// fabs is not reported as free because there is modifier for it in 1147// VOP3P instructions, so it is turned into the bit op. 1148def : GCNPat < 1149 (fneg (v2f16 (bitconvert (and_oneuse (i32 SReg_32:$src), 0x7fff7fff)))), 1150 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit 1151>; 1152 1153def : GCNPat < 1154 (fneg (v2f16 (fabs SReg_32:$src))), 1155 (S_OR_B32 SReg_32:$src, (S_MOV_B32 (i32 0x80008000))) // Set sign bit 1156>; 1157 1158// FIXME: The implicit-def of scc from S_[X]OR_B32 is mishandled 1159 // def : GCNPat < 1160// (fneg (f64 SReg_64:$src)), 1161// (REG_SEQUENCE SReg_64, 1162// (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)), 1163// sub0, 1164// (S_XOR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)), 1165// (i32 (S_MOV_B32 (i32 0x80000000)))), 1166// sub1) 1167// >; 1168 1169// def : GCNPat < 1170// (fneg (fabs (f64 SReg_64:$src))), 1171// (REG_SEQUENCE SReg_64, 1172// (i32 (EXTRACT_SUBREG SReg_64:$src, sub0)), 1173// sub0, 1174// (S_OR_B32 (i32 (EXTRACT_SUBREG SReg_64:$src, sub1)), 1175// (S_MOV_B32 (i32 0x80000000))), // Set sign bit. 1176// sub1) 1177// >; 1178 1179} // End let AddedComplexity = 1 1180 1181def : GCNPat < 1182 (fabs (f32 VGPR_32:$src)), 1183 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fffffff)), VGPR_32:$src) 1184>; 1185 1186def : GCNPat < 1187 (fneg (f32 VGPR_32:$src)), 1188 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80000000)), VGPR_32:$src) 1189>; 1190 1191def : GCNPat < 1192 (fabs (f16 VGPR_32:$src)), 1193 (V_AND_B32_e32 (S_MOV_B32 (i32 0x00007fff)), VGPR_32:$src) 1194>; 1195 1196def : GCNPat < 1197 (fneg (v2f16 VGPR_32:$src)), 1198 (V_XOR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src) 1199>; 1200 1201def : GCNPat < 1202 (fabs (v2f16 VGPR_32:$src)), 1203 (V_AND_B32_e32 (S_MOV_B32 (i32 0x7fff7fff)), VGPR_32:$src) 1204>; 1205 1206def : GCNPat < 1207 (fneg (v2f16 (fabs VGPR_32:$src))), 1208 (V_OR_B32_e32 (S_MOV_B32 (i32 0x80008000)), VGPR_32:$src) // Set sign bit 1209>; 1210 1211def : GCNPat < 1212 (fabs (f64 VReg_64:$src)), 1213 (REG_SEQUENCE VReg_64, 1214 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)), 1215 sub0, 1216 (V_AND_B32_e64 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)), 1217 (V_MOV_B32_e32 (i32 0x7fffffff))), // Set sign bit. 1218 sub1) 1219>; 1220 1221// TODO: Use SGPR for constant 1222def : GCNPat < 1223 (fneg (f64 VReg_64:$src)), 1224 (REG_SEQUENCE VReg_64, 1225 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)), 1226 sub0, 1227 (V_XOR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)), 1228 (i32 (V_MOV_B32_e32 (i32 0x80000000)))), 1229 sub1) 1230>; 1231 1232// TODO: Use SGPR for constant 1233def : GCNPat < 1234 (fneg (fabs (f64 VReg_64:$src))), 1235 (REG_SEQUENCE VReg_64, 1236 (i32 (EXTRACT_SUBREG VReg_64:$src, sub0)), 1237 sub0, 1238 (V_OR_B32_e32 (i32 (EXTRACT_SUBREG VReg_64:$src, sub1)), 1239 (V_MOV_B32_e32 (i32 0x80000000))), // Set sign bit. 1240 sub1) 1241>; 1242 1243def : GCNPat < 1244 (fcopysign f16:$src0, f16:$src1), 1245 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, $src1) 1246>; 1247 1248def : GCNPat < 1249 (fcopysign f32:$src0, f16:$src1), 1250 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), $src0, 1251 (V_LSHLREV_B32_e64 (i32 16), $src1)) 1252>; 1253 1254def : GCNPat < 1255 (fcopysign f64:$src0, f16:$src1), 1256 (REG_SEQUENCE SReg_64, 1257 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0, 1258 (V_BFI_B32 (S_MOV_B32 (i32 0x7fffffff)), (i32 (EXTRACT_SUBREG $src0, sub1)), 1259 (V_LSHLREV_B32_e64 (i32 16), $src1)), sub1) 1260>; 1261 1262def : GCNPat < 1263 (fcopysign f16:$src0, f32:$src1), 1264 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, 1265 (V_LSHRREV_B32_e64 (i32 16), $src1)) 1266>; 1267 1268def : GCNPat < 1269 (fcopysign f16:$src0, f64:$src1), 1270 (V_BFI_B32 (S_MOV_B32 (i32 0x00007fff)), $src0, 1271 (V_LSHRREV_B32_e64 (i32 16), (EXTRACT_SUBREG $src1, sub1))) 1272>; 1273 1274/********** ================== **********/ 1275/********** Immediate Patterns **********/ 1276/********** ================== **********/ 1277 1278def : GCNPat < 1279 (VGPRImm<(i32 imm)>:$imm), 1280 (V_MOV_B32_e32 imm:$imm) 1281>; 1282 1283def : GCNPat < 1284 (VGPRImm<(f32 fpimm)>:$imm), 1285 (V_MOV_B32_e32 (f32 (bitcast_fpimm_to_i32 $imm))) 1286>; 1287 1288def : GCNPat < 1289 (i32 imm:$imm), 1290 (S_MOV_B32 imm:$imm) 1291>; 1292 1293def : GCNPat < 1294 (VGPRImm<(SIlds tglobaladdr:$ga)>), 1295 (V_MOV_B32_e32 $ga) 1296>; 1297 1298def : GCNPat < 1299 (SIlds tglobaladdr:$ga), 1300 (S_MOV_B32 $ga) 1301>; 1302 1303// FIXME: Workaround for ordering issue with peephole optimizer where 1304// a register class copy interferes with immediate folding. Should 1305// use s_mov_b32, which can be shrunk to s_movk_i32 1306def : GCNPat < 1307 (VGPRImm<(f16 fpimm)>:$imm), 1308 (V_MOV_B32_e32 (f16 (bitcast_fpimm_to_i32 $imm))) 1309>; 1310 1311def : GCNPat < 1312 (f32 fpimm:$imm), 1313 (S_MOV_B32 (f32 (bitcast_fpimm_to_i32 $imm))) 1314>; 1315 1316def : GCNPat < 1317 (f16 fpimm:$imm), 1318 (S_MOV_B32 (i32 (bitcast_fpimm_to_i32 $imm))) 1319>; 1320 1321def : GCNPat < 1322 (i32 frameindex:$fi), 1323 (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi))) 1324>; 1325 1326def : GCNPat < 1327 (i64 InlineImm64:$imm), 1328 (S_MOV_B64 InlineImm64:$imm) 1329>; 1330 1331// XXX - Should this use a s_cmp to set SCC? 1332 1333// Set to sign-extended 64-bit value (true = -1, false = 0) 1334def : GCNPat < 1335 (i1 imm:$imm), 1336 (S_MOV_B64 (i64 (as_i64imm $imm))) 1337> { 1338 let WaveSizePredicate = isWave64; 1339} 1340 1341def : GCNPat < 1342 (i1 imm:$imm), 1343 (S_MOV_B32 (i32 (as_i32imm $imm))) 1344> { 1345 let WaveSizePredicate = isWave32; 1346} 1347 1348def : GCNPat < 1349 (f64 InlineImmFP64:$imm), 1350 (S_MOV_B64 (f64 (bitcast_fpimm_to_i64 InlineImmFP64:$imm))) 1351>; 1352 1353/********** ================== **********/ 1354/********** Intrinsic Patterns **********/ 1355/********** ================== **********/ 1356 1357// FIXME: Should use _e64 and select source modifiers. 1358def : POW_Common <V_LOG_F32_e32, V_EXP_F32_e32, V_MUL_LEGACY_F32_e32>; 1359 1360def : GCNPat < 1361 (i32 (sext i1:$src0)), 1362 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1363 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0) 1364>; 1365 1366class Ext32Pat <SDNode ext> : GCNPat < 1367 (i32 (ext i1:$src0)), 1368 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1369 /*src1mod*/(i32 0), /*src1*/(i32 1), $src0) 1370>; 1371 1372def : Ext32Pat <zext>; 1373def : Ext32Pat <anyext>; 1374 1375// The multiplication scales from [0,1] to the unsigned integer range 1376def : GCNPat < 1377 (AMDGPUurecip i32:$src0), 1378 (V_CVT_U32_F32_e32 1379 (V_MUL_F32_e32 (i32 CONST.FP_UINT_MAX_PLUS_1), 1380 (V_RCP_IFLAG_F32_e32 (V_CVT_F32_U32_e32 $src0)))) 1381>; 1382 1383//===----------------------------------------------------------------------===// 1384// VOP3 Patterns 1385//===----------------------------------------------------------------------===// 1386 1387def : IMad24Pat<V_MAD_I32_I24, 1>; 1388def : UMad24Pat<V_MAD_U32_U24, 1>; 1389 1390// FIXME: This should only be done for VALU inputs 1391defm : BFIPatterns <V_BFI_B32, S_MOV_B32, SReg_64>; 1392def : ROTRPattern <V_ALIGNBIT_B32>; 1393 1394def : GCNPat<(i32 (trunc (srl i64:$src0, (and i32:$src1, (i32 31))))), 1395 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)), 1396 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>; 1397 1398def : GCNPat<(i32 (trunc (srl i64:$src0, (i32 ShiftAmt32Imm:$src1)))), 1399 (V_ALIGNBIT_B32 (i32 (EXTRACT_SUBREG (i64 $src0), sub1)), 1400 (i32 (EXTRACT_SUBREG (i64 $src0), sub0)), $src1)>; 1401 1402/********** ====================== **********/ 1403/********** Indirect addressing **********/ 1404/********** ====================== **********/ 1405 1406multiclass SI_INDIRECT_Pattern <ValueType vt, ValueType eltvt, string VecSize> { 1407 // Extract with offset 1408 def : GCNPat< 1409 (eltvt (extractelt vt:$src, (MOVRELOffset i32:$idx, (i32 imm:$offset)))), 1410 (!cast<Instruction>("SI_INDIRECT_SRC_"#VecSize) $src, $idx, imm:$offset) 1411 >; 1412 1413 // Insert with offset 1414 def : GCNPat< 1415 (insertelt vt:$src, eltvt:$val, (MOVRELOffset i32:$idx, (i32 imm:$offset))), 1416 (!cast<Instruction>("SI_INDIRECT_DST_"#VecSize) $src, $idx, imm:$offset, $val) 1417 >; 1418} 1419 1420defm : SI_INDIRECT_Pattern <v2f32, f32, "V2">; 1421defm : SI_INDIRECT_Pattern <v4f32, f32, "V4">; 1422defm : SI_INDIRECT_Pattern <v8f32, f32, "V8">; 1423defm : SI_INDIRECT_Pattern <v16f32, f32, "V16">; 1424 1425defm : SI_INDIRECT_Pattern <v2i32, i32, "V2">; 1426defm : SI_INDIRECT_Pattern <v4i32, i32, "V4">; 1427defm : SI_INDIRECT_Pattern <v8i32, i32, "V8">; 1428defm : SI_INDIRECT_Pattern <v16i32, i32, "V16">; 1429 1430//===----------------------------------------------------------------------===// 1431// SAD Patterns 1432//===----------------------------------------------------------------------===// 1433 1434def : GCNPat < 1435 (add (sub_oneuse (umax i32:$src0, i32:$src1), 1436 (umin i32:$src0, i32:$src1)), 1437 i32:$src2), 1438 (V_SAD_U32 $src0, $src1, $src2, (i1 0)) 1439>; 1440 1441def : GCNPat < 1442 (add (select_oneuse (i1 (setugt i32:$src0, i32:$src1)), 1443 (sub i32:$src0, i32:$src1), 1444 (sub i32:$src1, i32:$src0)), 1445 i32:$src2), 1446 (V_SAD_U32 $src0, $src1, $src2, (i1 0)) 1447>; 1448 1449//===----------------------------------------------------------------------===// 1450// Conversion Patterns 1451//===----------------------------------------------------------------------===// 1452 1453def : GCNPat<(i32 (sext_inreg i32:$src, i1)), 1454 (S_BFE_I32 i32:$src, (i32 65536))>; // 0 | 1 << 16 1455 1456// Handle sext_inreg in i64 1457def : GCNPat < 1458 (i64 (sext_inreg i64:$src, i1)), 1459 (S_BFE_I64 i64:$src, (i32 0x10000)) // 0 | 1 << 16 1460>; 1461 1462def : GCNPat < 1463 (i16 (sext_inreg i16:$src, i1)), 1464 (S_BFE_I32 $src, (i32 0x00010000)) // 0 | 1 << 16 1465>; 1466 1467def : GCNPat < 1468 (i16 (sext_inreg i16:$src, i8)), 1469 (S_BFE_I32 $src, (i32 0x80000)) // 0 | 8 << 16 1470>; 1471 1472def : GCNPat < 1473 (i64 (sext_inreg i64:$src, i8)), 1474 (S_BFE_I64 i64:$src, (i32 0x80000)) // 0 | 8 << 16 1475>; 1476 1477def : GCNPat < 1478 (i64 (sext_inreg i64:$src, i16)), 1479 (S_BFE_I64 i64:$src, (i32 0x100000)) // 0 | 16 << 16 1480>; 1481 1482def : GCNPat < 1483 (i64 (sext_inreg i64:$src, i32)), 1484 (S_BFE_I64 i64:$src, (i32 0x200000)) // 0 | 32 << 16 1485>; 1486 1487def : GCNPat < 1488 (i64 (zext i32:$src)), 1489 (REG_SEQUENCE SReg_64, $src, sub0, (S_MOV_B32 (i32 0)), sub1) 1490>; 1491 1492def : GCNPat < 1493 (i64 (anyext i32:$src)), 1494 (REG_SEQUENCE SReg_64, $src, sub0, (i32 (IMPLICIT_DEF)), sub1) 1495>; 1496 1497class ZExt_i64_i1_Pat <SDNode ext> : GCNPat < 1498 (i64 (ext i1:$src)), 1499 (REG_SEQUENCE VReg_64, 1500 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1501 /*src1mod*/(i32 0), /*src1*/(i32 1), $src), 1502 sub0, (S_MOV_B32 (i32 0)), sub1) 1503>; 1504 1505 1506def : ZExt_i64_i1_Pat<zext>; 1507def : ZExt_i64_i1_Pat<anyext>; 1508 1509// FIXME: We need to use COPY_TO_REGCLASS to work-around the fact that 1510// REG_SEQUENCE patterns don't support instructions with multiple outputs. 1511def : GCNPat < 1512 (i64 (sext i32:$src)), 1513 (REG_SEQUENCE SReg_64, $src, sub0, 1514 (i32 (COPY_TO_REGCLASS (S_ASHR_I32 $src, (i32 31)), SReg_32_XM0)), sub1) 1515>; 1516 1517def : GCNPat < 1518 (i64 (sext i1:$src)), 1519 (REG_SEQUENCE VReg_64, 1520 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1521 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub0, 1522 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1523 /*src1mod*/(i32 0), /*src1*/(i32 -1), $src), sub1) 1524>; 1525 1526class FPToI1Pat<Instruction Inst, int KOne, ValueType kone_type, ValueType vt, SDPatternOperator fp_to_int> : GCNPat < 1527 (i1 (fp_to_int (vt (VOP3Mods vt:$src0, i32:$src0_modifiers)))), 1528 (i1 (Inst 0, (kone_type KOne), $src0_modifiers, $src0, DSTCLAMP.NONE)) 1529>; 1530 1531def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_ONE, i32, f32, fp_to_uint>; 1532def : FPToI1Pat<V_CMP_EQ_F32_e64, CONST.FP32_NEG_ONE, i32, f32, fp_to_sint>; 1533def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_ONE, i64, f64, fp_to_uint>; 1534def : FPToI1Pat<V_CMP_EQ_F64_e64, CONST.FP64_NEG_ONE, i64, f64, fp_to_sint>; 1535 1536// If we need to perform a logical operation on i1 values, we need to 1537// use vector comparisons since there is only one SCC register. Vector 1538// comparisons may write to a pair of SGPRs or a single SGPR, so treat 1539// these as 32 or 64-bit comparisons. When legalizing SGPR copies, 1540// instructions resulting in the copies from SCC to these instructions 1541// will be moved to the VALU. 1542 1543let WaveSizePredicate = isWave64 in { 1544def : GCNPat < 1545 (i1 (and i1:$src0, i1:$src1)), 1546 (S_AND_B64 $src0, $src1) 1547>; 1548 1549def : GCNPat < 1550 (i1 (or i1:$src0, i1:$src1)), 1551 (S_OR_B64 $src0, $src1) 1552>; 1553 1554def : GCNPat < 1555 (i1 (xor i1:$src0, i1:$src1)), 1556 (S_XOR_B64 $src0, $src1) 1557>; 1558 1559def : GCNPat < 1560 (i1 (add i1:$src0, i1:$src1)), 1561 (S_XOR_B64 $src0, $src1) 1562>; 1563 1564def : GCNPat < 1565 (i1 (sub i1:$src0, i1:$src1)), 1566 (S_XOR_B64 $src0, $src1) 1567>; 1568 1569let AddedComplexity = 1 in { 1570def : GCNPat < 1571 (i1 (add i1:$src0, (i1 -1))), 1572 (S_NOT_B64 $src0) 1573>; 1574 1575def : GCNPat < 1576 (i1 (sub i1:$src0, (i1 -1))), 1577 (S_NOT_B64 $src0) 1578>; 1579} 1580} // end isWave64 1581 1582let WaveSizePredicate = isWave32 in { 1583def : GCNPat < 1584 (i1 (and i1:$src0, i1:$src1)), 1585 (S_AND_B32 $src0, $src1) 1586>; 1587 1588def : GCNPat < 1589 (i1 (or i1:$src0, i1:$src1)), 1590 (S_OR_B32 $src0, $src1) 1591>; 1592 1593def : GCNPat < 1594 (i1 (xor i1:$src0, i1:$src1)), 1595 (S_XOR_B32 $src0, $src1) 1596>; 1597 1598def : GCNPat < 1599 (i1 (add i1:$src0, i1:$src1)), 1600 (S_XOR_B32 $src0, $src1) 1601>; 1602 1603def : GCNPat < 1604 (i1 (sub i1:$src0, i1:$src1)), 1605 (S_XOR_B32 $src0, $src1) 1606>; 1607 1608let AddedComplexity = 1 in { 1609def : GCNPat < 1610 (i1 (add i1:$src0, (i1 -1))), 1611 (S_NOT_B32 $src0) 1612>; 1613 1614def : GCNPat < 1615 (i1 (sub i1:$src0, (i1 -1))), 1616 (S_NOT_B32 $src0) 1617>; 1618} 1619} // end isWave32 1620 1621def : GCNPat < 1622 (f16 (sint_to_fp i1:$src)), 1623 (V_CVT_F16_F32_e32 ( 1624 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1625 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE), 1626 SSrc_i1:$src)) 1627>; 1628 1629def : GCNPat < 1630 (f16 (uint_to_fp i1:$src)), 1631 (V_CVT_F16_F32_e32 ( 1632 V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1633 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE), 1634 SSrc_i1:$src)) 1635>; 1636 1637def : GCNPat < 1638 (f32 (sint_to_fp i1:$src)), 1639 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1640 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_NEG_ONE), 1641 SSrc_i1:$src) 1642>; 1643 1644def : GCNPat < 1645 (f32 (uint_to_fp i1:$src)), 1646 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1647 /*src1mod*/(i32 0), /*src1*/(i32 CONST.FP32_ONE), 1648 SSrc_i1:$src) 1649>; 1650 1651def : GCNPat < 1652 (f64 (sint_to_fp i1:$src)), 1653 (V_CVT_F64_I32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1654 /*src1mod*/(i32 0), /*src1*/(i32 -1), 1655 SSrc_i1:$src)) 1656>; 1657 1658def : GCNPat < 1659 (f64 (uint_to_fp i1:$src)), 1660 (V_CVT_F64_U32_e32 (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), 1661 /*src1mod*/(i32 0), /*src1*/(i32 1), 1662 SSrc_i1:$src)) 1663>; 1664 1665//===----------------------------------------------------------------------===// 1666// Miscellaneous Patterns 1667//===----------------------------------------------------------------------===// 1668def : GCNPat < 1669 (i32 (AMDGPUfp16_zext f16:$src)), 1670 (COPY $src) 1671>; 1672 1673 1674def : GCNPat < 1675 (i32 (trunc i64:$a)), 1676 (EXTRACT_SUBREG $a, sub0) 1677>; 1678 1679def : GCNPat < 1680 (i1 (trunc i32:$a)), 1681 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1)) 1682>; 1683 1684def : GCNPat < 1685 (i1 (trunc i16:$a)), 1686 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), $a), (i32 1)) 1687>; 1688 1689def : GCNPat < 1690 (i1 (trunc i64:$a)), 1691 (V_CMP_EQ_U32_e64 (S_AND_B32 (i32 1), 1692 (i32 (EXTRACT_SUBREG $a, sub0))), (i32 1)) 1693>; 1694 1695def : GCNPat < 1696 (i32 (bswap i32:$a)), 1697 (V_BFI_B32 (S_MOV_B32 (i32 0x00ff00ff)), 1698 (V_ALIGNBIT_B32 $a, $a, (i32 24)), 1699 (V_ALIGNBIT_B32 $a, $a, (i32 8))) 1700>; 1701 1702let OtherPredicates = [NoFP16Denormals] in { 1703def : GCNPat< 1704 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))), 1705 (V_MUL_F16_e64 0, (i32 CONST.FP16_ONE), $src_mods, $src, 0, 0) 1706>; 1707 1708def : GCNPat< 1709 (fcanonicalize (f16 (fneg (VOP3Mods f16:$src, i32:$src_mods)))), 1710 (V_MUL_F16_e64 0, (i32 CONST.FP16_NEG_ONE), $src_mods, $src, 0, 0) 1711>; 1712 1713def : GCNPat< 1714 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))), 1715 (V_PK_MUL_F16 0, (i32 CONST.FP16_ONE), $src_mods, $src, DSTCLAMP.NONE) 1716>; 1717} 1718 1719let OtherPredicates = [FP16Denormals] in { 1720def : GCNPat< 1721 (fcanonicalize (f16 (VOP3Mods f16:$src, i32:$src_mods))), 1722 (V_MAX_F16_e64 $src_mods, $src, $src_mods, $src, 0, 0) 1723>; 1724 1725let SubtargetPredicate = HasVOP3PInsts in { 1726def : GCNPat< 1727 (fcanonicalize (v2f16 (VOP3PMods v2f16:$src, i32:$src_mods))), 1728 (V_PK_MAX_F16 $src_mods, $src, $src_mods, $src, DSTCLAMP.NONE) 1729>; 1730} 1731} 1732 1733let OtherPredicates = [NoFP32Denormals] in { 1734def : GCNPat< 1735 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))), 1736 (V_MUL_F32_e64 0, (i32 CONST.FP32_ONE), $src_mods, $src, 0, 0) 1737>; 1738 1739def : GCNPat< 1740 (fcanonicalize (f32 (fneg (VOP3Mods f32:$src, i32:$src_mods)))), 1741 (V_MUL_F32_e64 0, (i32 CONST.FP32_NEG_ONE), $src_mods, $src, 0, 0) 1742>; 1743} 1744 1745let OtherPredicates = [FP32Denormals] in { 1746def : GCNPat< 1747 (fcanonicalize (f32 (VOP3Mods f32:$src, i32:$src_mods))), 1748 (V_MAX_F32_e64 $src_mods, $src, $src_mods, $src, 0, 0) 1749>; 1750} 1751 1752let OtherPredicates = [NoFP64Denormals] in { 1753def : GCNPat< 1754 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))), 1755 (V_MUL_F64 0, CONST.FP64_ONE, $src_mods, $src, 0, 0) 1756>; 1757} 1758 1759let OtherPredicates = [FP64Denormals] in { 1760def : GCNPat< 1761 (fcanonicalize (f64 (VOP3Mods f64:$src, i32:$src_mods))), 1762 (V_MAX_F64 $src_mods, $src, $src_mods, $src, 0, 0) 1763>; 1764} 1765 1766let OtherPredicates = [HasDLInsts] in { 1767def : GCNPat < 1768 (fma (f32 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)), 1769 (f32 (VOP3Mods f32:$src1, i32:$src1_modifiers)), 1770 (f32 (VOP3NoMods f32:$src2))), 1771 (V_FMAC_F32_e64 $src0_modifiers, $src0, $src1_modifiers, $src1, 1772 SRCMODS.NONE, $src2, $clamp, $omod) 1773>; 1774} // End OtherPredicates = [HasDLInsts] 1775 1776let SubtargetPredicate = isGFX10Plus in 1777def : GCNPat < 1778 (fma (f16 (VOP3Mods0 f32:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)), 1779 (f16 (VOP3Mods f32:$src1, i32:$src1_modifiers)), 1780 (f16 (VOP3NoMods f32:$src2))), 1781 (V_FMAC_F16_e64 $src0_modifiers, $src0, $src1_modifiers, $src1, 1782 SRCMODS.NONE, $src2, $clamp, $omod) 1783>; 1784 1785// Allow integer inputs 1786class ExpPattern<SDPatternOperator node, ValueType vt, Instruction Inst> : GCNPat< 1787 (node (i8 timm:$tgt), (i8 timm:$en), vt:$src0, vt:$src1, vt:$src2, vt:$src3, (i1 timm:$compr), (i1 timm:$vm)), 1788 (Inst i8:$tgt, vt:$src0, vt:$src1, vt:$src2, vt:$src3, i1:$vm, i1:$compr, i8:$en) 1789>; 1790 1791def : ExpPattern<AMDGPUexport, i32, EXP>; 1792def : ExpPattern<AMDGPUexport_done, i32, EXP_DONE>; 1793 1794// COPY is workaround tablegen bug from multiple outputs 1795// from S_LSHL_B32's multiple outputs from implicit scc def. 1796def : GCNPat < 1797 (v2i16 (build_vector (i16 0), (i16 SReg_32:$src1))), 1798 (S_LSHL_B32 SReg_32:$src1, (i16 16)) 1799>; 1800 1801def : GCNPat < 1802 (v2i16 (build_vector (i16 SReg_32:$src0), (i16 undef))), 1803 (COPY_TO_REGCLASS SReg_32:$src0, SReg_32) 1804>; 1805 1806def : GCNPat < 1807 (v2i16 (build_vector (i16 VGPR_32:$src0), (i16 undef))), 1808 (COPY_TO_REGCLASS VGPR_32:$src0, VGPR_32) 1809>; 1810 1811def : GCNPat < 1812 (v2f16 (build_vector f16:$src0, (f16 undef))), 1813 (COPY $src0) 1814>; 1815 1816def : GCNPat < 1817 (v2i16 (build_vector (i16 undef), (i16 SReg_32:$src1))), 1818 (S_LSHL_B32 SReg_32:$src1, (i32 16)) 1819>; 1820 1821def : GCNPat < 1822 (v2f16 (build_vector (f16 undef), (f16 SReg_32:$src1))), 1823 (S_LSHL_B32 SReg_32:$src1, (i32 16)) 1824>; 1825 1826let SubtargetPredicate = HasVOP3PInsts in { 1827def : GCNPat < 1828 (v2i16 (build_vector (i16 SReg_32:$src0), (i16 SReg_32:$src1))), 1829 (S_PACK_LL_B32_B16 SReg_32:$src0, SReg_32:$src1) 1830>; 1831 1832// With multiple uses of the shift, this will duplicate the shift and 1833// increase register pressure. 1834def : GCNPat < 1835 (v2i16 (build_vector (i16 SReg_32:$src0), (i16 (trunc (srl_oneuse SReg_32:$src1, (i32 16)))))), 1836 (v2i16 (S_PACK_LH_B32_B16 SReg_32:$src0, SReg_32:$src1)) 1837>; 1838 1839 1840def : GCNPat < 1841 (v2i16 (build_vector (i16 (trunc (srl_oneuse SReg_32:$src0, (i32 16)))), 1842 (i16 (trunc (srl_oneuse SReg_32:$src1, (i32 16)))))), 1843 (S_PACK_HH_B32_B16 SReg_32:$src0, SReg_32:$src1) 1844>; 1845 1846// TODO: Should source modifiers be matched to v_pack_b32_f16? 1847def : GCNPat < 1848 (v2f16 (build_vector (f16 SReg_32:$src0), (f16 SReg_32:$src1))), 1849 (S_PACK_LL_B32_B16 SReg_32:$src0, SReg_32:$src1) 1850>; 1851 1852} // End SubtargetPredicate = HasVOP3PInsts 1853 1854 1855def : GCNPat < 1856 (v2f16 (scalar_to_vector f16:$src0)), 1857 (COPY $src0) 1858>; 1859 1860def : GCNPat < 1861 (v2i16 (scalar_to_vector i16:$src0)), 1862 (COPY $src0) 1863>; 1864 1865def : GCNPat < 1866 (v4i16 (scalar_to_vector i16:$src0)), 1867 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0) 1868>; 1869 1870def : GCNPat < 1871 (v4f16 (scalar_to_vector f16:$src0)), 1872 (INSERT_SUBREG (IMPLICIT_DEF), $src0, sub0) 1873>; 1874 1875def : GCNPat < 1876 (i64 (int_amdgcn_mov_dpp i64:$src, timm:$dpp_ctrl, timm:$row_mask, timm:$bank_mask, 1877 timm:$bound_ctrl)), 1878 (V_MOV_B64_DPP_PSEUDO $src, $src, (as_i32imm $dpp_ctrl), 1879 (as_i32imm $row_mask), (as_i32imm $bank_mask), 1880 (as_i1imm $bound_ctrl)) 1881>; 1882 1883def : GCNPat < 1884 (i64 (int_amdgcn_update_dpp i64:$old, i64:$src, timm:$dpp_ctrl, timm:$row_mask, 1885 timm:$bank_mask, timm:$bound_ctrl)), 1886 (V_MOV_B64_DPP_PSEUDO $old, $src, (as_i32imm $dpp_ctrl), 1887 (as_i32imm $row_mask), (as_i32imm $bank_mask), 1888 (as_i1imm $bound_ctrl)) 1889>; 1890 1891//===----------------------------------------------------------------------===// 1892// Fract Patterns 1893//===----------------------------------------------------------------------===// 1894 1895let SubtargetPredicate = isGFX6 in { 1896 1897// V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x)) is 1898// used instead. However, SI doesn't have V_FLOOR_F64, so the most efficient 1899// way to implement it is using V_FRACT_F64. 1900// The workaround for the V_FRACT bug is: 1901// fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999) 1902 1903// Convert floor(x) to (x - fract(x)) 1904def : GCNPat < 1905 (f64 (ffloor (f64 (VOP3Mods f64:$x, i32:$mods)))), 1906 (V_ADD_F64 1907 $mods, 1908 $x, 1909 SRCMODS.NEG, 1910 (V_CNDMASK_B64_PSEUDO 1911 (V_MIN_F64 1912 SRCMODS.NONE, 1913 (V_FRACT_F64_e64 $mods, $x, DSTCLAMP.NONE, DSTOMOD.NONE), 1914 SRCMODS.NONE, 1915 (V_MOV_B64_PSEUDO 0x3fefffffffffffff), 1916 DSTCLAMP.NONE, DSTOMOD.NONE), 1917 $x, 1918 (V_CMP_CLASS_F64_e64 SRCMODS.NONE, $x, (i32 3 /*NaN*/))), 1919 DSTCLAMP.NONE, DSTOMOD.NONE) 1920>; 1921 1922} // End SubtargetPredicates = isGFX6 1923 1924//============================================================================// 1925// Miscellaneous Optimization Patterns 1926//============================================================================// 1927 1928// Undo sub x, c -> add x, -c canonicalization since c is more likely 1929// an inline immediate than -c. 1930// TODO: Also do for 64-bit. 1931def : GCNPat< 1932 (add i32:$src0, (i32 NegSubInlineConst32:$src1)), 1933 (S_SUB_I32 SReg_32:$src0, NegSubInlineConst32:$src1) 1934>; 1935 1936def : GCNPat< 1937 (add i32:$src0, (i32 NegSubInlineConst32:$src1)), 1938 (V_SUB_U32_e64 VS_32:$src0, NegSubInlineConst32:$src1)> { 1939 let SubtargetPredicate = HasAddNoCarryInsts; 1940} 1941 1942def : GCNPat< 1943 (add i32:$src0, (i32 NegSubInlineConst32:$src1)), 1944 (V_SUB_I32_e64 VS_32:$src0, NegSubInlineConst32:$src1)> { 1945 let SubtargetPredicate = NotHasAddNoCarryInsts; 1946} 1947 1948 1949// Avoid pointlessly materializing a constant in VGPR. 1950// FIXME: Should also do this for readlane, but tablegen crashes on 1951// the ignored src1. 1952def : GCNPat< 1953 (int_amdgcn_readfirstlane (i32 imm:$src)), 1954 (S_MOV_B32 SReg_32:$src) 1955>; 1956 1957multiclass BFMPatterns <ValueType vt, InstSI BFM, InstSI MOV> { 1958 def : GCNPat < 1959 (vt (shl (vt (add (vt (shl 1, vt:$a)), -1)), vt:$b)), 1960 (BFM $a, $b) 1961 >; 1962 1963 def : GCNPat < 1964 (vt (add (vt (shl 1, vt:$a)), -1)), 1965 (BFM $a, (MOV (i32 0))) 1966 >; 1967} 1968 1969defm : BFMPatterns <i32, S_BFM_B32, S_MOV_B32>; 1970// FIXME: defm : BFMPatterns <i64, S_BFM_B64, S_MOV_B64>; 1971 1972defm : BFEPattern <V_BFE_U32, V_BFE_I32, S_MOV_B32>; 1973defm : SHA256MaPattern <V_BFI_B32, V_XOR_B32_e64, SReg_64>; 1974 1975multiclass IntMed3Pat<Instruction med3Inst, 1976 SDPatternOperator min, 1977 SDPatternOperator max, 1978 SDPatternOperator min_oneuse, 1979 SDPatternOperator max_oneuse> { 1980 1981 // This matches 16 permutations of 1982 // min(max(a, b), max(min(a, b), c)) 1983 def : AMDGPUPat < 1984 (min (max_oneuse i32:$src0, i32:$src1), 1985 (max_oneuse (min_oneuse i32:$src0, i32:$src1), i32:$src2)), 1986 (med3Inst VSrc_b32:$src0, VSrc_b32:$src1, VSrc_b32:$src2) 1987>; 1988 1989 // This matches 16 permutations of 1990 // max(min(x, y), min(max(x, y), z)) 1991 def : AMDGPUPat < 1992 (max (min_oneuse i32:$src0, i32:$src1), 1993 (min_oneuse (max_oneuse i32:$src0, i32:$src1), i32:$src2)), 1994 (med3Inst VSrc_b32:$src0, VSrc_b32:$src1, VSrc_b32:$src2) 1995>; 1996} 1997 1998defm : IntMed3Pat<V_MED3_I32, smin, smax, smin_oneuse, smax_oneuse>; 1999defm : IntMed3Pat<V_MED3_U32, umin, umax, umin_oneuse, umax_oneuse>; 2000 2001// This matches 16 permutations of 2002// max(min(x, y), min(max(x, y), z)) 2003class FPMed3Pat<ValueType vt, 2004 //SDPatternOperator max, SDPatternOperator min, 2005 Instruction med3Inst> : GCNPat< 2006 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods), 2007 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)), 2008 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods), 2009 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)), 2010 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))), 2011 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE, DSTOMOD.NONE) 2012>; 2013 2014class FP16Med3Pat<ValueType vt, 2015 Instruction med3Inst> : GCNPat< 2016 (fmaxnum_like (fminnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods), 2017 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)), 2018 (fminnum_like_oneuse (fmaxnum_like_oneuse (VOP3Mods_nnan vt:$src0, i32:$src0_mods), 2019 (VOP3Mods_nnan vt:$src1, i32:$src1_mods)), 2020 (vt (VOP3Mods_nnan vt:$src2, i32:$src2_mods)))), 2021 (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE) 2022>; 2023 2024multiclass Int16Med3Pat<Instruction med3Inst, 2025 SDPatternOperator min, 2026 SDPatternOperator max, 2027 SDPatternOperator max_oneuse, 2028 SDPatternOperator min_oneuse> { 2029 // This matches 16 permutations of 2030 // max(min(x, y), min(max(x, y), z)) 2031 def : GCNPat < 2032 (max (min_oneuse i16:$src0, i16:$src1), 2033 (min_oneuse (max_oneuse i16:$src0, i16:$src1), i16:$src2)), 2034 (med3Inst SRCMODS.NONE, VSrc_b16:$src0, SRCMODS.NONE, VSrc_b16:$src1, SRCMODS.NONE, VSrc_b16:$src2, DSTCLAMP.NONE) 2035>; 2036 2037 // This matches 16 permutations of 2038 // min(max(a, b), max(min(a, b), c)) 2039 def : GCNPat < 2040 (min (max_oneuse i16:$src0, i16:$src1), 2041 (max_oneuse (min_oneuse i16:$src0, i16:$src1), i16:$src2)), 2042 (med3Inst SRCMODS.NONE, VSrc_b16:$src0, SRCMODS.NONE, VSrc_b16:$src1, SRCMODS.NONE, VSrc_b16:$src2, DSTCLAMP.NONE) 2043>; 2044} 2045 2046def : FPMed3Pat<f32, V_MED3_F32>; 2047 2048let OtherPredicates = [isGFX9Plus] in { 2049def : FP16Med3Pat<f16, V_MED3_F16>; 2050defm : Int16Med3Pat<V_MED3_I16, smin, smax, smax_oneuse, smin_oneuse>; 2051defm : Int16Med3Pat<V_MED3_U16, umin, umax, umax_oneuse, umin_oneuse>; 2052} // End Predicates = [isGFX9Plus] 2053 2054class AMDGPUGenericInstruction : GenericInstruction { 2055 let Namespace = "AMDGPU"; 2056} 2057 2058def G_AMDGPU_FFBH_U32 : AMDGPUGenericInstruction { 2059 let OutOperandList = (outs type0:$dst); 2060 let InOperandList = (ins type1:$src); 2061 let hasSideEffects = 0; 2062} 2063 2064// Atomic cmpxchg. $cmpval ad $newval are packed in a single vector 2065// operand Expects a MachineMemOperand in addition to explicit 2066// operands. 2067def G_AMDGPU_ATOMIC_CMPXCHG : AMDGPUGenericInstruction { 2068 let OutOperandList = (outs type0:$oldval); 2069 let InOperandList = (ins ptype1:$addr, type0:$cmpval_nnenwval); 2070 let hasSideEffects = 0; 2071 let mayLoad = 1; 2072 let mayStore = 1; 2073} 2074