43 #ifdef EXPENSIVE_CHECKS 58 #define DEBUG_TYPE "isel" 74 static bool isNullConstantOrUndef(
SDValue V) {
91 Out =
C->getAPIntValue().getSExtValue();
96 Out =
C->getValueAPF().bitcastToAPInt().getSExtValue();
105 bool Negate =
false) {
108 if (getConstantValue(N->
getOperand(0), LHSVal) &&
112 (-LHSVal & 0xffff) | (-RHSVal << 16) :
113 (LHSVal & 0xffff) | (RHSVal << 16);
122 return packConstantV2I16(N, DAG,
true);
133 AMDGPU::SIModeRegisterDefaults
Mode;
135 bool EnableLateStructurizeCFG;
143 ~AMDGPUDAGToDAGISel()
override =
default;
148 #ifdef EXPENSIVE_CHECKS 155 bool matchLoadD16FromBuildVector(
SDNode *N)
const;
158 void PreprocessISelDAG()
override;
161 void PostprocessISelDAG()
override;
164 void SelectBuildVector(
SDNode *N,
unsigned RegClassID);
167 std::pair<SDValue, SDValue> foldFrameIndex(
SDValue N)
const;
168 bool isNoNanSrc(
SDValue N)
const;
169 bool isInlineImmediate(
const SDNode *N,
bool Negated =
false)
const;
170 bool isNegInlineImmediate(
const SDNode *N)
const {
171 return isInlineImmediate(N,
true);
174 bool isInlineImmediate16(int64_t Imm)
const {
178 bool isInlineImmediate32(int64_t Imm)
const {
182 bool isInlineImmediate64(int64_t Imm)
const {
186 bool isInlineImmediate(
const APFloat &Imm)
const {
190 bool isVGPRImm(
const SDNode *N)
const;
191 bool isUniformLoad(
const SDNode *N)
const;
192 bool isUniformBr(
const SDNode *N)
const;
203 bool isDSOffsetLegal(
SDValue Base,
unsigned Offset,
204 unsigned OffsetBits)
const;
219 bool SelectMUBUFScratchOffen(
SDNode *Parent,
222 bool SelectMUBUFScratchOffset(
SDNode *Parent,
234 template <
bool IsSigned>
256 bool SelectVOP3ModsImpl(
SDValue In,
SDValue &Src,
unsigned &SrcMods)
const;
278 bool SelectVOP3PMadMixModsImpl(
SDValue In,
SDValue &Src,
unsigned &Mods)
const;
283 SDValue getMaterializedScalarImm32(int64_t Val,
const SDLoc &DL)
const;
285 void SelectADD_SUB_I64(
SDNode *N);
286 void SelectAddcSubb(
SDNode *N);
287 void SelectUADDO_USUBO(
SDNode *N);
288 void SelectDIV_SCALE(
SDNode *N);
289 void SelectDIV_FMAS(
SDNode *N);
290 void SelectMAD_64_32(
SDNode *N);
291 void SelectFMA_W_CHAIN(
SDNode *N);
292 void SelectFMUL_W_CHAIN(
SDNode *N);
296 void SelectS_BFEFromShifts(
SDNode *N);
297 void SelectS_BFE(
SDNode *N);
298 bool isCBranchSCC(
const SDNode *N)
const;
299 void SelectBRCOND(
SDNode *N);
300 void SelectFMAD_FMA(
SDNode *N);
301 void SelectATOMIC_CMP_SWAP(
SDNode *N);
302 void SelectDSAppendConsume(
SDNode *N,
unsigned IntrID);
303 void SelectDS_GWS(
SDNode *N,
unsigned IntrID);
304 void SelectINTRINSIC_W_CHAIN(
SDNode *N);
305 void SelectINTRINSIC_WO_CHAIN(
SDNode *N);
306 void SelectINTRINSIC_VOID(
SDNode *N);
310 #include "AMDGPUGenDAGISel.inc" 313 class R600DAGToDAGISel :
public AMDGPUDAGToDAGISel {
316 bool isConstantLoad(
const MemSDNode *N,
int cbID)
const;
317 bool SelectGlobalValueConstantOffset(
SDValue Addr,
SDValue& IntPtr);
318 bool SelectGlobalValueVariableOffset(
SDValue Addr,
SDValue &BaseReg,
322 AMDGPUDAGToDAGISel(TM, OptLevel) {}
333 void PreprocessISelDAG()
override {}
337 #include "R600GenDAGISel.inc" 346 In = stripBitcast(In);
353 if (ShiftAmt->getZExtValue() == 16) {
369 return stripBitcast(Src);
378 "AMDGPU DAG->DAG Pattern Instruction Selection",
false,
false)
382 #ifdef EXPENSIVE_CHECKS 387 "AMDGPU DAG->DAG Pattern Instruction Selection",
false,
false)
392 CodeGenOpt::
Level OptLevel) {
393 return new AMDGPUDAGToDAGISel(TM, OptLevel);
400 return new R600DAGToDAGISel(TM, OptLevel);
404 #ifdef EXPENSIVE_CHECKS 405 DominatorTree & DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
406 LoopInfo * LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
408 assert(L->isLCSSAForm(DT));
416 bool AMDGPUDAGToDAGISel::matchLoadD16FromBuildVector(
SDNode *
N)
const {
417 assert(Subtarget->d16PreservesUnusedBits());
450 CurDAG->getMemIntrinsicNode(LoadOp,
SDLoc(LdHi), VTList,
454 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), NewLoadHi);
455 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(LdHi, 1), NewLoadHi.
getValue(1));
464 SDValue TiedIn = getHi16Elt(Hi);
484 CurDAG->getMemIntrinsicNode(LoadOp,
SDLoc(LdLo), VTList,
488 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), NewLoadLo);
489 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(LdLo, 1), NewLoadLo.
getValue(1));
496 void AMDGPUDAGToDAGISel::PreprocessISelDAG() {
497 if (!Subtarget->d16PreservesUnusedBits())
502 bool MadeChange =
false;
503 while (Position != CurDAG->allnodes_begin()) {
510 MadeChange |= matchLoadD16FromBuildVector(N);
518 CurDAG->RemoveDeadNodes();
524 bool AMDGPUDAGToDAGISel::isNoNanSrc(
SDValue N)
const {
525 if (
TM.Options.NoNaNsFPMath)
532 return CurDAG->isKnownNeverNaN(N);
535 bool AMDGPUDAGToDAGISel::isInlineImmediate(
const SDNode *N,
536 bool Negated)
const {
564 unsigned OpNo)
const {
592 return Subtarget->getRegisterInfo()->getRegClass(RegClass);
594 case AMDGPU::REG_SEQUENCE: {
595 unsigned RCID = cast<ConstantSDNode>(N->
getOperand(0))->getZExtValue();
597 Subtarget->getRegisterInfo()->getRegClass(RCID);
600 unsigned SubRegIdx = cast<ConstantSDNode>(SubRegOp)->getZExtValue();
601 return Subtarget->getRegisterInfo()->getSubClassWithSubReg(SuperRC,
625 return glueCopyToOp(N, M0, M0.getValue(1));
628 SDNode *AMDGPUDAGToDAGISel::glueCopyToM0LDSInit(
SDNode *N)
const {
629 unsigned AS = cast<MemSDNode>(
N)->getAddressSpace();
631 if (Subtarget->ldsRequiresM0Init())
632 return glueCopyToM0(N, CurDAG->getTargetConstant(-1,
SDLoc(N),
MVT::i32));
637 glueCopyToM0(N, CurDAG->getTargetConstant(Value,
SDLoc(N),
MVT::i32));
644 SDNode *
Lo = CurDAG->getMachineNode(
646 CurDAG->getTargetConstant(Imm & 0xFFFFFFFF, DL,
MVT::i32));
648 CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL,
MVT::i32,
649 CurDAG->getTargetConstant(Imm >> 32, DL,
MVT::i32));
651 CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, DL,
MVT::i32),
653 SDValue(Hi, 0), CurDAG->getTargetConstant(AMDGPU::sub1, DL,
MVT::i32)};
655 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL, VT, Ops);
659 switch (NumVectorElts) {
661 return AMDGPU::SReg_32RegClassID;
663 return AMDGPU::SReg_64RegClassID;
665 return AMDGPU::SGPR_96RegClassID;
667 return AMDGPU::SGPR_128RegClassID;
669 return AMDGPU::SGPR_160RegClassID;
671 return AMDGPU::SReg_256RegClassID;
673 return AMDGPU::SReg_512RegClassID;
675 return AMDGPU::SReg_1024RegClassID;
681 void AMDGPUDAGToDAGISel::SelectBuildVector(
SDNode *N,
unsigned RegClassID) {
686 SDValue RegClass = CurDAG->getTargetConstant(RegClassID, DL,
MVT::i32);
688 if (NumVectorElts == 1) {
689 CurDAG->SelectNodeTo(N, AMDGPU::COPY_TO_REGCLASS, EltVT, N->
getOperand(0),
694 assert(NumVectorElts <= 32 &&
"Vectors with more than 32 elements not " 701 RegSeqArgs[0] = CurDAG->getTargetConstant(RegClassID, DL,
MVT::i32);
702 bool IsRegSeq =
true;
704 for (
unsigned i = 0; i < NOps; i++) {
712 RegSeqArgs[1 + (2 * i) + 1] = CurDAG->getTargetConstant(Sub, DL,
MVT::i32);
714 if (NOps != NumVectorElts) {
717 MachineSDNode *ImpDef = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
719 for (
unsigned i = NOps; i < NumVectorElts; ++i) {
721 RegSeqArgs[1 + (2 * i)] =
SDValue(ImpDef, 0);
722 RegSeqArgs[1 + (2 * i) + 1] =
723 CurDAG->getTargetConstant(Sub, DL,
MVT::i32);
729 CurDAG->SelectNodeTo(N, AMDGPU::REG_SEQUENCE, N->
getVTList(), RegSeqArgs);
746 N = glueCopyToM0LDSInit(N);
764 SelectADD_SUB_I64(N);
776 SelectUADDO_USUBO(N);
780 SelectFMUL_W_CHAIN(N);
784 SelectFMA_W_CHAIN(N);
794 if (
SDNode *Packed = packConstantV2I16(N, *CurDAG)) {
795 ReplaceNode(N, Packed);
805 SelectBuildVector(N, RegClassID);
812 RC = CurDAG->getTargetConstant(AMDGPU::SGPR_128RegClassID, DL,
MVT::i32);
813 SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0_sub1, DL,
MVT::i32);
814 SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub2_sub3, DL,
MVT::i32);
816 RC = CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, DL,
MVT::i32);
817 SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0, DL,
MVT::i32);
818 SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub1, DL,
MVT::i32);
824 ReplaceNode(N, CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL,
836 Imm = FP->getValueAPF().bitcastToAPInt().getZExtValue();
843 ReplaceNode(N, buildSMovImm64(DL, Imm, N->
getValueType(0)));
869 ReplaceNode(N, getS_BFE(Signed ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32,
909 SelectATOMIC_CMP_SWAP(N);
919 N = CurDAG->MorphNodeTo(N, N->
getOpcode(), CurDAG->getVTList(NewVT),
928 SelectINTRINSIC_W_CHAIN(N);
932 SelectINTRINSIC_WO_CHAIN(N);
936 SelectINTRINSIC_VOID(N);
944 bool AMDGPUDAGToDAGISel::isUniformBr(
const SDNode *N)
const {
945 const BasicBlock *BB = FuncInfo->MBB->getBasicBlock();
951 StringRef AMDGPUDAGToDAGISel::getPassName()
const {
952 return "AMDGPU DAG->DAG Pattern Instruction Selection";
964 bool AMDGPUDAGToDAGISel::SelectADDRIndirect(
SDValue Addr,
SDValue &Base,
969 if ((C = dyn_cast<ConstantSDNode>(Addr))) {
970 Base = CurDAG->getRegister(R600::INDIRECT_BASE_ADDR,
MVT::i32);
973 (C = dyn_cast<ConstantSDNode>(Addr.
getOperand(0)))) {
974 Base = CurDAG->getRegister(R600::INDIRECT_BASE_ADDR,
MVT::i32);
977 (C = dyn_cast<ConstantSDNode>(Addr.
getOperand(1)))) {
982 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
988 SDValue AMDGPUDAGToDAGISel::getMaterializedScalarImm32(int64_t Val,
989 const SDLoc &DL)
const {
990 SDNode *Mov = CurDAG->getMachineNode(
992 CurDAG->getTargetConstant(Val, DL,
MVT::i32));
997 void AMDGPUDAGToDAGISel::SelectADD_SUB_I64(
SDNode *N) {
1011 SDNode *Lo0 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
1013 SDNode *Hi0 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
1016 SDNode *Lo1 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
1018 SDNode *Hi1 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
1023 unsigned Opc = IsAdd ? AMDGPU::S_ADD_U32 : AMDGPU::S_SUB_U32;
1024 unsigned CarryOpc = IsAdd ? AMDGPU::S_ADDC_U32 : AMDGPU::S_SUBB_U32;
1027 if (!ConsumeCarry) {
1029 AddLo = CurDAG->getMachineNode(Opc, DL, VTList, Args);
1032 AddLo = CurDAG->getMachineNode(CarryOpc, DL, VTList, Args);
1039 SDNode *AddHi = CurDAG->getMachineNode(CarryOpc, DL, VTList, AddHiArgs);
1042 CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, DL,
MVT::i32),
1057 ReplaceNode(N, RegSequence);
1060 void AMDGPUDAGToDAGISel::SelectAddcSubb(
SDNode *N) {
1067 : AMDGPU::V_SUBB_U32_e64;
1068 CurDAG->SelectNodeTo(
1070 {LHS, RHS, CI, CurDAG->getTargetConstant(0, {},
MVT::i1) });
1073 void AMDGPUDAGToDAGISel::SelectUADDO_USUBO(
SDNode *N) {
1078 AMDGPU::V_ADD_I32_e64 : AMDGPU::V_SUB_I32_e64;
1080 CurDAG->SelectNodeTo(
1083 CurDAG->getTargetConstant(0, {},
MVT::i1) });
1086 void AMDGPUDAGToDAGISel::SelectFMA_W_CHAIN(
SDNode *N) {
1091 SelectVOP3Mods0(N->
getOperand(1), Ops[1], Ops[0], Ops[6], Ops[7]);
1092 SelectVOP3Mods(N->
getOperand(2), Ops[3], Ops[2]);
1093 SelectVOP3Mods(N->
getOperand(3), Ops[5], Ops[4]);
1097 CurDAG->SelectNodeTo(N, AMDGPU::V_FMA_F32, N->
getVTList(), Ops);
1100 void AMDGPUDAGToDAGISel::SelectFMUL_W_CHAIN(
SDNode *N) {
1105 SelectVOP3Mods0(N->
getOperand(1), Ops[1], Ops[0], Ops[4], Ops[5]);
1106 SelectVOP3Mods(N->
getOperand(2), Ops[3], Ops[2]);
1110 CurDAG->SelectNodeTo(N, AMDGPU::V_MUL_F32_e64, N->
getVTList(), Ops);
1115 void AMDGPUDAGToDAGISel::SelectDIV_SCALE(
SDNode *N) {
1122 = (VT ==
MVT::f64) ? AMDGPU::V_DIV_SCALE_F64 : AMDGPU::V_DIV_SCALE_F32;
1125 CurDAG->SelectNodeTo(N, Opc, N->
getVTList(), Ops);
1128 void AMDGPUDAGToDAGISel::SelectDIV_FMAS(
SDNode *N) {
1138 = (VT ==
MVT::f64) ? AMDGPU::V_DIV_FMAS_F64 : AMDGPU::V_DIV_FMAS_F32;
1142 SDValue VCC = CurDAG->getCopyToReg(CurDAG->getEntryNode(), SL,
1147 SelectVOP3Mods0(N->
getOperand(0), Ops[1], Ops[0], Ops[6], Ops[7]);
1148 SelectVOP3Mods(N->
getOperand(1), Ops[3], Ops[2]);
1149 SelectVOP3Mods(N->
getOperand(2), Ops[5], Ops[4]);
1154 CurDAG->SelectNodeTo(N, Opc, N->
getVTList(), Ops);
1159 void AMDGPUDAGToDAGISel::SelectMAD_64_32(
SDNode *N) {
1162 unsigned Opc = Signed ? AMDGPU::V_MAD_I64_I32 : AMDGPU::V_MAD_U64_U32;
1167 CurDAG->SelectNodeTo(N, Opc, N->
getVTList(), Ops);
1170 bool AMDGPUDAGToDAGISel::isDSOffsetLegal(
SDValue Base,
unsigned Offset,
1171 unsigned OffsetBits)
const {
1172 if ((OffsetBits == 16 && !
isUInt<16>(Offset)) ||
1173 (OffsetBits == 8 && !
isUInt<8>(Offset)))
1176 if (Subtarget->hasUsableDSOffset() ||
1177 Subtarget->unsafeDSOffsetFoldingEnabled())
1182 return CurDAG->SignBitIsZero(Base);
1185 bool AMDGPUDAGToDAGISel::SelectDS1Addr1Offset(
SDValue Addr,
SDValue &Base,
1188 if (CurDAG->isBaseWithConstantOffset(Addr)) {
1201 int64_t ByteOffset =
C->getSExtValue();
1211 if (isDSOffsetLegal(Sub, ByteOffset, 16)) {
1217 unsigned SubOp = AMDGPU::V_SUB_I32_e32;
1218 if (Subtarget->hasAddNoCarry()) {
1219 SubOp = AMDGPU::V_SUB_U32_e64;
1221 CurDAG->getTargetConstant(0, {},
MVT::i1));
1225 CurDAG->getMachineNode(SubOp, DL,
MVT::i32, Opnds);
1227 Base =
SDValue(MachineSub, 0);
1228 Offset = CurDAG->getTargetConstant(ByteOffset, DL,
MVT::i16);
1233 }
else if (
const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
1243 MachineSDNode *MovZero = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
1246 Offset = CurDAG->getTargetConstant(CAddr->getZExtValue(), DL,
MVT::i16);
1253 Offset = CurDAG->getTargetConstant(0,
SDLoc(Addr),
MVT::i16);
1258 bool AMDGPUDAGToDAGISel::SelectDS64Bit4ByteAligned(
SDValue Addr,
SDValue &Base,
1263 if (CurDAG->isBaseWithConstantOffset(Addr)) {
1268 unsigned DWordOffset1 = DWordOffset0 + 1;
1270 if (isDSOffsetLegal(N0, DWordOffset1, 8)) {
1272 Offset0 = CurDAG->getTargetConstant(DWordOffset0, DL,
MVT::i8);
1273 Offset1 = CurDAG->getTargetConstant(DWordOffset1, DL,
MVT::i8);
1279 unsigned DWordOffset0 =
C->getZExtValue() / 4;
1280 unsigned DWordOffset1 = DWordOffset0 + 1;
1292 if (isDSOffsetLegal(Sub, DWordOffset1, 8)) {
1296 unsigned SubOp = AMDGPU::V_SUB_I32_e32;
1297 if (Subtarget->hasAddNoCarry()) {
1298 SubOp = AMDGPU::V_SUB_U32_e64;
1300 CurDAG->getTargetConstant(0, {},
MVT::i1));
1304 = CurDAG->getMachineNode(SubOp, DL,
MVT::i32, Opnds);
1306 Base =
SDValue(MachineSub, 0);
1307 Offset0 = CurDAG->getTargetConstant(DWordOffset0, DL,
MVT::i8);
1308 Offset1 = CurDAG->getTargetConstant(DWordOffset1, DL,
MVT::i8);
1313 }
else if (
const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
1314 unsigned DWordOffset0 = CAddr->getZExtValue() / 4;
1315 unsigned DWordOffset1 = DWordOffset0 + 1;
1316 assert(4 * DWordOffset0 == CAddr->getZExtValue());
1321 = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
1324 Offset0 = CurDAG->getTargetConstant(DWordOffset0, DL,
MVT::i8);
1325 Offset1 = CurDAG->getTargetConstant(DWordOffset1, DL,
MVT::i8);
1333 Offset0 = CurDAG->getTargetConstant(0, DL,
MVT::i8);
1334 Offset1 = CurDAG->getTargetConstant(1, DL,
MVT::i8);
1346 if (Subtarget->useFlatForGlobal())
1352 GLC = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1354 SLC = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1355 TFE = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1356 DLC = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1357 SWZ = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1359 Idxen = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1360 Offen = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1361 Addr64 = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1362 SOffset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
1366 if (CurDAG->isBaseWithConstantOffset(Addr)) {
1367 C1 = cast<ConstantSDNode>(Addr.
getOperand(1));
1379 Addr64 = CurDAG->getTargetConstant(1, DL,
MVT::i1);
1397 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i16);
1403 Addr64 = CurDAG->getTargetConstant(1, DL,
MVT::i1);
1407 VAddr = CurDAG->getTargetConstant(0, DL,
MVT::i32);
1413 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i16);
1424 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i16);
1426 SDValue(CurDAG->getMachineNode(
1433 bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(
SDValue Addr,
SDValue &SRsrc,
1438 SDValue Ptr, Offen, Idxen, Addr64;
1441 if (!Subtarget->hasAddr64())
1444 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
1445 GLC, SLC, TFE, DLC, SWZ))
1462 bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(
SDValue Addr,
SDValue &SRsrc,
1466 SLC = CurDAG->getTargetConstant(0,
SDLoc(Addr),
MVT::i1);
1469 return SelectMUBUFAddr64(Addr, SRsrc, VAddr, SOffset, Offset, GLC, SLC, TFE, DLC, SWZ);
1477 std::pair<SDValue, SDValue> AMDGPUDAGToDAGISel::foldFrameIndex(
SDValue N)
const {
1481 if (
auto FI = dyn_cast<FrameIndexSDNode>(N)) {
1482 SDValue TFI = CurDAG->getTargetFrameIndex(FI->getIndex(),
1483 FI->getValueType(0));
1487 return std::make_pair(
1497 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(
SDNode *Parent,
1509 unsigned Imm = CAddr->getZExtValue();
1511 SDValue HighBits = CurDAG->getTargetConstant(Imm & ~4095, DL,
MVT::i32);
1512 MachineSDNode *MovHighBits = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
1514 VAddr =
SDValue(MovHighBits, 0);
1522 SOffset = CurDAG->getRegister(SOffsetReg,
MVT::i32);
1523 ImmOffset = CurDAG->getTargetConstant(Imm & 4095, DL,
MVT::i16);
1527 if (CurDAG->isBaseWithConstantOffset(Addr)) {
1550 (!Subtarget->privateMemoryResourceIsRangeChecked() ||
1551 CurDAG->SignBitIsZero(N0))) {
1552 std::tie(VAddr, SOffset) = foldFrameIndex(N0);
1559 std::tie(VAddr, SOffset) = foldFrameIndex(Addr);
1560 ImmOffset = CurDAG->getTargetConstant(0, DL,
MVT::i16);
1564 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffset(
SDNode *Parent,
1585 SOffset = CurDAG->getRegister(SOffsetReg,
MVT::i32);
1591 bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1596 SDValue Ptr, VAddr, Offen, Idxen, Addr64;
1598 static_cast<const SIInstrInfo *
>(Subtarget->getInstrInfo());
1600 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
1601 GLC, SLC, TFE, DLC, SWZ))
1604 if (!cast<ConstantSDNode>(Offen)->getSExtValue() &&
1605 !cast<ConstantSDNode>(Idxen)->getSExtValue() &&
1606 !cast<ConstantSDNode>(Addr64)->getSExtValue()) {
1620 bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1623 SDValue GLC, SLC, TFE, DLC, SWZ;
1625 return SelectMUBUFOffset(Addr, SRsrc, Soffset, Offset, GLC, SLC, TFE, DLC, SWZ);
1627 bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1632 return SelectMUBUFOffset(Addr, SRsrc, Soffset, Offset, GLC, SLC, TFE, DLC, SWZ);
1639 if (
MemSDNode *MN = dyn_cast<MemSDNode>(N))
1641 assert(isa<BuildVectorSDNode>(N));
1649 template <
bool IsSigned>
1650 bool AMDGPUDAGToDAGISel::SelectFlatOffset(
SDNode *N,
1655 int64_t OffsetVal = 0;
1657 if (Subtarget->hasFlatInstOffsets() &&
1658 (!Subtarget->hasFlatSegmentOffsetBug() ||
1660 CurDAG->isBaseWithConstantOffset(Addr)) {
1663 uint64_t COffsetVal = cast<ConstantSDNode>(N1)->getSExtValue();
1669 OffsetVal = COffsetVal;
1685 if (static_cast<int64_t>(COffsetVal) > 0) {
1686 if (static_cast<int64_t>(ImmField) < 0) {
1687 const uint64_t OffsetMask = maskTrailingOnes<uint64_t>(NumBits - 1);
1688 ImmField = COffsetVal & OffsetMask;
1693 const uint64_t OffsetMask = maskTrailingOnes<uint64_t>(NumBits);
1694 ImmField = COffsetVal & OffsetMask;
1697 uint64_t RemainderOffset = COffsetVal - ImmField;
1700 assert(RemainderOffset + ImmField == COffsetVal);
1702 OffsetVal = ImmField;
1709 SDNode *N0Lo = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
1711 SDNode *N0Hi = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
1715 = getMaterializedScalarImm32(
Lo_32(RemainderOffset), DL);
1717 = getMaterializedScalarImm32(
Hi_32(RemainderOffset), DL);
1723 AMDGPU::V_ADD_I32_e64, DL, VTs,
1724 {AddOffsetLo,
SDValue(N0Lo, 0), Clamp});
1726 SDNode *Addc = CurDAG->getMachineNode(
1727 AMDGPU::V_ADDC_U32_e64, DL, VTs,
1731 CurDAG->getTargetConstant(AMDGPU::VReg_64RegClassID, DL,
MVT::i32),
1735 Addr =
SDValue(CurDAG->getMachineNode(AMDGPU::REG_SEQUENCE, DL,
1741 Offset = CurDAG->getTargetConstant(OffsetVal,
SDLoc(),
MVT::i16);
1746 bool AMDGPUDAGToDAGISel::SelectFlatAtomic(
SDNode *N,
1751 return SelectFlatOffset<false>(
N, Addr, VAddr,
Offset, SLC);
1754 bool AMDGPUDAGToDAGISel::SelectFlatAtomicSigned(
SDNode *N,
1759 return SelectFlatOffset<true>(
N, Addr, VAddr,
Offset, SLC);
1762 bool AMDGPUDAGToDAGISel::SelectSMRDOffset(
SDValue ByteOffsetNode,
1763 SDValue &Offset,
bool &Imm)
const {
1770 SDLoc SL(ByteOffsetNode);
1776 Offset = CurDAG->getTargetConstant(EncodedOffset, SL,
MVT::i32);
1786 Offset = CurDAG->getTargetConstant(EncodedOffset, SL,
MVT::i32);
1789 Offset =
SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL,
MVT::i32,
1796 SDValue AMDGPUDAGToDAGISel::Expand32BitAddress(
SDValue Addr)
const {
1809 CurDAG->getTargetConstant(AMDGPU::SReg_64_XEXECRegClassID, SL,
MVT::i32),
1811 CurDAG->getTargetConstant(AMDGPU::sub0, SL,
MVT::i32),
1812 SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL,
MVT::i32, AddrHi),
1814 CurDAG->getTargetConstant(AMDGPU::sub1, SL,
MVT::i32),
1817 return SDValue(CurDAG->getMachineNode(AMDGPU::REG_SEQUENCE, SL,
MVT::i64,
1821 bool AMDGPUDAGToDAGISel::SelectSMRD(
SDValue Addr,
SDValue &SBase,
1822 SDValue &Offset,
bool &Imm)
const {
1829 CurDAG->isBaseWithConstantOffset(Addr)) {
1833 if (SelectSMRDOffset(N1, Offset, Imm)) {
1834 SBase = Expand32BitAddress(N0);
1838 SBase = Expand32BitAddress(Addr);
1839 Offset = CurDAG->getTargetConstant(0, SL,
MVT::i32);
1844 bool AMDGPUDAGToDAGISel::SelectSMRDImm(
SDValue Addr,
SDValue &SBase,
1847 return SelectSMRD(Addr, SBase, Offset, Imm) && Imm;
1850 bool AMDGPUDAGToDAGISel::SelectSMRDImm32(
SDValue Addr,
SDValue &SBase,
1857 if (!SelectSMRD(Addr, SBase, Offset, Imm))
1860 return !Imm && isa<ConstantSDNode>(
Offset);
1863 bool AMDGPUDAGToDAGISel::SelectSMRDSgpr(
SDValue Addr,
SDValue &SBase,
1866 return SelectSMRD(Addr, SBase, Offset, Imm) && !Imm &&
1867 !isa<ConstantSDNode>(
Offset);
1870 bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm(
SDValue Addr,
1873 return SelectSMRDOffset(Addr, Offset, Imm) && Imm;
1876 bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm32(
SDValue Addr,
1882 if (!SelectSMRDOffset(Addr, Offset, Imm))
1885 return !Imm && isa<ConstantSDNode>(
Offset);
1888 bool AMDGPUDAGToDAGISel::SelectMOVRELOffset(
SDValue Index,
1893 if (CurDAG->isBaseWithConstantOffset(Index)) {
1901 if (C1->
getSExtValue() <= 0 || CurDAG->SignBitIsZero(N0)) {
1908 if (isa<ConstantSDNode>(Index))
1912 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
1916 SDNode *AMDGPUDAGToDAGISel::getS_BFE(
unsigned Opcode,
const SDLoc &DL,
1922 uint32_t PackedVal = Offset | (Width << 16);
1923 SDValue PackedConst = CurDAG->getTargetConstant(PackedVal, DL,
MVT::i32);
1925 return CurDAG->getMachineNode(Opcode, DL,
MVT::i32, Val, PackedConst);
1928 void AMDGPUDAGToDAGISel::SelectS_BFEFromShifts(
SDNode *N) {
1941 if (0 < BVal && BVal <= CVal && CVal < 32) {
1943 unsigned Opcode = Signed ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32;
1945 ReplaceNode(N, getS_BFE(Opcode,
SDLoc(N), Shl.
getOperand(0), CVal - BVal,
1953 void AMDGPUDAGToDAGISel::SelectS_BFE(
SDNode *N) {
1963 if (Shift && Mask) {
1965 uint32_t MaskVal = Mask->getZExtValue();
1970 ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_U32,
SDLoc(N),
1985 if (Shift && Mask) {
1987 uint32_t MaskVal = Mask->getZExtValue() >> ShiftVal;
1992 ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_U32,
SDLoc(N),
1998 SelectS_BFEFromShifts(N);
2004 SelectS_BFEFromShifts(N);
2019 unsigned Width = cast<VTSDNode>(N->
getOperand(1))->getVT().getSizeInBits();
2020 ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_I32,
SDLoc(N), Src.
getOperand(0),
2029 bool AMDGPUDAGToDAGISel::isCBranchSCC(
const SDNode *N)
const {
2046 auto ST =
static_cast<const GCNSubtarget *
>(Subtarget);
2055 void AMDGPUDAGToDAGISel::SelectBRCOND(
SDNode *N) {
2059 CurDAG->SelectNodeTo(N, AMDGPU::SI_BR_UNDEF,
MVT::Other,
2067 bool UseSCCBr = isCBranchSCC(N) && isUniformBr(N);
2068 unsigned BrOp = UseSCCBr ? AMDGPU::S_CBRANCH_SCC1 : AMDGPU::S_CBRANCH_VCCNZ;
2069 unsigned CondReg = UseSCCBr ? (
unsigned)AMDGPU::SCC : TRI->
getVCC();
2086 Cond =
SDValue(CurDAG->getMachineNode(ST->
isWave32() ? AMDGPU::S_AND_B32
2087 : AMDGPU::S_AND_B64,
2089 CurDAG->getRegister(ST->
isWave32() ? AMDGPU::EXEC_LO
2102 void AMDGPUDAGToDAGISel::SelectFMAD_FMA(
SDNode *N) {
2105 if (VT !=
MVT::f32 || (!Subtarget->hasMadMixInsts() &&
2106 !Subtarget->hasFmaMixInsts()) ||
2107 ((IsFMA && Subtarget->hasMadMixInsts()) ||
2108 (!IsFMA && Subtarget->hasFmaMixInsts()))) {
2116 unsigned Src0Mods, Src1Mods, Src2Mods;
2120 bool Sel0 = SelectVOP3PMadMixModsImpl(Src0, Src0, Src0Mods);
2121 bool Sel1 = SelectVOP3PMadMixModsImpl(Src1, Src1, Src1Mods);
2122 bool Sel2 = SelectVOP3PMadMixModsImpl(Src2, Src2, Src2Mods);
2125 "fmad selected with denormals enabled");
2129 if (Sel0 || Sel1 || Sel2) {
2133 CurDAG->getTargetConstant(Src0Mods,
SDLoc(),
MVT::i32), Src0,
2134 CurDAG->getTargetConstant(Src1Mods,
SDLoc(),
MVT::i32), Src1,
2135 CurDAG->getTargetConstant(Src2Mods,
SDLoc(),
MVT::i32), Src2,
2140 CurDAG->SelectNodeTo(N,
2141 IsFMA ? AMDGPU::V_FMA_MIX_F32 : AMDGPU::V_MAD_MIX_F32,
2150 void AMDGPUDAGToDAGISel::SelectATOMIC_CMP_SWAP(
SDNode *N) {
2163 if (Subtarget->hasAddr64()) {
2166 if (SelectMUBUFAddr64(Mem->
getBasePtr(), SRsrc, VAddr, SOffset,
Offset, SLC)) {
2167 unsigned Opcode = Is32 ? AMDGPU::BUFFER_ATOMIC_CMPSWAP_ADDR64_RTN :
2168 AMDGPU::BUFFER_ATOMIC_CMPSWAP_X2_ADDR64_RTN;
2177 CmpSwap = CurDAG->getMachineNode(Opcode, SL, Mem->
getVTList(), Ops);
2184 unsigned Opcode = Is32 ? AMDGPU::BUFFER_ATOMIC_CMPSWAP_OFFSET_RTN :
2185 AMDGPU::BUFFER_ATOMIC_CMPSWAP_X2_OFFSET_RTN;
2192 CmpSwap = CurDAG->getMachineNode(Opcode, SL, Mem->
getVTList(), Ops);
2202 CurDAG->setNodeMemRefs(CmpSwap, {MMO});
2204 unsigned SubReg = Is32 ? AMDGPU::sub0 : AMDGPU::sub0_sub1;
2206 = CurDAG->getTargetExtractSubreg(SubReg, SL, VT,
SDValue(CmpSwap, 0));
2208 ReplaceUses(
SDValue(N, 0), Extract);
2210 CurDAG->RemoveDeadNode(N);
2213 void AMDGPUDAGToDAGISel::SelectDSAppendConsume(
SDNode *N,
unsigned IntrID) {
2216 unsigned Opc = IntrID == Intrinsic::amdgcn_ds_append ?
2217 AMDGPU::DS_APPEND : AMDGPU::DS_CONSUME;
2226 if (CurDAG->isBaseWithConstantOffset(Ptr)) {
2230 const APInt &OffsetVal = cast<ConstantSDNode>(PtrOffset)->getAPIntValue();
2231 if (isDSOffsetLegal(PtrBase, OffsetVal.
getZExtValue(), 16)) {
2232 N = glueCopyToM0(N, PtrBase);
2233 Offset = CurDAG->getTargetConstant(OffsetVal,
SDLoc(),
MVT::i32);
2238 N = glueCopyToM0(N, Ptr);
2250 CurDAG->setNodeMemRefs(cast<MachineSDNode>(Selected), {MMO});
2255 case Intrinsic::amdgcn_ds_gws_init:
2256 return AMDGPU::DS_GWS_INIT;
2257 case Intrinsic::amdgcn_ds_gws_barrier:
2258 return AMDGPU::DS_GWS_BARRIER;
2259 case Intrinsic::amdgcn_ds_gws_sema_v:
2260 return AMDGPU::DS_GWS_SEMA_V;
2261 case Intrinsic::amdgcn_ds_gws_sema_br:
2262 return AMDGPU::DS_GWS_SEMA_BR;
2263 case Intrinsic::amdgcn_ds_gws_sema_p:
2264 return AMDGPU::DS_GWS_SEMA_P;
2265 case Intrinsic::amdgcn_ds_gws_sema_release_all:
2266 return AMDGPU::DS_GWS_SEMA_RELEASE_ALL;
2272 void AMDGPUDAGToDAGISel::SelectDS_GWS(
SDNode *N,
unsigned IntrID) {
2273 if (IntrID == Intrinsic::amdgcn_ds_gws_sema_release_all &&
2274 !Subtarget->hasGWSSemaReleaseAll()) {
2296 if (
ConstantSDNode *ConstOffset = dyn_cast<ConstantSDNode>(BaseOffset)) {
2301 glueCopyToM0(N, CurDAG->getTargetConstant(0, SL,
MVT::i32));
2302 ImmOffset = ConstOffset->getZExtValue();
2304 if (CurDAG->isBaseWithConstantOffset(BaseOffset)) {
2313 = CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL,
MVT::i32,
2317 = CurDAG->getMachineNode(AMDGPU::S_LSHL_B32, SL,
MVT::i32,
2319 CurDAG->getTargetConstant(16, SL,
MVT::i32));
2320 glueCopyToM0(N,
SDValue(M0Base, 0));
2324 SDValue OffsetField = CurDAG->getTargetConstant(ImmOffset, SL,
MVT::i32);
2338 CurDAG->setNodeMemRefs(cast<MachineSDNode>(Selected), {MMO});
2341 void AMDGPUDAGToDAGISel::SelectINTRINSIC_W_CHAIN(
SDNode *N) {
2342 unsigned IntrID = cast<ConstantSDNode>(N->
getOperand(1))->getZExtValue();
2344 case Intrinsic::amdgcn_ds_append:
2345 case Intrinsic::amdgcn_ds_consume: {
2348 SelectDSAppendConsume(N, IntrID);
2356 void AMDGPUDAGToDAGISel::SelectINTRINSIC_WO_CHAIN(
SDNode *N) {
2357 unsigned IntrID = cast<ConstantSDNode>(N->
getOperand(0))->getZExtValue();
2360 case Intrinsic::amdgcn_wqm:
2363 case Intrinsic::amdgcn_softwqm:
2364 Opcode = AMDGPU::SOFT_WQM;
2366 case Intrinsic::amdgcn_wwm:
2367 Opcode = AMDGPU::WWM;
2375 CurDAG->SelectNodeTo(N, Opcode, N->
getVTList(), {Src});
2378 void AMDGPUDAGToDAGISel::SelectINTRINSIC_VOID(
SDNode *N) {
2379 unsigned IntrID = cast<ConstantSDNode>(N->
getOperand(1))->getZExtValue();
2381 case Intrinsic::amdgcn_ds_gws_init:
2382 case Intrinsic::amdgcn_ds_gws_barrier:
2383 case Intrinsic::amdgcn_ds_gws_sema_v:
2384 case Intrinsic::amdgcn_ds_gws_sema_br:
2385 case Intrinsic::amdgcn_ds_gws_sema_p:
2386 case Intrinsic::amdgcn_ds_gws_sema_release_all:
2387 SelectDS_GWS(N, IntrID);
2397 unsigned &Mods)
const {
2414 bool AMDGPUDAGToDAGISel::SelectVOP3Mods(
SDValue In,
SDValue &Src,
2417 if (SelectVOP3ModsImpl(In, Src, Mods)) {
2418 SrcMods = CurDAG->getTargetConstant(Mods,
SDLoc(In),
MVT::i32);
2425 bool AMDGPUDAGToDAGISel::SelectVOP3Mods_NNaN(
SDValue In,
SDValue &Src,
2427 SelectVOP3Mods(In, Src, SrcMods);
2428 return isNoNanSrc(Src);
2431 bool AMDGPUDAGToDAGISel::SelectVOP3Mods_f32(
SDValue In,
SDValue &Src,
2434 return SelectVOP3Mods(In, Src, SrcMods);
2436 SrcMods = CurDAG->getTargetConstant(0,
SDLoc(In),
MVT::i32);;
2440 bool AMDGPUDAGToDAGISel::SelectVOP3NoMods(
SDValue In,
SDValue &Src)
const {
2448 bool AMDGPUDAGToDAGISel::SelectVOP3Mods0(
SDValue In,
SDValue &Src,
2452 Clamp = CurDAG->getTargetConstant(0, DL,
MVT::i1);
2453 Omod = CurDAG->getTargetConstant(0, DL,
MVT::i1);
2455 return SelectVOP3Mods(In, Src, SrcMods);
2458 bool AMDGPUDAGToDAGISel::SelectVOP3OMods(
SDValue In,
SDValue &Src,
2463 Clamp = CurDAG->getTargetConstant(0, DL,
MVT::i1);
2464 Omod = CurDAG->getTargetConstant(0, DL,
MVT::i1);
2469 bool AMDGPUDAGToDAGISel::SelectVOP3PMods(
SDValue In,
SDValue &Src,
2480 unsigned VecMods = Mods;
2491 Hi = stripBitcast(Hi.getOperand(0));
2495 if (isExtractHiElt(Lo, Lo))
2498 if (isExtractHiElt(Hi, Hi))
2501 Lo = stripExtractLoElt(Lo);
2502 Hi = stripExtractLoElt(Hi);
2504 if (Lo == Hi && !isInlineImmediate(Lo.
getNode())) {
2509 SrcMods = CurDAG->getTargetConstant(Mods,
SDLoc(In),
MVT::i32);
2519 SrcMods = CurDAG->getTargetConstant(Mods,
SDLoc(In),
MVT::i32);
2523 bool AMDGPUDAGToDAGISel::SelectVOP3PMods0(
SDValue In,
SDValue &Src,
2529 Clamp = CurDAG->getTargetConstant(0, SL,
MVT::i32);
2531 return SelectVOP3PMods(In, Src, SrcMods);
2534 bool AMDGPUDAGToDAGISel::SelectVOP3OpSel(
SDValue In,
SDValue &Src,
2538 SrcMods = CurDAG->getTargetConstant(0,
SDLoc(In),
MVT::i32);
2542 bool AMDGPUDAGToDAGISel::SelectVOP3OpSel0(
SDValue In,
SDValue &Src,
2548 Clamp = CurDAG->getTargetConstant(0, SL,
MVT::i32);
2550 return SelectVOP3OpSel(In, Src, SrcMods);
2553 bool AMDGPUDAGToDAGISel::SelectVOP3OpSelMods(
SDValue In,
SDValue &Src,
2556 return SelectVOP3Mods(In, Src, SrcMods);
2559 bool AMDGPUDAGToDAGISel::SelectVOP3OpSelMods0(
SDValue In,
SDValue &Src,
2565 Clamp = CurDAG->getTargetConstant(0, SL,
MVT::i32);
2567 return SelectVOP3OpSelMods(In, Src, SrcMods);
2572 bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsImpl(
SDValue In,
SDValue &Src,
2573 unsigned &Mods)
const {
2575 SelectVOP3ModsImpl(In, Src, Mods);
2580 Src = stripBitcast(Src);
2586 SelectVOP3ModsImpl(Src, Src, ModsTmp);
2591 if ((ModsTmp & SISrcMods::ABS) != 0)
2601 if (isExtractHiElt(Src, Src)) {
2613 bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixMods(
SDValue In,
SDValue &Src,
2616 SelectVOP3PMadMixModsImpl(In, Src, Mods);
2617 SrcMods = CurDAG->getTargetConstant(Mods,
SDLoc(In),
MVT::i32);
2627 return CurDAG->getConstant(
C->getZExtValue() << 16, SL,
MVT::i32);
2632 return CurDAG->getConstant(
2633 C->getValueAPF().bitcastToAPInt().getZExtValue() << 16, SL,
MVT::i32);
2637 if (isExtractHiElt(In, Src))
2643 bool AMDGPUDAGToDAGISel::isVGPRImm(
const SDNode * N)
const {
2647 static_cast<const SIRegisterInfo *
>(Subtarget->getRegisterInfo());
2649 static_cast<const SIInstrInfo *
>(Subtarget->getInstrInfo());
2652 bool AllUsesAcceptSReg =
true;
2654 Limit < 10 && U !=
E; ++U, ++Limit) {
2660 if (!RC || SIRI->isSGPRClass(RC))
2663 if (RC != &AMDGPU::VS_32RegClass) {
2664 AllUsesAcceptSReg =
false;
2670 unsigned OpIdx = Desc.
getNumDefs() + U.getOperandNo();
2673 unsigned CommutedOpNo = CommuteIdx1 - Desc.
getNumDefs();
2675 if (CommutedRC == &AMDGPU::VS_32RegClass)
2676 AllUsesAcceptSReg =
true;
2684 if (!AllUsesAcceptSReg)
2688 return !AllUsesAcceptSReg && (Limit < 10);
2691 bool AMDGPUDAGToDAGISel::isUniformLoad(
const SDNode * N)
const {
2692 auto Ld = cast<LoadSDNode>(
N);
2694 return Ld->getAlignment() >= 4 &&
2706 Subtarget->getScalarizeGlobalBehavior() &&
2708 !Ld->isVolatile() &&
2711 getTargetLowering())->isMemOpHasNoClobberedMemOperand(N)
2716 void AMDGPUDAGToDAGISel::PostprocessISelDAG() {
2719 bool IsModified =
false;
2725 while (Position != CurDAG->allnodes_end()) {
2726 SDNode *Node = &*Position++;
2732 if (ResNode != Node) {
2734 ReplaceUses(Node, ResNode);
2738 CurDAG->RemoveDeadNodes();
2739 }
while (IsModified);
2747 bool R600DAGToDAGISel::isConstantLoad(
const MemSDNode *N,
int CbId)
const {
2757 bool R600DAGToDAGISel::SelectGlobalValueConstantOffset(
SDValue Addr,
2760 IntPtr = CurDAG->getIntPtrConstant(Cst->getZExtValue() / 4,
SDLoc(Addr),
2767 bool R600DAGToDAGISel::SelectGlobalValueVariableOffset(
SDValue Addr,
2769 if (!isa<ConstantSDNode>(Addr)) {
2771 Offset = CurDAG->getIntPtrConstant(0,
SDLoc(Addr),
true);
2791 unsigned RegClassID;
2796 switch(NumVectorElts) {
2797 case 2: RegClassID = R600::R600_Reg64RegClassID;
break;
2800 RegClassID = R600::R600_Reg128VerticalRegClassID;
2802 RegClassID = R600::R600_Reg128RegClassID;
2806 SelectBuildVector(N, RegClassID);
2814 bool R600DAGToDAGISel::SelectADDRIndirect(
SDValue Addr,
SDValue &Base,
2819 if ((C = dyn_cast<ConstantSDNode>(Addr))) {
2820 Base = CurDAG->getRegister(R600::INDIRECT_BASE_ADDR,
MVT::i32);
2823 (C = dyn_cast<ConstantSDNode>(Addr.
getOperand(0)))) {
2824 Base = CurDAG->getRegister(R600::INDIRECT_BASE_ADDR,
MVT::i32);
2827 (C = dyn_cast<ConstantSDNode>(Addr.
getOperand(1)))) {
2832 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
2838 bool R600DAGToDAGISel::SelectADDRVTX_READ(
SDValue Addr,
SDValue &Base,
2844 &&
isInt<16>(IMMOffset->getZExtValue())) {
2847 Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(),
SDLoc(Addr),
2851 }
else if ((IMMOffset = dyn_cast<ConstantSDNode>(Addr))
2852 &&
isInt<16>(IMMOffset->getZExtValue())) {
2853 Base = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
2854 SDLoc(CurDAG->getEntryNode()),
2856 Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(),
SDLoc(Addr),
2863 Offset = CurDAG->getTargetConstant(0,
SDLoc(Addr),
MVT::i32);
unsigned getScratchWaveOffsetReg() const
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
constexpr bool isUInt< 32 >(uint64_t x)
EVT getValueType() const
Return the ValueType of the referenced return value.
Interface definition for SIRegisterInfo.
This SDNode is used for target intrinsics that touch memory and need an associated MachineMemOperand...
uint64_t getZExtValue() const
Get zero extended value.
INITIALIZE_PASS_BEGIN(AMDGPUDAGToDAGISel, "amdgpu-isel", "AMDGPU DAG->DAG Pattern Instruction Selection", false, false) INITIALIZE_PASS_END(AMDGPUDAGToDAGISel
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
AMDGPU specific subclass of TargetSubtarget.
static unsigned gwsIntrinToOpcode(unsigned IntrID)
This class represents lattice values for constants.
uint64_t getDefaultRsrcDataFormat() const
FunctionPass * createR600ISelDag(TargetMachine *TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a R600-specific.
unsigned getStackPtrOffsetReg() const
bool isCommutable() const
Return true if this may be a 2- or 3-address instruction (of the form "X = op Y, Z, ..."), which produces the same result if Y and Z are exchanged.
SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL, SDValue V) const
const SDValue & getBasePtr() const
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Carry-setting nodes for multiple precision addition and subtraction.
void push_back(const T &Elt)
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Describe properties that are true of each instruction in the target description file.
SDVTList getVTList() const
Address space for global memory (RAT0, VTX0).
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
const SDValue & getChain() const
const SIInstrInfo * getInstrInfo() const override
virtual SDNode * PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const =0
SDNode * legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const
Legalize target independent instructions (e.g.
constexpr bool isInt< 16 >(int64_t x)
unsigned const TargetRegisterInfo * TRI
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
const SDNodeFlags getFlags() const
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
bool isInlineConstant(const APInt &Imm) const
constexpr bool isMask_32(uint32_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Address space for flat memory.
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
unsigned getAddressSpace() const
Return the address space for the associated pointer.
bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi)
MachineSDNode * wrapAddr64Rsrc(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr) const
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool hasOneUse() const
Return true if there is exactly one use of this node.
A description of a memory reference used in the backend.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const HexagonInstrInfo * TII
Shift and rotation operations.
static bool EnableLateStructurizeCFG
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s), MachineInstr opcode, and operands.
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
CopyToReg - This node has three operands: a chain, a register number to set to this value...
uint64_t getConstantOperandVal(unsigned i) const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
static MemSDNode * findMemSDNode(SDNode *N)
Address space for 32-bit constant memory.
Position
Position to insert a new instruction relative to an existing instruction.
This file implements a class to represent arbitrary precision integral constant values and operations...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
TargetRegisterInfo interface that is implemented by all hw codegen targets.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Address space for region memory. (GDS)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
int64_t getSExtValue() const
uint32_t get32BitAddressHighBits() const
Simple integer binary arithmetic operators.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
static unsigned getSubRegFromChannel(unsigned Channel, unsigned NumRegs=1)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Analysis containing CSE Info
This node is for VLIW targets and it is used to represent a vector that is stored in consecutive regi...
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
static const unsigned CommuteAnyOperandIndex
FunctionPass * createAMDGPUISelDag(TargetMachine *TM=nullptr, CodeGenOpt::Level OptLevel=CodeGenOpt::Default)
This pass converts a legalized DAG into a AMDGPU-specific.
int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi)
Is this literal inlinable.
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
constexpr bool isUInt< 8 >(uint64_t x)
unsigned const MachineRegisterInfo * MRI
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
iterator_range< value_op_iterator > op_values() const
const SDValue & getOperand(unsigned Num) const
Carry-using nodes for multiple precision addition and subtraction.
SI DAG Lowering interface definition.
Represent the analysis usage information of a pass.
This class provides iterator support for SDUse operands that use a specific SDNode.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
const R600RegisterInfo & getRegisterInfo() const
bool isDefined() const
Returns true if the flags are in a defined state.
The AMDGPU TargetMachine interface definition for hw codgen targets.
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
This class contains a discriminated union of information about pointers in memory operands...
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getNumOperands() const
Return the number of values used by this operation.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned selectSGPRVectorRegClassID(unsigned NumVectorElts)
bool use_empty() const
Return true if there are no uses of this node.
MachineSDNode * buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr, uint32_t RsrcDword1, uint64_t RsrcDword2And3) const
Return a resource descriptor with the 'Add TID' bit enabled The TID (Thread ID) is multiplied by the ...
Iterator for intrusive lists based on ilist_node.
unsigned countPopulation(T Value)
Count the number of set bits in a value.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Interface definition of the TargetLowering class that is common to all AMD GPUs.
Address space for local memory.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses...
BRCOND - Conditional branch.
An SDNode that represents everything that will be needed to construct a MachineInstr.
This is an abstract virtual class for memory operations.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
EVT getMemoryVT() const
Return the type of the in-memory value.
Class for arbitrary precision integers.
Special value supplied for machine level alias analysis.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
static bool isStackPtrRelative(const MachinePointerInfo &PtrInfo)
static use_iterator use_end()
static SDValue stripBitcast(SDValue Val)
Contains the definition of a TargetInstrInfo class that is common to all AMD GPUs.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
unsigned getNumFlatOffsetBits(unsigned AddrSpace, bool Signed) const
Provides AMDGPU specific target descriptions.
bool hasInv2PiInlineImm() const
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
Bitwise operators - logical and, logical or, logical xor.
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getOpcode() const
SDValue getValue(unsigned R) const
constexpr bool isUInt< 16 >(uint64_t x)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
SmallVector< LoopT *, 4 > getLoopsInPreorder()
Return all of the loops in the function in preorder across the loop nests, with siblings in forward p...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isLegalMUBUFImmOffset(unsigned Imm)
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
TypeSize getScalarSizeInBits() const
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
LLVM Value Representation.
FMA - Perform a * b + c with no intermediate rounding step.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
const TargetRegisterClass * getPhysRegClass(unsigned Reg) const
Return the 'base' register class for this register.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
bool hasNoUnsignedWrap() const
const MCOperandInfo * OpInfo
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isUndef() const
Return true if the type of the node type undefined.
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
Primary interface to the complete machine description for the target machine.
The legacy pass manager's analysis pass to compute loop information.
bool isLegalFLATOffset(int64_t Offset, unsigned AddrSpace, bool Signed) const
Returns if Offset is legal for the subtarget as the offset to a FLAT encoded instruction.
StringRef - Represent a constant reference to a string, i.e.
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations...
SetCC operator - This evaluates to a true value iff the condition is true.
Legacy analysis pass which computes a DominatorTree.
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
const SDValue & getOperand(unsigned i) const
uint64_t getZExtValue() const
TRUNCATE - Completely drop the high bits.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
Perform various unary floating-point operations inspired by libm.
Analyzes if a function potentially memory bound and if a kernel kernel may benefit from limiting numb...
const SDValue & getBasePtr() const
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Address space for constant memory (VTX2).
Carry-using nodes for multiple precision addition and subtraction.
This class is used to represent ISD::LOAD nodes.
const SIRegisterInfo * getRegisterInfo() const override