28#include "llvm/IR/IntrinsicsAMDGPU.h"
32#ifdef EXPENSIVE_CHECKS
37#define DEBUG_TYPE "amdgpu-isel"
52 In = stripBitcast(In);
58 Out = In.getOperand(0);
69 if (ShiftAmt->getZExtValue() == 16) {
75 if (Result.getValueSizeInBits() != 32)
86static bool isLoEltExtractHi(
SDValue BV) {
89 Lo = stripBitcast(
Lo.getOperand(0));
104 if (
Lo->isDivergent()) {
106 SL,
Lo.getValueType()),
114 Src.getValueType(),
Ops),
132 SDValue Idx = In.getOperand(1);
134 return In.getOperand(0);
138 SDValue Src = In.getOperand(0);
139 if (Src.getValueType().getSizeInBits() == 32)
140 return stripBitcast(Src);
150 assert(Elts.
size() == SubRegClass.
size() &&
"array size mismatch");
151 unsigned NumElts = Elts.
size();
154 for (
unsigned i = 0; i < NumElts; ++i) {
155 Ops[2 * i + 1] = Elts[i];
165 "AMDGPU DAG->DAG Pattern Instruction Selection",
false,
169#ifdef EXPENSIVE_CHECKS
174 "AMDGPU DAG->DAG Pattern Instruction Selection",
false,
194bool AMDGPUDAGToDAGISel::fp16SrcZerosHighBits(
unsigned Opc)
const {
230 case AMDGPUISD::FRACT:
231 case AMDGPUISD::CLAMP:
232 case AMDGPUISD::COS_HW:
233 case AMDGPUISD::SIN_HW:
234 case AMDGPUISD::FMIN3:
235 case AMDGPUISD::FMAX3:
236 case AMDGPUISD::FMED3:
237 case AMDGPUISD::FMAD_FTZ:
240 case AMDGPUISD::RCP_IFLAG:
250 case AMDGPUISD::DIV_FIXUP:
260#ifdef EXPENSIVE_CHECKS
264 assert(L->isLCSSAForm(DT));
272#ifdef EXPENSIVE_CHECKS
280 assert(Subtarget->d16PreservesUnusedBits());
281 MVT VT =
N->getValueType(0).getSimpleVT();
282 if (VT != MVT::v2i16 && VT != MVT::v2f16)
303 if (LdHi &&
Hi.hasOneUse() && !LoIsT16Load &&
312 unsigned LoadOp = AMDGPUISD::LOAD_D16_HI;
315 AMDGPUISD::LOAD_D16_HI_I8 : AMDGPUISD::LOAD_D16_HI_U8;
321 CurDAG->getMemIntrinsicNode(LoadOp,
SDLoc(LdHi), VTList,
334 if (LdLo &&
Lo.hasOneUse()) {
340 unsigned LoadOp = AMDGPUISD::LOAD_D16_LO;
343 AMDGPUISD::LOAD_D16_LO_I8 : AMDGPUISD::LOAD_D16_LO_U8;
355 CurDAG->getMemIntrinsicNode(LoadOp,
SDLoc(LdLo), VTList,
369 EVT VT =
N->getValueType(0);
383 Ld ?
CurDAG->getExtLoad(ExtType, SL, MVT::i32, Mem->getChain(),
384 Mem->getBasePtr(), MemVT, Mem->getMemOperand())
385 :
CurDAG->getAtomicLoad(ExtType, SL, MemVT, MVT::i32, Mem->getChain(),
386 Mem->getBasePtr(), Mem->getMemOperand());
397 bool MadeChange =
false;
398 while (Position !=
CurDAG->allnodes_begin()) {
403 switch (
N->getOpcode()) {
406 if (Subtarget->d16PreservesUnusedBits())
411 if (Subtarget->useRealTrue16Insts())
420 CurDAG->RemoveDeadNodes();
426bool AMDGPUDAGToDAGISel::isInlineImmediate(
const SDNode *
N)
const {
432 return TII->isInlineConstant(
C->getAPIntValue());
435 return TII->isInlineConstant(
C->getValueAPF());
445 unsigned OpNo)
const {
446 if (!
N->isMachineOpcode()) {
449 if (
Reg.isVirtual()) {
451 return MRI.getRegClass(
Reg);
454 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
455 return TRI->getPhysRegBaseClass(
Reg);
461 switch (
N->getMachineOpcode()) {
463 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
464 const MCInstrDesc &
Desc =
TII->get(
N->getMachineOpcode());
465 unsigned OpIdx =
Desc.getNumDefs() + OpNo;
466 if (OpIdx >=
Desc.getNumOperands())
469 int16_t RegClass =
TII->getOpRegClassID(
Desc.operands()[OpIdx]);
473 return Subtarget->getRegisterInfo()->getRegClass(RegClass);
475 case AMDGPU::REG_SEQUENCE: {
476 unsigned RCID =
N->getConstantOperandVal(0);
478 Subtarget->getRegisterInfo()->getRegClass(RCID);
480 SDValue SubRegOp =
N->getOperand(OpNo + 1);
482 return Subtarget->getRegisterInfo()->getSubClassWithSubReg(SuperRC,
491 Ops.push_back(NewChain);
492 for (
unsigned i = 1, e =
N->getNumOperands(); i != e; ++i)
493 Ops.push_back(
N->getOperand(i));
496 return CurDAG->MorphNodeTo(
N,
N->getOpcode(),
N->getVTList(),
Ops);
503 assert(
N->getOperand(0).getValueType() == MVT::Other &&
"Expected chain");
506 return glueCopyToOp(
N,
M0,
M0.getValue(1));
509SDNode *AMDGPUDAGToDAGISel::glueCopyToM0LDSInit(
SDNode *
N)
const {
512 if (Subtarget->ldsRequiresM0Init())
514 N,
CurDAG->getSignedTargetConstant(-1, SDLoc(
N), MVT::i32));
517 unsigned Value =
MF.getInfo<SIMachineFunctionInfo>()->getGDSSize();
519 glueCopyToM0(
N,
CurDAG->getTargetConstant(
Value, SDLoc(
N), MVT::i32));
526 SDNode *
Lo =
CurDAG->getMachineNode(
527 AMDGPU::S_MOV_B32,
DL, MVT::i32,
529 SDNode *
Hi =
CurDAG->getMachineNode(
530 AMDGPU::S_MOV_B32,
DL, MVT::i32,
533 CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID,
DL, MVT::i32),
537 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
DL, VT,
Ops);
540SDNode *AMDGPUDAGToDAGISel::packConstantV2I16(
const SDNode *
N,
545 uint32_t LHSVal, RHSVal;
549 uint32_t
K = (LHSVal & 0xffff) | (RHSVal << 16);
551 isVGPRImm(
N) ? AMDGPU::V_MOV_B32_e32 : AMDGPU::S_MOV_B32, SL,
559 EVT VT =
N->getValueType(0);
563 SDValue RegClass =
CurDAG->getTargetConstant(RegClassID,
DL, MVT::i32);
565 if (NumVectorElts == 1) {
566 CurDAG->SelectNodeTo(
N, AMDGPU::COPY_TO_REGCLASS, EltVT,
N->getOperand(0),
571 bool IsGCN =
CurDAG->getSubtarget().getTargetTriple().isAMDGCN();
572 if (IsGCN && Subtarget->has64BitLiterals() && VT.
getSizeInBits() == 64 &&
575 bool AllConst =
true;
577 for (
unsigned I = 0;
I < NumVectorElts; ++
I) {
585 Val = CF->getValueAPF().bitcastToAPInt().getZExtValue();
588 C |= Val << (EltSize *
I);
593 CurDAG->getMachineNode(AMDGPU::S_MOV_B64_IMM_PSEUDO,
DL, VT, CV);
594 CurDAG->SelectNodeTo(
N, AMDGPU::COPY_TO_REGCLASS, VT,
SDValue(Copy, 0),
600 assert(NumVectorElts <= 32 &&
"Vectors with more than 32 elements not "
607 RegSeqArgs[0] =
CurDAG->getTargetConstant(RegClassID,
DL, MVT::i32);
608 bool IsRegSeq =
true;
609 unsigned NOps =
N->getNumOperands();
611 assert(IsGCN || EltSizeInRegs == 1);
612 for (
unsigned i = 0; i < NOps; i++) {
619 i * EltSizeInRegs, EltSizeInRegs)
621 RegSeqArgs[1 + (2 * i)] =
N->getOperand(i);
622 RegSeqArgs[1 + (2 * i) + 1] =
CurDAG->getTargetConstant(
Sub,
DL, MVT::i32);
624 if (NOps != NumVectorElts) {
629 for (
unsigned i = NOps; i < NumVectorElts; ++i) {
631 i * EltSizeInRegs, EltSizeInRegs)
633 RegSeqArgs[1 + (2 * i)] =
SDValue(ImpDef, 0);
634 RegSeqArgs[1 + (2 * i) + 1] =
641 CurDAG->SelectNodeTo(
N, AMDGPU::REG_SEQUENCE,
N->getVTList(), RegSeqArgs);
645 EVT VT =
N->getValueType(0);
649 if (!Subtarget->hasPkMovB32() || !EltVT.
bitsEq(MVT::i32) ||
657 SDValue Src0 = SVN->getOperand(0);
658 SDValue Src1 = SVN->getOperand(1);
662 assert(Src0.getValueType().getVectorNumElements() == 2 && Mask.size() == 2 &&
663 Mask[0] < 4 && Mask[1] < 4);
665 SDValue VSrc0 = Mask[0] < 2 ? Src0 : Src1;
666 SDValue VSrc1 = Mask[1] < 2 ? Src0 : Src1;
667 unsigned Src0SubReg = Mask[0] & 1 ? AMDGPU::sub1 : AMDGPU::sub0;
668 unsigned Src1SubReg = Mask[1] & 1 ? AMDGPU::sub1 : AMDGPU::sub0;
671 Src0SubReg = Src1SubReg;
673 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
DL, VT);
678 Src1SubReg = Src0SubReg;
680 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
DL, VT);
690 if (
N->isDivergent() && Src0SubReg == AMDGPU::sub1 &&
691 Src1SubReg == AMDGPU::sub0) {
707 SDValue Src0OpSelVal =
CurDAG->getTargetConstant(Src0OpSel,
DL, MVT::i32);
708 SDValue Src1OpSelVal =
CurDAG->getTargetConstant(Src1OpSel,
DL, MVT::i32);
711 CurDAG->SelectNodeTo(
N, AMDGPU::V_PK_MOV_B32,
N->getVTList(),
712 {Src0OpSelVal, VSrc0, Src1OpSelVal, VSrc1,
722 CurDAG->getTargetExtractSubreg(Src0SubReg,
DL, EltVT, VSrc0);
724 CurDAG->getTargetExtractSubreg(Src1SubReg,
DL, EltVT, VSrc1);
727 CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID,
DL, MVT::i32),
728 ResultElt0,
CurDAG->getTargetConstant(AMDGPU::sub0,
DL, MVT::i32),
729 ResultElt1,
CurDAG->getTargetConstant(AMDGPU::sub1,
DL, MVT::i32)};
730 CurDAG->SelectNodeTo(
N, TargetOpcode::REG_SEQUENCE, VT,
Ops);
734 unsigned int Opc =
N->getOpcode();
735 if (
N->isMachineOpcode()) {
743 N = glueCopyToM0LDSInit(
N);
753 if (
N->getValueType(0) == MVT::i64) {
754 SelectAddcSubbI64(
N);
758 if (
N->getValueType(0) != MVT::i32)
765 if (
N->getValueType(0) == MVT::i64) {
766 SelectAddcSubbI64(
N);
770 SelectUADDO_USUBO(
N);
773 case AMDGPUISD::FMUL_W_CHAIN: {
774 SelectFMUL_W_CHAIN(
N);
777 case AMDGPUISD::FMA_W_CHAIN: {
778 SelectFMA_W_CHAIN(
N);
784 EVT VT =
N->getValueType(0);
802 N->isDivergent() ?
TRI->getDefaultVectorSuperClassForBitWidth(VecInBits)
814 if (
N->getValueType(0) == MVT::i128) {
815 RC =
CurDAG->getTargetConstant(AMDGPU::SGPR_128RegClassID,
DL, MVT::i32);
816 SubReg0 =
CurDAG->getTargetConstant(AMDGPU::sub0_sub1,
DL, MVT::i32);
817 SubReg1 =
CurDAG->getTargetConstant(AMDGPU::sub2_sub3,
DL, MVT::i32);
818 }
else if (
N->getValueType(0) == MVT::i64) {
819 RC =
CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID,
DL, MVT::i32);
820 SubReg0 =
CurDAG->getTargetConstant(AMDGPU::sub0,
DL, MVT::i32);
821 SubReg1 =
CurDAG->getTargetConstant(AMDGPU::sub1,
DL, MVT::i32);
825 const SDValue Ops[] = { RC,
N->getOperand(0), SubReg0,
826 N->getOperand(1), SubReg1 };
828 N->getValueType(0),
Ops));
834 if (
N->getValueType(0).getSizeInBits() != 64 || isInlineImmediate(
N) ||
835 Subtarget->has64BitLiterals())
840 Imm =
FP->getValueAPF().bitcastToAPInt().getZExtValue();
845 Imm =
C->getZExtValue();
854 case AMDGPUISD::BFE_I32:
855 case AMDGPUISD::BFE_U32: {
881 case AMDGPUISD::DIV_SCALE: {
892 return SelectMUL_LOHI(
N);
903 if (
N->getValueType(0) != MVT::i32)
914 case AMDGPUISD::CVT_PKRTZ_F16_F32:
915 case AMDGPUISD::CVT_PKNORM_I16_F32:
916 case AMDGPUISD::CVT_PKNORM_U16_F32:
917 case AMDGPUISD::CVT_PK_U16_U32:
918 case AMDGPUISD::CVT_PK_I16_I32: {
920 if (
N->getValueType(0) == MVT::i32) {
921 MVT NewVT =
Opc == AMDGPUISD::CVT_PKRTZ_F16_F32 ? MVT::v2f16 : MVT::v2i16;
923 { N->getOperand(0), N->getOperand(1) });
931 SelectINTRINSIC_W_CHAIN(
N);
935 SelectINTRINSIC_WO_CHAIN(
N);
939 SelectINTRINSIC_VOID(
N);
943 SelectWAVE_ADDRESS(
N);
947 SelectSTACKRESTORE(
N);
951 SelectWRITE_REGISTER(
N);
960 if (!Subtarget->hasSDWA())
970 return RHS->getZExtValue() == 0xFF || RHS->getZExtValue() == 0xFFFF;
974 return (RHS->getZExtValue() % 8) == 0;
979bool AMDGPUDAGToDAGISel::isUniformBr(
const SDNode *
N)
const {
982 return Term->getMetadata(
"amdgpu.uniform") ||
983 Term->getMetadata(
"structurizecfg.uniform");
986bool AMDGPUDAGToDAGISel::isVRegIdxFoldableAdd(
const SDNode *
N,
987 unsigned NumDwords)
const {
991 int64_t
Offset =
C->getSExtValue();
992 unsigned NumIndexable =
997 return N->getOpcode() ==
ISD::OR ||
N->getFlags().hasNoUnsignedWrap() ||
1001bool AMDGPUDAGToDAGISel::isUnneededShiftMask(
const SDNode *
N,
1002 unsigned ShAmtBits)
const {
1005 const APInt &
RHS =
N->getConstantOperandAPInt(1);
1006 if (
RHS.countr_one() >= ShAmtBits)
1009 const APInt &LHSKnownZeros =
CurDAG->computeKnownBits(
N->getOperand(0)).Zero;
1010 return (LHSKnownZeros |
RHS).countr_one() >= ShAmtBits;
1036 N1 =
Lo.getOperand(1);
1046 if (
CurDAG->isBaseWithConstantOffset(Addr)) {
1061 return "AMDGPU DAG->DAG Pattern Instruction Selection";
1077#ifdef EXPENSIVE_CHECKS
1080 for (
auto &L : LI.getLoopsInPreorder())
1081 assert(L->isLCSSAForm(DT) &&
"Loop is not in LCSSA form!");
1103 }
else if ((Addr.
getOpcode() == AMDGPUISD::DWORDADDR) &&
1105 Base =
CurDAG->getRegister(R600::INDIRECT_BASE_ADDR, MVT::i32);
1119SDValue AMDGPUDAGToDAGISel::getMaterializedScalarImm32(int64_t Val,
1121 SDNode *Mov =
CurDAG->getMachineNode(
1122 AMDGPU::S_MOV_B32,
DL, MVT::i32,
1123 CurDAG->getTargetConstant(Val,
DL, MVT::i32));
1127void AMDGPUDAGToDAGISel::SelectAddcSubb(
SDNode *
N) {
1132 if (
N->isDivergent()) {
1134 : AMDGPU::V_SUBB_U32_e64;
1136 N,
Opc,
N->getVTList(),
1138 CurDAG->getTargetConstant(0, {}, MVT::i1) });
1141 : AMDGPU::S_SUB_CO_PSEUDO;
1142 CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(), {LHS, RHS, CI});
1146void AMDGPUDAGToDAGISel::SelectAddcSubbI64(
SDNode *
N) {
1151 unsigned Opcode =
N->getOpcode();
1158 SDNode *Lo0 =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
DL,
1159 MVT::i32,
LHS, Sub0);
1160 SDNode *Hi0 =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
DL,
1161 MVT::i32,
LHS, Sub1);
1163 SDNode *Lo1 =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
DL,
1164 MVT::i32,
RHS, Sub0);
1165 SDNode *Hi1 =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
DL,
1166 MVT::i32,
RHS, Sub1);
1168 SDVTList VTList =
CurDAG->getVTList(MVT::i32,
N->getValueType(1));
1170 static const unsigned NoCarryOpcMap[2][2] = {
1171 {AMDGPU::S_USUBO_PSEUDO, AMDGPU::S_UADDO_PSEUDO},
1172 {AMDGPU::V_SUB_CO_U32_e64, AMDGPU::V_ADD_CO_U32_e64}};
1173 static const unsigned CarryOpcMap[2][2] = {
1174 {AMDGPU::S_SUB_CO_PSEUDO, AMDGPU::S_ADD_CO_PSEUDO},
1175 {AMDGPU::V_SUBB_U32_e64, AMDGPU::V_ADDC_U32_e64}};
1177 bool IsVALU =
N->isDivergent();
1179 unsigned NoCarryOpc = NoCarryOpcMap[IsVALU][IsAdd];
1180 unsigned CarryOpc = CarryOpcMap[IsVALU][IsAdd];
1184 if (!ConsumeCarry) {
1187 AddLo =
CurDAG->getMachineNode(NoCarryOpc,
DL, VTList, Args);
1190 AddLo =
CurDAG->getMachineNode(NoCarryOpc,
DL, VTList, Args);
1196 AddLo =
CurDAG->getMachineNode(CarryOpc,
DL, VTList, Args);
1199 AddLo =
CurDAG->getMachineNode(CarryOpc,
DL, VTList, Args);
1207 AddHi =
CurDAG->getMachineNode(CarryOpc,
DL, VTList, Args);
1210 AddHi =
CurDAG->getMachineNode(CarryOpc,
DL, VTList, Args);
1213 unsigned RC = IsVALU ? AMDGPU::VReg_64RegClassID : AMDGPU::SReg_64RegClassID;
1214 SDValue RegSequenceArgs[] = {
CurDAG->getTargetConstant(RC,
DL, MVT::i32),
1218 MVT::i64, RegSequenceArgs);
1224void AMDGPUDAGToDAGISel::SelectUADDO_USUBO(
SDNode *
N) {
1229 bool IsVALU =
N->isDivergent();
1231 for (SDNode::user_iterator UI =
N->user_begin(),
E =
N->user_end(); UI !=
E;
1233 if (UI.getUse().getResNo() == 1) {
1234 if (UI->isMachineOpcode()) {
1235 if (UI->getMachineOpcode() !=
1236 (IsAdd ? AMDGPU::S_ADD_CO_PSEUDO : AMDGPU::S_SUB_CO_PSEUDO)) {
1249 unsigned Opc = IsAdd ? AMDGPU::V_ADD_CO_U32_e64 : AMDGPU::V_SUB_CO_U32_e64;
1252 N,
Opc,
N->getVTList(),
1253 {N->getOperand(0), N->getOperand(1),
1254 CurDAG->getTargetConstant(0, {}, MVT::i1) });
1256 unsigned Opc = IsAdd ? AMDGPU::S_UADDO_PSEUDO : AMDGPU::S_USUBO_PSEUDO;
1258 CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(),
1259 {N->getOperand(0), N->getOperand(1)});
1263void AMDGPUDAGToDAGISel::SelectFMA_W_CHAIN(
SDNode *
N) {
1267 SelectVOP3Mods0(
N->getOperand(1),
Ops[1],
Ops[0],
Ops[6],
Ops[7]);
1268 SelectVOP3Mods(
N->getOperand(2),
Ops[3],
Ops[2]);
1269 SelectVOP3Mods(
N->getOperand(3),
Ops[5],
Ops[4]);
1270 Ops[8] =
N->getOperand(0);
1271 Ops[9] =
N->getOperand(4);
1275 bool UseFMAC = Subtarget->hasDLInsts() &&
1279 unsigned Opcode = UseFMAC ? AMDGPU::V_FMAC_F32_e64 : AMDGPU::V_FMA_F32_e64;
1280 CurDAG->SelectNodeTo(
N, Opcode,
N->getVTList(),
Ops);
1283void AMDGPUDAGToDAGISel::SelectFMUL_W_CHAIN(
SDNode *
N) {
1287 SelectVOP3Mods0(
N->getOperand(1),
Ops[1],
Ops[0],
Ops[4],
Ops[5]);
1288 SelectVOP3Mods(
N->getOperand(2),
Ops[3],
Ops[2]);
1289 Ops[6] =
N->getOperand(0);
1290 Ops[7] =
N->getOperand(3);
1292 CurDAG->SelectNodeTo(
N, AMDGPU::V_MUL_F32_e64,
N->getVTList(),
Ops);
1297void AMDGPUDAGToDAGISel::SelectDIV_SCALE(
SDNode *
N) {
1298 EVT VT =
N->getValueType(0);
1300 assert(VT == MVT::f32 || VT == MVT::f64);
1303 = (VT == MVT::f64) ? AMDGPU::V_DIV_SCALE_F64_e64 : AMDGPU::V_DIV_SCALE_F32_e64;
1308 SelectVOP3BMods0(
N->getOperand(0),
Ops[1],
Ops[0],
Ops[6],
Ops[7]);
1309 SelectVOP3BMods(
N->getOperand(1),
Ops[3],
Ops[2]);
1310 SelectVOP3BMods(
N->getOperand(2),
Ops[5],
Ops[4]);
1316void AMDGPUDAGToDAGISel::SelectMAD_64_32(
SDNode *
N) {
1320 bool UseNoCarry = Subtarget->hasMadNC64_32Insts() && !
N->hasAnyUseOfValue(1);
1321 if (Subtarget->hasMADIntraFwdBug())
1322 Opc =
Signed ? AMDGPU::V_MAD_I64_I32_gfx11_e64
1323 : AMDGPU::V_MAD_U64_U32_gfx11_e64;
1324 else if (UseNoCarry)
1325 Opc =
Signed ? AMDGPU::V_MAD_NC_I64_I32_e64 : AMDGPU::V_MAD_NC_U64_U32_e64;
1327 Opc =
Signed ? AMDGPU::V_MAD_I64_I32_e64 : AMDGPU::V_MAD_U64_U32_e64;
1330 SDValue Ops[] = {
N->getOperand(0),
N->getOperand(1),
N->getOperand(2),
1334 MachineSDNode *Mad =
CurDAG->getMachineNode(
Opc, SL, MVT::i64,
Ops);
1345void AMDGPUDAGToDAGISel::SelectMUL_LOHI(
SDNode *
N) {
1350 if (Subtarget->hasMadNC64_32Insts()) {
1351 VTList =
CurDAG->getVTList(MVT::i64);
1352 Opc =
Signed ? AMDGPU::V_MAD_NC_I64_I32_e64 : AMDGPU::V_MAD_NC_U64_U32_e64;
1354 VTList =
CurDAG->getVTList(MVT::i64, MVT::i1);
1355 if (Subtarget->hasMADIntraFwdBug()) {
1356 Opc =
Signed ? AMDGPU::V_MAD_I64_I32_gfx11_e64
1357 : AMDGPU::V_MAD_U64_U32_gfx11_e64;
1359 Opc =
Signed ? AMDGPU::V_MAD_I64_I32_e64 : AMDGPU::V_MAD_U64_U32_e64;
1366 SDNode *Mad =
CurDAG->getMachineNode(
Opc, SL, VTList,
Ops);
1368 SDValue Sub0 =
CurDAG->getTargetConstant(AMDGPU::sub0, SL, MVT::i32);
1369 SDNode *
Lo =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, SL,
1370 MVT::i32,
SDValue(Mad, 0), Sub0);
1374 SDValue Sub1 =
CurDAG->getTargetConstant(AMDGPU::sub1, SL, MVT::i32);
1375 SDNode *
Hi =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, SL,
1376 MVT::i32,
SDValue(Mad, 0), Sub1);
1386 if (!
Base || Subtarget->hasUsableDSOffset() ||
1387 Subtarget->unsafeDSOffsetFoldingEnabled())
1398 if (
CurDAG->isBaseWithConstantOffset(Addr)) {
1402 if (isDSOffsetLegal(N0,
C1->getSExtValue())) {
1411 int64_t ByteOffset =
C->getSExtValue();
1412 if (isDSOffsetLegal(
SDValue(), ByteOffset)) {
1421 if (isDSOffsetLegal(
Sub, ByteOffset)) {
1427 unsigned SubOp = AMDGPU::V_SUB_CO_U32_e32;
1428 if (Subtarget->hasAddNoCarryInsts()) {
1429 SubOp = AMDGPU::V_SUB_U32_e64;
1431 CurDAG->getTargetConstant(0, {}, MVT::i1));
1434 MachineSDNode *MachineSub =
1435 CurDAG->getMachineNode(SubOp,
DL, MVT::i32, Opnds);
1451 if (isDSOffsetLegal(
SDValue(), CAddr->getZExtValue())) {
1453 MachineSDNode *MovZero =
CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
1456 Offset =
CurDAG->getTargetConstant(CAddr->getZExtValue(),
DL, MVT::i16);
1463 Offset =
CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i16);
1467bool AMDGPUDAGToDAGISel::isDSOffset2Legal(
SDValue Base,
unsigned Offset0,
1469 unsigned Size)
const {
1470 if (Offset0 %
Size != 0 || Offset1 %
Size != 0)
1475 if (!
Base || Subtarget->hasUsableDSOffset() ||
1476 Subtarget->unsafeDSOffsetFoldingEnabled())
1494bool AMDGPUDAGToDAGISel::isFlatScratchBaseLegal(
SDValue Addr)
const {
1500 if (Subtarget->hasSignedScratchOffsets())
1510 ConstantSDNode *ImmOp =
nullptr;
1521bool AMDGPUDAGToDAGISel::isFlatScratchBaseLegalSV(
SDValue Addr)
const {
1527 if (Subtarget->hasSignedScratchOffsets())
1537bool AMDGPUDAGToDAGISel::isFlatScratchBaseLegalSVImm(
SDValue Addr)
const {
1551 (RHSImm->getSExtValue() < 0 && RHSImm->getSExtValue() > -0x40000000)))
1554 auto LHS =
Base.getOperand(0);
1555 auto RHS =
Base.getOperand(1);
1563 return SelectDSReadWrite2(Addr,
Base, Offset0, Offset1, 4);
1569 return SelectDSReadWrite2(Addr,
Base, Offset0, Offset1, 8);
1574 unsigned Size)
const {
1577 if (
CurDAG->isBaseWithConstantOffset(Addr)) {
1581 unsigned OffsetValue0 =
C1->getZExtValue();
1582 unsigned OffsetValue1 = OffsetValue0 +
Size;
1585 if (isDSOffset2Legal(N0, OffsetValue0, OffsetValue1,
Size)) {
1587 Offset0 =
CurDAG->getTargetConstant(OffsetValue0 /
Size,
DL, MVT::i32);
1588 Offset1 =
CurDAG->getTargetConstant(OffsetValue1 /
Size,
DL, MVT::i32);
1593 if (
const ConstantSDNode *
C =
1595 unsigned OffsetValue0 =
C->getZExtValue();
1596 unsigned OffsetValue1 = OffsetValue0 +
Size;
1598 if (isDSOffset2Legal(
SDValue(), OffsetValue0, OffsetValue1,
Size)) {
1608 if (isDSOffset2Legal(
Sub, OffsetValue0, OffsetValue1,
Size)) {
1612 unsigned SubOp = AMDGPU::V_SUB_CO_U32_e32;
1613 if (Subtarget->hasAddNoCarryInsts()) {
1614 SubOp = AMDGPU::V_SUB_U32_e64;
1616 CurDAG->getTargetConstant(0, {}, MVT::i1));
1619 MachineSDNode *MachineSub =
CurDAG->getMachineNode(
1624 CurDAG->getTargetConstant(OffsetValue0 /
Size,
DL, MVT::i32);
1626 CurDAG->getTargetConstant(OffsetValue1 /
Size,
DL, MVT::i32);
1632 unsigned OffsetValue0 = CAddr->getZExtValue();
1633 unsigned OffsetValue1 = OffsetValue0 +
Size;
1635 if (isDSOffset2Legal(
SDValue(), OffsetValue0, OffsetValue1,
Size)) {
1637 MachineSDNode *MovZero =
1638 CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
DL, MVT::i32,
Zero);
1640 Offset0 =
CurDAG->getTargetConstant(OffsetValue0 /
Size,
DL, MVT::i32);
1641 Offset1 =
CurDAG->getTargetConstant(OffsetValue1 /
Size,
DL, MVT::i32);
1649 Offset0 =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1650 Offset1 =
CurDAG->getTargetConstant(1,
DL, MVT::i32);
1660 if (Subtarget->useFlatForGlobal())
1666 Idxen =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
1667 Offen =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
1668 Addr64 =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
1669 SOffset = Subtarget->hasRestrictedSOffset()
1670 ?
CurDAG->getRegister(AMDGPU::SGPR_NULL, MVT::i32)
1671 :
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1673 ConstantSDNode *
C1 =
nullptr;
1676 CurDAG->isBaseWithConstantOffset(Addr)) {
1684 N0 = Expand32BitAddress(N0);
1690 Addr64 =
CurDAG->getTargetConstant(1,
DL, MVT::i1);
1696 Ptr =
SDValue(buildSMovImm64(
DL, 0, MVT::v2i32), 0);
1712 Ptr =
SDValue(buildSMovImm64(
DL, 0, MVT::v2i32), 0);
1714 Addr64 =
CurDAG->getTargetConstant(1,
DL, MVT::i1);
1718 VAddr =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1728 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1729 if (
TII->isLegalMUBUFImmOffset(
C1->getZExtValue())) {
1739 AMDGPU::S_MOV_B32,
DL, MVT::i32,
1740 CurDAG->getTargetConstant(
C1->getZExtValue(),
DL, MVT::i32)),
1745bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(
SDValue Addr,
SDValue &SRsrc,
1748 SDValue Ptr, Offen, Idxen, Addr64;
1752 if (!Subtarget->hasAddr64())
1755 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset,
Offset, Offen, Idxen, Addr64))
1759 if (
C->getSExtValue()) {
1772std::pair<SDValue, SDValue> AMDGPUDAGToDAGISel::foldFrameIndex(
SDValue N)
const {
1777 FI ?
CurDAG->getTargetFrameIndex(FI->getIndex(), FI->getValueType(0)) :
N;
1783 return std::pair(TFI,
CurDAG->getTargetConstant(0,
DL, MVT::i32));
1786bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(
SDNode *Parent,
1793 const SIMachineFunctionInfo *
Info =
MF.getInfo<SIMachineFunctionInfo>();
1795 Rsrc =
CurDAG->getRegister(
Info->getScratchRSrcReg(), MVT::v4i32);
1798 int64_t
Imm = CAddr->getSExtValue();
1799 const int64_t NullPtr =
1802 if (
Imm != NullPtr) {
1805 CurDAG->getTargetConstant(
Imm & ~MaxOffset,
DL, MVT::i32);
1806 MachineSDNode *MovHighBits =
CurDAG->getMachineNode(
1807 AMDGPU::V_MOV_B32_e32,
DL, MVT::i32, HighBits);
1808 VAddr =
SDValue(MovHighBits, 0);
1810 SOffset =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1811 ImmOffset =
CurDAG->getTargetConstant(
Imm & MaxOffset,
DL, MVT::i32);
1816 if (
CurDAG->isBaseWithConstantOffset(Addr)) {
1837 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1838 if (
TII->isLegalMUBUFImmOffset(
C1) &&
1839 (!Subtarget->privateMemoryResourceIsRangeChecked() ||
1840 CurDAG->SignBitIsZero(N0))) {
1841 std::tie(VAddr, SOffset) = foldFrameIndex(N0);
1842 ImmOffset =
CurDAG->getTargetConstant(
C1,
DL, MVT::i32);
1848 std::tie(VAddr, SOffset) = foldFrameIndex(Addr);
1849 ImmOffset =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1857 if (!
Reg.isPhysical())
1859 const auto *RC =
TRI.getPhysRegBaseClass(
Reg);
1860 return RC &&
TRI.isSGPRClass(RC);
1863bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffset(
SDNode *Parent,
1868 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
1869 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1871 const SIMachineFunctionInfo *
Info =
MF.getInfo<SIMachineFunctionInfo>();
1876 SRsrc =
CurDAG->getRegister(
Info->getScratchRSrcReg(), MVT::v4i32);
1882 ConstantSDNode *CAddr;
1895 SOffset =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1900 SRsrc =
CurDAG->getRegister(
Info->getScratchRSrcReg(), MVT::v4i32);
1906bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1909 SDValue Ptr, VAddr, Offen, Idxen, Addr64;
1910 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1912 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset,
Offset, Offen, Idxen, Addr64))
1931bool AMDGPUDAGToDAGISel::SelectBUFSOffset(
SDValue ByteOffsetNode,
1933 if (Subtarget->hasRestrictedSOffset() &&
isNullConstant(ByteOffsetNode)) {
1934 SOffset =
CurDAG->getRegister(AMDGPU::SGPR_NULL, MVT::i32);
1938 SOffset = ByteOffsetNode;
1956bool AMDGPUDAGToDAGISel::SelectFlatOffsetImpl(
1960 int64_t OffsetVal = 0;
1963 bool Is32BitConstant =
1966 bool CanHaveFlatSegmentOffsetBug =
1967 Subtarget->hasFlatSegmentOffsetBug() &&
1968 FlatVariant == FlatAddrSpace::FLAT &&
1971 if (Subtarget->hasFlatInstOffsets() && !CanHaveFlatSegmentOffsetBug) {
1974 isBaseWithConstantOffset64(Addr, N0, N1) &&
1975 (FlatVariant != FlatAddrSpace::FlatScratch ||
1976 isFlatScratchBaseLegal(Addr))) {
1978 int64_t COffsetVal =
1979 Is32BitConstant ? COffset->getZExtValue() : COffset->getSExtValue();
1987 if (COffsetVal == 0 || FlatVariant != FlatAddrSpace::FLAT || IsInBounds ||
1989 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1990 if (
TII->isLegalFLATOffset(COffsetVal, AS, FlatVariant)) {
1992 OffsetVal = COffsetVal;
2007 std::tie(OffsetVal, RemainderOffset) =
2008 TII->splitFlatOffset(COffsetVal, AS, FlatVariant);
2011 getMaterializedScalarImm32(
Lo_32(RemainderOffset),
DL);
2018 unsigned AddOp = AMDGPU::V_ADD_CO_U32_e32;
2019 if (Subtarget->hasAddNoCarryInsts()) {
2020 AddOp = AMDGPU::V_ADD_U32_e64;
2029 CurDAG->getTargetConstant(AMDGPU::sub0,
DL, MVT::i32);
2031 CurDAG->getTargetConstant(AMDGPU::sub1,
DL, MVT::i32);
2033 SDNode *N0Lo =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
2034 DL, MVT::i32, N0, Sub0);
2035 SDNode *N0Hi =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
2036 DL, MVT::i32, N0, Sub1);
2039 getMaterializedScalarImm32(
Hi_32(RemainderOffset),
DL);
2041 SDVTList VTs =
CurDAG->getVTList(MVT::i32, MVT::i1);
2044 CurDAG->getMachineNode(AMDGPU::V_ADD_CO_U32_e64,
DL, VTs,
2045 {AddOffsetLo,
SDValue(N0Lo, 0), Clamp});
2047 SDNode *Addc =
CurDAG->getMachineNode(
2048 AMDGPU::V_ADDC_U32_e64,
DL, VTs,
2052 CurDAG->getTargetConstant(AMDGPU::VReg_64RegClassID,
DL,
2057 MVT::i64, RegSequenceArgs),
2065 VAddr = Is32BitConstant ? Expand32BitAddress(Addr) : Addr;
2066 Offset =
CurDAG->getSignedTargetConstant(OffsetVal, SDLoc(), MVT::i32);
2070bool AMDGPUDAGToDAGISel::SelectFlatOffset(
SDNode *
N,
SDValue Addr,
2073 return SelectFlatOffsetImpl(
N, Addr, VAddr,
Offset,
2077bool AMDGPUDAGToDAGISel::SelectGlobalOffset(
SDNode *
N,
SDValue Addr,
2080 return SelectFlatOffsetImpl(
N, Addr, VAddr,
Offset,
2084bool AMDGPUDAGToDAGISel::SelectScratchOffset(
SDNode *
N,
SDValue Addr,
2087 return SelectFlatOffsetImpl(
N, Addr, VAddr,
Offset,
2095 if (
Op.getValueType() == MVT::i32)
2110bool AMDGPUDAGToDAGISel::SelectGlobalSAddr(
SDNode *
N,
SDValue Addr,
2113 bool NeedIOffset)
const {
2115 int64_t ImmOffset = 0;
2116 ScaleOffset =
false;
2125 isBaseWithConstantOffset64(Addr,
LHS,
RHS)) {
2127 int64_t COffsetVal =
2128 Is32Bit ? COffset->getZExtValue() : COffset->getSExtValue();
2129 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
2133 FlatAddrSpace::FlatGlobal)) {
2135 ImmOffset = COffsetVal;
2136 }
else if (!
LHS->isDivergent()) {
2137 if (COffsetVal != 0) {
2142 int64_t SplitImmOffset = 0, RemainderOffset = COffsetVal;
2144 std::tie(SplitImmOffset, RemainderOffset) =
TII->splitFlatOffset(
2148 if (Subtarget->hasSignedGVSOffset() ?
isInt<32>(RemainderOffset)
2150 SDNode *VMov =
CurDAG->getMachineNode(
2151 AMDGPU::V_MOV_B32_e32, SL, MVT::i32,
2152 CurDAG->getTargetConstant(
Lo_32(RemainderOffset), SDLoc(),
2155 SAddr = Expand32BitAddress(
LHS);
2156 Offset =
CurDAG->getSignedTargetConstant(SplitImmOffset, SDLoc(),
2168 unsigned NumLiterals =
2169 !
TII->isInlineConstant(APInt(32,
Lo_32(COffsetVal))) +
2170 !
TII->isInlineConstant(APInt(32,
Hi_32(COffsetVal)));
2172 Subtarget->getConstantBusLimit(AMDGPU::V_ADD_U32_e64) > NumLiterals)
2177 Addr = Expand32BitAddress(Addr);
2183 if (!
LHS->isDivergent()) {
2186 ScaleOffset = SelectScaleOffset(
N,
RHS, Subtarget->hasSignedGVSOffset());
2188 RHS, Subtarget->hasSignedGVSOffset(),
CurDAG)) {
2195 if (!SAddr && !
RHS->isDivergent()) {
2197 ScaleOffset = SelectScaleOffset(
N,
LHS, Subtarget->hasSignedGVSOffset());
2199 LHS, Subtarget->hasSignedGVSOffset(),
CurDAG)) {
2206 Offset =
CurDAG->getSignedTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2211 if (Subtarget->hasScaleOffset() &&
2212 (Addr.
getOpcode() == (Subtarget->hasSignedGVSOffset()
2227 Offset =
CurDAG->getTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2239 CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32, SDLoc(Addr), MVT::i32,
2240 CurDAG->getTargetConstant(0, SDLoc(), MVT::i32));
2242 Offset =
CurDAG->getSignedTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2246bool AMDGPUDAGToDAGISel::SelectGlobalSAddr(
SDNode *
N,
SDValue Addr,
2251 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2259bool AMDGPUDAGToDAGISel::SelectGlobalSAddrCPol(
SDNode *
N,
SDValue Addr,
2264 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2269 N->getConstantOperandVal(
N->getNumOperands() - 1) & ~AMDGPU::CPol::SCAL;
2275bool AMDGPUDAGToDAGISel::SelectGlobalSAddrCPolM0(
SDNode *
N,
SDValue Addr,
2281 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2286 N->getConstantOperandVal(
N->getNumOperands() - 2) & ~AMDGPU::CPol::SCAL;
2292bool AMDGPUDAGToDAGISel::SelectGlobalSAddrGLC(
SDNode *
N,
SDValue Addr,
2297 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2301 CPol =
CurDAG->getTargetConstant(CPolVal, SDLoc(), MVT::i32);
2305bool AMDGPUDAGToDAGISel::SelectGlobalSAddrNoIOffset(
SDNode *
N,
SDValue Addr,
2311 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset, DummyOffset, ScaleOffset,
2317 N->getConstantOperandVal(
N->getNumOperands() - 1) & ~AMDGPU::CPol::SCAL;
2323bool AMDGPUDAGToDAGISel::SelectGlobalSAddrNoIOffsetM0(
SDNode *
N,
SDValue Addr,
2329 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset, DummyOffset, ScaleOffset,
2350 FI->getValueType(0));
2360bool AMDGPUDAGToDAGISel::SelectScratchSAddr(
SDNode *Parent,
SDValue Addr,
2369 int64_t COffsetVal = 0;
2371 if (
CurDAG->isBaseWithConstantOffset(Addr) && isFlatScratchBaseLegal(Addr)) {
2380 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
2383 FlatAddrSpace::FlatScratch)) {
2384 int64_t SplitImmOffset, RemainderOffset;
2385 std::tie(SplitImmOffset, RemainderOffset) =
TII->splitFlatOffset(
2388 COffsetVal = SplitImmOffset;
2392 ? getMaterializedScalarImm32(
Lo_32(RemainderOffset),
DL)
2393 :
CurDAG->getSignedTargetConstant(RemainderOffset,
DL, MVT::i32);
2394 SAddr =
SDValue(
CurDAG->getMachineNode(AMDGPU::S_ADD_I32,
DL, MVT::i32,
2399 Offset =
CurDAG->getSignedTargetConstant(COffsetVal,
DL, MVT::i32);
2405bool AMDGPUDAGToDAGISel::checkFlatScratchSVSSwizzleBug(
2407 if (!Subtarget->hasFlatScratchSVSSwizzleBug())
2413 KnownBits VKnown =
CurDAG->computeKnownBits(VAddr);
2420 return (VMax & 3) + (
SMax & 3) >= 4;
2423bool AMDGPUDAGToDAGISel::SelectScratchSVAddr(
SDNode *
N,
SDValue Addr,
2427 int64_t ImmOffset = 0;
2431 if (isBaseWithConstantOffset64(Addr,
LHS,
RHS)) {
2433 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
2438 ImmOffset = COffsetVal;
2439 }
else if (!
LHS->isDivergent() && COffsetVal > 0) {
2443 int64_t SplitImmOffset, RemainderOffset;
2444 std::tie(SplitImmOffset, RemainderOffset) =
2449 SDNode *VMov =
CurDAG->getMachineNode(
2450 AMDGPU::V_MOV_B32_e32, SL, MVT::i32,
2451 CurDAG->getTargetConstant(RemainderOffset, SDLoc(), MVT::i32));
2454 if (!isFlatScratchBaseLegal(Addr))
2456 if (checkFlatScratchSVSSwizzleBug(VAddr, SAddr, SplitImmOffset))
2458 Offset =
CurDAG->getTargetConstant(SplitImmOffset, SDLoc(), MVT::i32);
2459 CPol =
CurDAG->getTargetConstant(0, SDLoc(), MVT::i32);
2471 if (!
LHS->isDivergent() &&
RHS->isDivergent()) {
2474 }
else if (!
RHS->isDivergent() &&
LHS->isDivergent()) {
2481 if (OrigAddr != Addr) {
2482 if (!isFlatScratchBaseLegalSVImm(OrigAddr))
2485 if (!isFlatScratchBaseLegalSV(OrigAddr))
2489 if (checkFlatScratchSVSSwizzleBug(VAddr, SAddr, ImmOffset))
2492 Offset =
CurDAG->getSignedTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2494 bool ScaleOffset = SelectScaleOffset(
N, VAddr,
true );
2503bool AMDGPUDAGToDAGISel::isSOffsetLegalWithImmOffset(
SDValue *SOffset,
2506 int64_t ImmOffset)
const {
2507 if (!IsBuffer && !Imm32Only && ImmOffset < 0 &&
2509 KnownBits SKnown =
CurDAG->computeKnownBits(*SOffset);
2521 bool IsSigned,
bool IsSMEM)
const {
2522 bool ScaleOffset =
false;
2523 if (!Subtarget->hasScaleOffset() || !
Offset)
2537 (IsSigned &&
Offset.getOpcode() == AMDGPUISD::MUL_I24) ||
2538 Offset.getOpcode() == AMDGPUISD::MUL_U24 ||
2539 (
Offset.isMachineOpcode() &&
2540 Offset.getMachineOpcode() ==
2541 (IsSigned ? AMDGPU::S_MUL_I64_I32_PSEUDO
2542 : AMDGPU::S_MUL_U64_U32_PSEUDO))) {
2544 ScaleOffset =
C->getZExtValue() ==
Size;
2553 if (
Off.getValueType() == MVT::i64) {
2555 if (
Known.countMaxActiveBits() + Bits > 32)
2559 SDNodeFlags
Flags =
Off->getFlags();
2561 if (IsSigned && !
Flags.hasNoSignedWrap() &&
2562 CurDAG->ComputeNumSignBits(Idx) <= Bits)
2564 if (!IsSigned && !
Flags.hasNoUnsignedWrap() &&
2565 CurDAG->computeKnownBits(Idx).countMinLeadingZeros() < Bits)
2576bool AMDGPUDAGToDAGISel::SelectSMRDOffset(
SDNode *
N,
SDValue ByteOffsetNode,
2578 bool Imm32Only,
bool IsBuffer,
2579 bool HasSOffset, int64_t ImmOffset,
2580 bool *ScaleOffset)
const {
2582 "Cannot match both soffset and offset at the same time!");
2587 *ScaleOffset = SelectScaleOffset(
N, ByteOffsetNode,
false ,
2598 *SOffset = ByteOffsetNode;
2599 return isSOffsetLegalWithImmOffset(SOffset, Imm32Only, IsBuffer,
2605 return isSOffsetLegalWithImmOffset(SOffset, Imm32Only, IsBuffer,
2612 SDLoc SL(ByteOffsetNode);
2616 int64_t ByteOffset = IsBuffer ?
C->getZExtValue() :
C->getSExtValue();
2618 *Subtarget, ByteOffset, IsBuffer, HasSOffset);
2619 if (EncodedOffset &&
Offset && !Imm32Only) {
2620 *
Offset =
CurDAG->getSignedTargetConstant(*EncodedOffset, SL, MVT::i32);
2629 if (EncodedOffset &&
Offset && Imm32Only) {
2630 *
Offset =
CurDAG->getTargetConstant(*EncodedOffset, SL, MVT::i32);
2638 SDValue C32Bit =
CurDAG->getTargetConstant(ByteOffset, SL, MVT::i32);
2640 CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL, MVT::i32, C32Bit), 0);
2647SDValue AMDGPUDAGToDAGISel::Expand32BitAddress(
SDValue Addr)
const {
2655 const SIMachineFunctionInfo *
Info =
MF.getInfo<SIMachineFunctionInfo>();
2656 unsigned AddrHiVal =
Info->get32BitAddressHighBits();
2657 SDValue AddrHi =
CurDAG->getTargetConstant(AddrHiVal, SL, MVT::i32);
2660 CurDAG->getTargetConstant(AMDGPU::SReg_64_XEXECRegClassID, SL, MVT::i32),
2662 CurDAG->getTargetConstant(AMDGPU::sub0, SL, MVT::i32),
2663 SDValue(
CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL, MVT::i32, AddrHi),
2665 CurDAG->getTargetConstant(AMDGPU::sub1, SL, MVT::i32),
2668 return SDValue(
CurDAG->getMachineNode(AMDGPU::REG_SEQUENCE, SL, MVT::i64,
2675bool AMDGPUDAGToDAGISel::SelectSMRDBaseOffset(
SDNode *
N,
SDValue Addr,
2678 bool IsBuffer,
bool HasSOffset,
2680 bool *ScaleOffset)
const {
2682 assert(!Imm32Only && !IsBuffer);
2685 if (!SelectSMRDBaseOffset(
N, Addr,
B,
nullptr,
Offset,
false,
false,
true))
2690 ImmOff =
C->getSExtValue();
2692 return SelectSMRDBaseOffset(
N,
B, SBase, SOffset,
nullptr,
false,
false,
2693 true, ImmOff, ScaleOffset);
2713 if (SelectSMRDOffset(
N, N1, SOffset,
Offset, Imm32Only, IsBuffer, HasSOffset,
2714 ImmOffset, ScaleOffset)) {
2718 if (SelectSMRDOffset(
N, N0, SOffset,
Offset, Imm32Only, IsBuffer, HasSOffset,
2719 ImmOffset, ScaleOffset)) {
2728 bool Imm32Only,
bool *ScaleOffset)
const {
2729 if (SelectSMRDBaseOffset(
N, Addr, SBase, SOffset,
Offset, Imm32Only,
2732 SBase = Expand32BitAddress(SBase);
2737 SBase = Expand32BitAddress(Addr);
2738 *
Offset =
CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
2745bool AMDGPUDAGToDAGISel::SelectSMRDImm(
SDValue Addr,
SDValue &SBase,
2747 return SelectSMRD(
nullptr, Addr, SBase,
nullptr,
2751bool AMDGPUDAGToDAGISel::SelectSMRDImm32(
SDValue Addr,
SDValue &SBase,
2754 return SelectSMRD(
nullptr, Addr, SBase,
nullptr,
2761 if (!SelectSMRD(
N, Addr, SBase, &SOffset,
nullptr,
2762 false, &ScaleOffset))
2766 SDLoc(
N), MVT::i32);
2770bool AMDGPUDAGToDAGISel::SelectSMRDSgprImm(
SDNode *
N,
SDValue Addr,
2775 if (!SelectSMRD(
N, Addr, SBase, &SOffset, &
Offset,
false, &ScaleOffset))
2779 SDLoc(
N), MVT::i32);
2784 return SelectSMRDOffset(
nullptr,
N,
nullptr, &
Offset,
2788bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm32(
SDValue N,
2791 return SelectSMRDOffset(
nullptr,
N,
nullptr, &
Offset,
2795bool AMDGPUDAGToDAGISel::SelectSMRDBufferSgprImm(
SDValue N,
SDValue &SOffset,
2799 return N.getValueType() == MVT::i32 &&
2800 SelectSMRDBaseOffset(
nullptr,
N, SOffset,
2805bool AMDGPUDAGToDAGISel::SelectMOVRELOffset(
SDValue Index,
2810 if (
CurDAG->isBaseWithConstantOffset(Index)) {
2819 if (
C1->getSExtValue() <= 0 ||
CurDAG->SignBitIsZero(N0) ||
2835SDNode *AMDGPUDAGToDAGISel::getBFE32(
bool IsSigned,
const SDLoc &
DL,
2839 unsigned Opcode = IsSigned ? AMDGPU::V_BFE_I32_e64 : AMDGPU::V_BFE_U32_e64;
2843 return CurDAG->getMachineNode(Opcode,
DL, MVT::i32, Val,
Off, W);
2845 unsigned Opcode = IsSigned ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32;
2849 uint32_t PackedVal =
Offset | (Width << 16);
2850 SDValue PackedConst =
CurDAG->getTargetConstant(PackedVal,
DL, MVT::i32);
2852 return CurDAG->getMachineNode(Opcode,
DL, MVT::i32, Val, PackedConst);
2855void AMDGPUDAGToDAGISel::SelectS_BFEFromShifts(
SDNode *
N) {
2860 const SDValue &Shl =
N->getOperand(0);
2865 uint32_t BVal =
B->getZExtValue();
2866 uint32_t CVal =
C->getZExtValue();
2868 if (0 < BVal && BVal <= CVal && CVal < 32) {
2878void AMDGPUDAGToDAGISel::SelectS_BFE(
SDNode *
N) {
2879 switch (
N->getOpcode()) {
2881 if (
N->getOperand(0).getOpcode() ==
ISD::SRL) {
2884 const SDValue &Srl =
N->getOperand(0);
2888 if (Shift && Mask) {
2890 uint32_t MaskVal =
Mask->getZExtValue();
2902 if (
N->getOperand(0).getOpcode() ==
ISD::AND) {
2909 if (Shift && Mask) {
2911 uint32_t MaskVal =
Mask->getZExtValue() >> ShiftVal;
2920 }
else if (
N->getOperand(0).getOpcode() ==
ISD::SHL) {
2921 SelectS_BFEFromShifts(
N);
2926 if (
N->getOperand(0).getOpcode() ==
ISD::SHL) {
2927 SelectS_BFEFromShifts(
N);
2942 unsigned Width =
cast<VTSDNode>(
N->getOperand(1))->getVT().getSizeInBits();
2952bool AMDGPUDAGToDAGISel::isCBranchSCC(
const SDNode *
N)
const {
2954 if (!
N->hasOneUse())
2961 if (!
Cond.hasOneUse() ||
2965 MVT VT =
Cond.getOperand(0).getSimpleValueType();
2967 return VT == MVT::i16 || VT == MVT::i32 || VT == MVT::i64;
2972 if (VT == MVT::i64) {
2975 Subtarget->hasScalarCompareEq64();
2978 if ((VT == MVT::f16 || VT == MVT::f32) && Subtarget->hasSALUFloatInsts())
3011void AMDGPUDAGToDAGISel::SelectBRCOND(
SDNode *
N) {
3014 if (
Cond.isUndef()) {
3015 CurDAG->SelectNodeTo(
N, AMDGPU::SI_BR_UNDEF, MVT::Other,
3016 N->getOperand(2),
N->getOperand(0));
3020 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
3022 bool UseSCCBr = isCBranchSCC(
N) && isUniformBr(
N);
3023 bool AndExec = !UseSCCBr;
3024 bool Negate =
false;
3027 Cond->getOperand(0)->getOpcode() == AMDGPUISD::SETCC) {
3029 auto CC =
Cond->getOperandCondCode(2);
3042 bool NegatedBallot =
false;
3045 UseSCCBr = !BallotCond->isDivergent();
3046 Negate = Negate ^ NegatedBallot;
3061 UseSCCBr ? (Negate ? AMDGPU::S_CBRANCH_SCC0 : AMDGPU::S_CBRANCH_SCC1)
3062 : (Negate ? AMDGPU::S_CBRANCH_VCCZ : AMDGPU::S_CBRANCH_VCCNZ);
3063 Register CondReg = UseSCCBr ? AMDGPU::SCC :
TRI->getVCC();
3082 Subtarget->isWave32() ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64, SL,
3084 CurDAG->getRegister(Subtarget->isWave32() ? AMDGPU::EXEC_LO
3092 CurDAG->SelectNodeTo(
N, BrOp, MVT::Other,
3097void AMDGPUDAGToDAGISel::SelectFP_EXTEND(
SDNode *
N) {
3098 if (Subtarget->hasSALUFloatInsts() &&
N->getValueType(0) == MVT::f32 &&
3099 !
N->isDivergent()) {
3101 if (Src.getValueType() == MVT::f16) {
3103 CurDAG->SelectNodeTo(
N, AMDGPU::S_CVT_HI_F32_F16,
N->getVTList(),
3113void AMDGPUDAGToDAGISel::SelectDSAppendConsume(
SDNode *
N,
unsigned IntrID) {
3116 unsigned Opc = IntrID == Intrinsic::amdgcn_ds_append ?
3117 AMDGPU::DS_APPEND : AMDGPU::DS_CONSUME;
3122 MachineMemOperand *MMO =
M->getMemOperand();
3126 if (
CurDAG->isBaseWithConstantOffset(Ptr)) {
3131 if (isDSOffsetLegal(PtrBase, OffsetVal.
getZExtValue())) {
3132 N = glueCopyToM0(
N, PtrBase);
3133 Offset =
CurDAG->getTargetConstant(OffsetVal, SDLoc(), MVT::i32);
3138 N = glueCopyToM0(
N, Ptr);
3139 Offset =
CurDAG->getTargetConstant(0, SDLoc(), MVT::i32);
3144 CurDAG->getTargetConstant(IsGDS, SDLoc(), MVT::i32),
3149 SDNode *Selected =
CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(),
Ops);
3155void AMDGPUDAGToDAGISel::SelectDSBvhStackIntrinsic(
SDNode *
N,
unsigned IntrID) {
3158 case Intrinsic::amdgcn_ds_bvh_stack_rtn:
3159 case Intrinsic::amdgcn_ds_bvh_stack_push4_pop1_rtn:
3160 Opc = AMDGPU::DS_BVH_STACK_RTN_B32;
3162 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop1_rtn:
3163 Opc = AMDGPU::DS_BVH_STACK_PUSH8_POP1_RTN_B32;
3165 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop2_rtn:
3166 Opc = AMDGPU::DS_BVH_STACK_PUSH8_POP2_RTN_B64;
3169 SDValue Ops[] = {
N->getOperand(2),
N->getOperand(3),
N->getOperand(4),
3170 N->getOperand(5),
N->getOperand(0)};
3173 MachineMemOperand *MMO =
M->getMemOperand();
3174 SDNode *Selected =
CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(),
Ops);
3178void AMDGPUDAGToDAGISel::SelectTensorLoadStore(
SDNode *
N,
unsigned IntrID) {
3179 bool IsLoad = IntrID == Intrinsic::amdgcn_tensor_load_to_lds;
3181 IsLoad ? AMDGPU::TENSOR_LOAD_TO_LDS_d4 : AMDGPU::TENSOR_STORE_FROM_LDS_d4;
3193 Opc = IsLoad ? AMDGPU::TENSOR_LOAD_TO_LDS_d2
3194 : AMDGPU::TENSOR_STORE_FROM_LDS_d2;
3206 (void)
CurDAG->SelectNodeTo(
N,
Opc, MVT::Other, TensorOps);
3211 case Intrinsic::amdgcn_ds_gws_init:
3212 return AMDGPU::DS_GWS_INIT;
3213 case Intrinsic::amdgcn_ds_gws_barrier:
3214 return AMDGPU::DS_GWS_BARRIER;
3215 case Intrinsic::amdgcn_ds_gws_sema_v:
3216 return AMDGPU::DS_GWS_SEMA_V;
3217 case Intrinsic::amdgcn_ds_gws_sema_br:
3218 return AMDGPU::DS_GWS_SEMA_BR;
3219 case Intrinsic::amdgcn_ds_gws_sema_p:
3220 return AMDGPU::DS_GWS_SEMA_P;
3221 case Intrinsic::amdgcn_ds_gws_sema_release_all:
3222 return AMDGPU::DS_GWS_SEMA_RELEASE_ALL;
3228void AMDGPUDAGToDAGISel::SelectDS_GWS(
SDNode *
N,
unsigned IntrID) {
3229 if (!Subtarget->hasGWS() ||
3230 (IntrID == Intrinsic::amdgcn_ds_gws_sema_release_all &&
3231 !Subtarget->hasGWSSemaReleaseAll())) {
3238 const bool HasVSrc =
N->getNumOperands() == 4;
3239 assert(HasVSrc ||
N->getNumOperands() == 3);
3242 SDValue BaseOffset =
N->getOperand(HasVSrc ? 3 : 2);
3245 MachineMemOperand *MMO =
M->getMemOperand();
3258 glueCopyToM0(
N,
CurDAG->getTargetConstant(0, SL, MVT::i32));
3259 ImmOffset = ConstOffset->getZExtValue();
3261 if (
CurDAG->isBaseWithConstantOffset(BaseOffset)) {
3270 =
CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL, MVT::i32,
3274 =
CurDAG->getMachineNode(AMDGPU::S_LSHL_B32, SL, MVT::i32,
3276 CurDAG->getTargetConstant(16, SL, MVT::i32));
3277 glueCopyToM0(
N,
SDValue(M0Base, 0));
3281 SDValue OffsetField =
CurDAG->getTargetConstant(ImmOffset, SL, MVT::i32);
3285 const MCInstrDesc &InstrDesc =
TII->get(
Opc);
3286 int Data0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::data0);
3292 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
3295 MVT DataVT =
Data.getValueType().getSimpleVT();
3296 if (
TRI->isTypeLegalForClass(*DataRC, DataVT)) {
3298 Ops.push_back(
N->getOperand(2));
3304 CurDAG->getTargetConstant(AMDGPU::sub0, SL, MVT::i32),
3306 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, SL, MVT::i32),
3308 CurDAG->getTargetConstant(AMDGPU::sub1, SL, MVT::i32)};
3311 SL, MVT::v2i32, RegSeqOps),
3316 Ops.push_back(OffsetField);
3317 Ops.push_back(Chain);
3319 SDNode *Selected =
CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(),
Ops);
3323void AMDGPUDAGToDAGISel::SelectInterpP1F16(
SDNode *
N) {
3324 if (Subtarget->getLDSBankCount() != 16) {
3354 SDVTList VTs =
CurDAG->getVTList(MVT::f32, MVT::Other);
3357 CurDAG->getMachineNode(AMDGPU::V_INTERP_MOV_F32,
DL, VTs, {
3358 CurDAG->getTargetConstant(2,
DL, MVT::i32),
3364 SDNode *InterpP1LV =
3365 CurDAG->getMachineNode(AMDGPU::V_INTERP_P1LV_F16,
DL, MVT::f32, {
3366 CurDAG->getTargetConstant(0,
DL, MVT::i32),
3370 CurDAG->getTargetConstant(0,
DL, MVT::i32),
3373 CurDAG->getTargetConstant(0,
DL, MVT::i1),
3374 CurDAG->getTargetConstant(0,
DL, MVT::i32),
3381void AMDGPUDAGToDAGISel::SelectINTRINSIC_W_CHAIN(
SDNode *
N) {
3382 unsigned IntrID =
N->getConstantOperandVal(1);
3384 case Intrinsic::amdgcn_ds_append:
3385 case Intrinsic::amdgcn_ds_consume: {
3386 if (
N->getValueType(0) != MVT::i32)
3388 SelectDSAppendConsume(
N, IntrID);
3391 case Intrinsic::amdgcn_ds_bvh_stack_rtn:
3392 case Intrinsic::amdgcn_ds_bvh_stack_push4_pop1_rtn:
3393 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop1_rtn:
3394 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop2_rtn:
3395 SelectDSBvhStackIntrinsic(
N, IntrID);
3397 case Intrinsic::amdgcn_init_whole_wave:
3398 CurDAG->getMachineFunction()
3399 .getInfo<SIMachineFunctionInfo>()
3400 ->setInitWholeWave();
3407void AMDGPUDAGToDAGISel::SelectINTRINSIC_WO_CHAIN(
SDNode *
N) {
3408 unsigned IntrID =
N->getConstantOperandVal(0);
3409 unsigned Opcode = AMDGPU::INSTRUCTION_LIST_END;
3410 SDNode *ConvGlueNode =
N->getGluedNode();
3416 CurDAG->getMachineNode(TargetOpcode::CONVERGENCECTRL_GLUE, {},
3417 MVT::Glue,
SDValue(ConvGlueNode, 0));
3419 ConvGlueNode =
nullptr;
3422 case Intrinsic::amdgcn_wqm:
3423 Opcode = AMDGPU::WQM;
3425 case Intrinsic::amdgcn_softwqm:
3426 Opcode = AMDGPU::SOFT_WQM;
3428 case Intrinsic::amdgcn_wwm:
3429 case Intrinsic::amdgcn_strict_wwm:
3430 Opcode = AMDGPU::STRICT_WWM;
3432 case Intrinsic::amdgcn_strict_wqm:
3433 Opcode = AMDGPU::STRICT_WQM;
3435 case Intrinsic::amdgcn_interp_p1_f16:
3436 SelectInterpP1F16(
N);
3438 case Intrinsic::amdgcn_permlane16_swap:
3439 case Intrinsic::amdgcn_permlane32_swap: {
3440 if ((IntrID == Intrinsic::amdgcn_permlane16_swap &&
3441 !Subtarget->hasPermlane16Swap()) ||
3442 (IntrID == Intrinsic::amdgcn_permlane32_swap &&
3443 !Subtarget->hasPermlane32Swap())) {
3448 Opcode = IntrID == Intrinsic::amdgcn_permlane16_swap
3449 ? AMDGPU::V_PERMLANE16_SWAP_B32_e64
3450 : AMDGPU::V_PERMLANE32_SWAP_B32_e64;
3454 NewOps.push_back(
SDValue(ConvGlueNode, 0));
3456 bool FI =
N->getConstantOperandVal(3);
3457 NewOps[2] =
CurDAG->getTargetConstant(
3460 CurDAG->SelectNodeTo(
N, Opcode,
N->getVTList(), NewOps);
3468 if (Opcode != AMDGPU::INSTRUCTION_LIST_END) {
3470 CurDAG->SelectNodeTo(
N, Opcode,
N->getVTList(), {Src});
3475 NewOps.push_back(
SDValue(ConvGlueNode, 0));
3476 CurDAG->MorphNodeTo(
N,
N->getOpcode(),
N->getVTList(), NewOps);
3480void AMDGPUDAGToDAGISel::SelectINTRINSIC_VOID(
SDNode *
N) {
3481 unsigned IntrID =
N->getConstantOperandVal(1);
3483 case Intrinsic::amdgcn_ds_gws_init:
3484 case Intrinsic::amdgcn_ds_gws_barrier:
3485 case Intrinsic::amdgcn_ds_gws_sema_v:
3486 case Intrinsic::amdgcn_ds_gws_sema_br:
3487 case Intrinsic::amdgcn_ds_gws_sema_p:
3488 case Intrinsic::amdgcn_ds_gws_sema_release_all:
3489 SelectDS_GWS(
N, IntrID);
3491 case Intrinsic::amdgcn_tensor_load_to_lds:
3492 case Intrinsic::amdgcn_tensor_store_from_lds:
3493 SelectTensorLoadStore(
N, IntrID);
3502void AMDGPUDAGToDAGISel::SelectWAVE_ADDRESS(
SDNode *
N) {
3504 CurDAG->getTargetConstant(Subtarget->getWavefrontSizeLog2(), SDLoc(
N), MVT::i32);
3505 CurDAG->SelectNodeTo(
N, AMDGPU::S_LSHR_B32,
N->getVTList(),
3506 {N->getOperand(0), Log2WaveSize});
3509void AMDGPUDAGToDAGISel::SelectSTACKRESTORE(
SDNode *
N) {
3524 Subtarget->getWavefrontSizeLog2(), SL, MVT::i32);
3526 if (
N->isDivergent()) {
3527 SrcVal =
SDValue(
CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL,
3532 CopyVal =
SDValue(
CurDAG->getMachineNode(AMDGPU::S_LSHL_B32, SL, MVT::i32,
3533 {SrcVal, Log2WaveSize}),
3537 SDValue CopyToSP =
CurDAG->getCopyToReg(
N->getOperand(0), SL,
SP, CopyVal);
3541void AMDGPUDAGToDAGISel::SelectWRITE_REGISTER(
SDNode *
N) {
3548 CurDAG->getMachineFunction());
3552 "invalid register \"" + Twine(RegStr->
getString()) +
3553 "\" for llvm.write_register",
3554 Fn,
N->getDebugLoc()));
3566 }
else if (VT == MVT::i32) {
3567 CopyVal =
SDValue(
CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL,
3573 CurDAG->getTargetExtractSubreg(AMDGPU::sub0, SL, MVT::i32, SrcVal);
3575 CurDAG->getTargetExtractSubreg(AMDGPU::sub1, SL, MVT::i32, SrcVal);
3577 CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL, MVT::i32,
Lo),
3580 CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL, MVT::i32,
Hi),
3582 CopyVal = emitRegSequence(*
CurDAG, AMDGPU::SReg_64RegClassID, VT, {
Lo,
Hi},
3583 {AMDGPU::sub0, AMDGPU::sub1}, SL);
3590bool AMDGPUDAGToDAGISel::SelectVOP3ModsImpl(
SDValue In,
SDValue &Src,
3592 bool IsCanonicalizing,
3593 bool AllowAbs)
const {
3599 Src = Src.getOperand(0);
3600 }
else if (Src.getOpcode() ==
ISD::FSUB && IsCanonicalizing) {
3604 if (
LHS &&
LHS->isZero()) {
3606 Src = Src.getOperand(1);
3610 if (AllowAbs && Src.getOpcode() ==
ISD::FABS) {
3612 Src = Src.getOperand(0);
3625 if (IsCanonicalizing)
3640 EVT VT = Src.getValueType();
3642 (VT != MVT::i32 && VT != MVT::v2i32 && VT != MVT::i64))
3649 auto ReplaceSrc = [&]() ->
SDValue {
3651 return Src.getOperand(0);
3656 Src.getValueType(),
LHS, Index);
3682 if (SelectVOP3ModsImpl(In, Src, Mods,
true,
3684 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3691bool AMDGPUDAGToDAGISel::SelectVOP3ModsNonCanonicalizing(
3694 if (SelectVOP3ModsImpl(In, Src, Mods,
false,
3696 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3703bool AMDGPUDAGToDAGISel::SelectVOP3BMods(
SDValue In,
SDValue &Src,
3706 if (SelectVOP3ModsImpl(In, Src, Mods,
3709 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3716bool AMDGPUDAGToDAGISel::SelectVOP3NoMods(
SDValue In,
SDValue &Src)
const {
3724bool AMDGPUDAGToDAGISel::SelectVOP3NoOpSelMods(
SDValue In,
SDValue &Src)
const {
3729 return SelectVOP3NoMods(In, Src);
3732bool AMDGPUDAGToDAGISel::SelectVINTERPModsImpl(
SDValue In,
SDValue &Src,
3736 if (SelectVOP3ModsImpl(In, Src, Mods,
3741 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3748bool AMDGPUDAGToDAGISel::SelectVINTERPMods(
SDValue In,
SDValue &Src,
3750 return SelectVINTERPModsImpl(In, Src, SrcMods,
false);
3753bool AMDGPUDAGToDAGISel::SelectVINTERPModsHi(
SDValue In,
SDValue &Src,
3755 return SelectVINTERPModsImpl(In, Src, SrcMods,
true);
3758bool AMDGPUDAGToDAGISel::SelectVOP3Mods0(
SDValue In,
SDValue &Src,
3762 Clamp =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3763 Omod =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3765 return SelectVOP3Mods(In, Src, SrcMods);
3768bool AMDGPUDAGToDAGISel::SelectVOP3BMods0(
SDValue In,
SDValue &Src,
3772 Clamp =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3773 Omod =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3775 return SelectVOP3BMods(In, Src, SrcMods);
3778bool AMDGPUDAGToDAGISel::SelectVOP3OMods(
SDValue In,
SDValue &Src,
3783 Clamp =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3784 Omod =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3789bool AMDGPUDAGToDAGISel::SelectVOP3PModsPkFmaOpSel0(
SDValue In,
SDValue &Src,
3791 return SelectVOP3PMods(In, Src, SrcMods,
false,
3792 Subtarget->hasPkF32InvalidOpSel() &&
3793 In.getValueType() == MVT::v2f32);
3796bool AMDGPUDAGToDAGISel::SelectVOP3PModsPkAddMulOpSel0(
SDValue In,
SDValue &Src,
3798 if (!SelectVOP3PMods(In, Src, SrcMods))
3801 return !Subtarget->hasPkF32InvalidOpSel() ||
3802 In.getValueType() != MVT::v2f32 ||
3807bool AMDGPUDAGToDAGISel::SelectVOP3PMods(
SDValue In,
SDValue &Src,
3809 bool NoOpSel0)
const {
3816 Src = Src.getOperand(0);
3820 bool HasOpSel = Src.getValueSizeInBits() != 128;
3823 (!IsDOT || !Subtarget->hasDOTOpSelHazard()) &&
3824 (!NoOpSel0 || !isLoEltExtractHi(Src))) {
3825 unsigned VecMods = Mods;
3827 SDValue Lo = stripBitcast(Src.getOperand(0));
3828 SDValue Hi = stripBitcast(Src.getOperand(1));
3831 Lo = stripBitcast(
Lo.getOperand(0));
3836 Hi = stripBitcast(
Hi.getOperand(0));
3848 unsigned VecSize = Src.getValueSizeInBits();
3849 Lo = stripExtractLoElt(
Lo);
3850 Hi = stripExtractLoElt(
Hi);
3852 if (
Lo.getValueSizeInBits() > VecSize) {
3853 Lo =
CurDAG->getTargetExtractSubreg(
3854 (VecSize > 32) ? AMDGPU::sub0_sub1 : AMDGPU::sub0, SDLoc(In),
3858 if (
Hi.getValueSizeInBits() > VecSize) {
3859 Hi =
CurDAG->getTargetExtractSubreg(
3860 (VecSize > 32) ? AMDGPU::sub0_sub1 : AMDGPU::sub0, SDLoc(In),
3864 assert(
Lo.getValueSizeInBits() <= VecSize &&
3865 Hi.getValueSizeInBits() <= VecSize);
3867 if (
Lo ==
Hi && !isInlineImmediate(
Lo.getNode())) {
3871 if (VecSize ==
Lo.getValueSizeInBits()) {
3873 }
else if (VecSize == 32) {
3874 Src = createVOP3PSrc32FromLo16(
Lo, Src,
CurDAG, Subtarget);
3876 assert((
Lo.getValueSizeInBits() == 32 && VecSize == 64) ||
3877 (
Lo.getValueSizeInBits() == 64 && VecSize == 128));
3881 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, SL,
3882 Lo.getValueType()), 0);
3883 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
3888 auto RC =
Lo->isDivergent() ?
TRI->getVGPRClassForBitWidth(VecSize)
3889 :
TRI->getSGPRClassForBitWidth(VecSize);
3890 unsigned NumRegs =
Lo.getValueSizeInBits() == 32 ? 1 : 2;
3892 CurDAG->getTargetConstant(RC->getID(), SL, MVT::i32),
Lo,
3893 CurDAG->getTargetConstant(
TRI->getSubRegFromChannel(0, NumRegs), SL,
3898 CurDAG->getTargetConstant(
3899 TRI->getSubRegFromChannel(NumRegs, NumRegs), SL, MVT::i32)};
3901 Src =
SDValue(
CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, SL,
3902 Src.getValueType(),
Ops), 0);
3906 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3912 .bitcastToAPInt().getZExtValue();
3914 Src =
CurDAG->getTargetConstant(
Lit, SDLoc(In), MVT::i64);
3915 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3922 Src.getNumOperands() == 2) {
3927 assert(Src.getValueSizeInBits() != 128 &&
3928 "<2 x 64> VECTOR_SHUFFLE should not be legal.");
3931 ArrayRef<int>
Mask = SVN->getMask();
3933 if (Mask[0] < 2 && Mask[1] < 2 && (!NoOpSel0 || Mask[0] != 1)) {
3935 SDValue ShuffleSrc = SVN->getOperand(0);
3948 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3956 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3960bool AMDGPUDAGToDAGISel::SelectVOP3PModsDOT(
SDValue In,
SDValue &Src,
3962 return SelectVOP3PMods(In, Src, SrcMods,
true);
3965bool AMDGPUDAGToDAGISel::SelectVOP3PNoModsDOT(
SDValue In,
SDValue &Src)
const {
3967 SelectVOP3PMods(In, SrcTmp, SrcModsTmp,
true);
3976bool AMDGPUDAGToDAGISel::SelectVOP3PModsF32(
SDValue In,
SDValue &Src,
3978 SelectVOP3Mods(In, Src, SrcMods);
3981 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3985bool AMDGPUDAGToDAGISel::SelectVOP3PNoModsF32(
SDValue In,
SDValue &Src)
const {
3987 SelectVOP3PModsF32(In, SrcTmp, SrcModsTmp);
3996bool AMDGPUDAGToDAGISel::SelectWMMAOpSelVOP3PMods(
SDValue In,
3999 assert(
C->getAPIntValue().getBitWidth() == 1 &&
"expected i1 value");
4002 unsigned SrcVal =
C->getZExtValue();
4006 Src =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4013 unsigned DstRegClass;
4015 switch (Elts.
size()) {
4017 DstRegClass = AMDGPU::VReg_256RegClassID;
4021 DstRegClass = AMDGPU::VReg_128RegClassID;
4025 DstRegClass = AMDGPU::VReg_64RegClassID;
4033 Ops.push_back(
CurDAG->getTargetConstant(DstRegClass,
DL, MVT::i32));
4034 for (
unsigned i = 0; i < Elts.
size(); ++i) {
4035 Ops.push_back(Elts[i]);
4036 Ops.push_back(
CurDAG->getTargetConstant(
4039 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
DL, DstTy,
Ops);
4046 assert(
"unhandled Reg sequence size" &&
4047 (Elts.
size() == 8 || Elts.
size() == 16));
4051 for (
unsigned i = 0; i < Elts.
size(); i += 2) {
4052 SDValue LoSrc = stripExtractLoElt(stripBitcast(Elts[i]));
4057 if (Subtarget->useRealTrue16Insts()) {
4062 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
DL, MVT::i16),
4065 emitRegSequence(*
CurDAG, AMDGPU::VGPR_32RegClassID, MVT::i32,
4066 {Elts[i],
Undef}, {AMDGPU::lo16, AMDGPU::hi16},
DL);
4067 Elts[i + 1] = emitRegSequence(*
CurDAG, AMDGPU::VGPR_32RegClassID,
4068 MVT::i32, {Elts[i + 1],
Undef},
4069 {AMDGPU::lo16, AMDGPU::hi16},
DL);
4071 SDValue PackLoLo =
CurDAG->getTargetConstant(0x05040100,
DL, MVT::i32);
4073 CurDAG->getMachineNode(AMDGPU::V_PERM_B32_e64,
DL, MVT::i32,
4074 {Elts[i + 1], Elts[i], PackLoLo});
4078 return buildRegSequence32(PackedElts,
DL);
4084 unsigned ElementSize)
const {
4085 if (ElementSize == 16)
4086 return buildRegSequence16(Elts,
DL);
4087 if (ElementSize == 32)
4088 return buildRegSequence32(Elts,
DL);
4092void AMDGPUDAGToDAGISel::selectWMMAModsNegAbs(
unsigned ModOpcode,
4096 unsigned ElementSize)
const {
4101 for (
auto El : Elts) {
4104 NegAbsElts.
push_back(El->getOperand(0));
4106 if (Elts.size() != NegAbsElts.
size()) {
4108 Src =
SDValue(buildRegSequence(Elts,
DL, ElementSize), 0);
4112 Src =
SDValue(buildRegSequence(NegAbsElts,
DL, ElementSize), 0);
4118 Src =
SDValue(buildRegSequence(Elts,
DL, ElementSize), 0);
4126 std::function<
bool(
SDValue)> ModifierCheck) {
4130 for (
unsigned i = 0; i < F16Pair->getNumOperands(); ++i) {
4131 SDValue ElF16 = stripBitcast(F16Pair->getOperand(i));
4132 if (!ModifierCheck(ElF16))
4139bool AMDGPUDAGToDAGISel::SelectWMMAModsF16Neg(
SDValue In,
SDValue &Src,
4157 Src =
SDValue(buildRegSequence16(EltsF16, SDLoc(In)), 0);
4176 Src =
SDValue(buildRegSequence32(EltsV2F16, SDLoc(In)), 0);
4182 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4186bool AMDGPUDAGToDAGISel::SelectWMMAModsF16NegAbs(
SDValue In,
SDValue &Src,
4197 if (EltsF16.
empty())
4207 selectWMMAModsNegAbs(ModOpcode, Mods, EltsF16, Src, SDLoc(In), 16);
4217 if (EltsV2F16.
empty())
4226 selectWMMAModsNegAbs(ModOpcode, Mods, EltsV2F16, Src, SDLoc(In), 32);
4229 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4233bool AMDGPUDAGToDAGISel::SelectWMMAModsF32NegAbs(
SDValue In,
SDValue &Src,
4243 unsigned ModOpcode =
4254 selectWMMAModsNegAbs(ModOpcode, Mods, EltsF32, Src, SDLoc(In), 32);
4257 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4261bool AMDGPUDAGToDAGISel::SelectWMMAVISrc(
SDValue In,
SDValue &Src)
const {
4263 BitVector UndefElements;
4265 if (isInlineImmediate(
Splat.getNode())) {
4267 unsigned Imm =
C->getAPIntValue().getSExtValue();
4268 Src =
CurDAG->getTargetConstant(
Imm, SDLoc(In), MVT::i32);
4272 unsigned Imm =
C->getValueAPF().bitcastToAPInt().getSExtValue();
4273 Src =
CurDAG->getTargetConstant(
Imm, SDLoc(In), MVT::i32);
4281 SDValue SplatSrc32 = stripBitcast(In);
4283 if (
SDValue Splat32 = SplatSrc32BV->getSplatValue()) {
4284 SDValue SplatSrc16 = stripBitcast(Splat32);
4287 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
4288 std::optional<APInt> RawValue;
4290 RawValue =
C->getValueAPF().bitcastToAPInt();
4292 RawValue =
C->getAPIntValue();
4294 if (RawValue.has_value()) {
4295 EVT VT =
In.getValueType().getScalarType();
4301 if (
TII->isInlineConstant(FloatVal)) {
4302 Src =
CurDAG->getTargetConstant(RawValue.value(), SDLoc(In),
4307 if (
TII->isInlineConstant(RawValue.value())) {
4308 Src =
CurDAG->getTargetConstant(RawValue.value(), SDLoc(In),
4321 if (
CurDAG->isConstantIntBuildVectorOrConstantInt(SplatSrc32)) {
4326 int64_t LoImm = Lo32->getAPIntValue().getSExtValue();
4327 int64_t HiImm = Hi32->getAPIntValue().getSExtValue();
4328 int64_t Imm64I = (HiImm << 32) + LoImm;
4330 if (!isInlineImmediate(APInt(64, Imm64I)))
4333 }
else if (Imm64I != Imm64)
4337 Src =
CurDAG->getTargetConstant(Imm64, SDLoc(In), MVT::i64);
4344bool AMDGPUDAGToDAGISel::SelectSWMMACIndex8(
SDValue In,
SDValue &Src,
4350 const llvm::SDValue &ShiftSrc =
In.getOperand(0);
4359 IndexKey =
CurDAG->getTargetConstant(
Key, SDLoc(In), MVT::i32);
4363bool AMDGPUDAGToDAGISel::SelectSWMMACIndex16(
SDValue In,
SDValue &Src,
4369 const llvm::SDValue &ShiftSrc =
In.getOperand(0);
4378 IndexKey =
CurDAG->getTargetConstant(
Key, SDLoc(In), MVT::i32);
4382bool AMDGPUDAGToDAGISel::SelectSWMMACIndex32(
SDValue In,
SDValue &Src,
4390 const SDValue &ExtendSrc =
In.getOperand(0);
4394 const SDValue &CastSrc =
In.getOperand(0);
4398 if (
Zero &&
Zero->getZExtValue() == 0)
4409 Src = ExtractVecEltSrc;
4413 IndexKey =
CurDAG->getTargetConstant(
Key, SDLoc(In), MVT::i32);
4417bool AMDGPUDAGToDAGISel::SelectVOP3OpSel(
SDValue In,
SDValue &Src,
4421 if (!Subtarget->useRealTrue16Insts() &&
In.getValueSizeInBits() == 16 &&
4424 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4428bool AMDGPUDAGToDAGISel::SelectVOP3OpSelMods(
SDValue In,
SDValue &Src,
4431 if (!SelectVOP3ModsImpl(In, Src, Mods,
true,
4435 if (!Subtarget->useRealTrue16Insts() &&
In.getValueSizeInBits() == 16 &&
4439 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4452 Op =
Op.getOperand(0);
4454 IsExtractHigh =
false;
4457 if (!Low16 || !Low16->isZero())
4459 Op = stripBitcast(
Op.getOperand(1));
4460 if (
Op.getValueType() != MVT::bf16)
4465 if (
Op.getValueType() != MVT::i32)
4470 if (Mask->getZExtValue() == 0xffff0000) {
4471 IsExtractHigh =
true;
4472 return Op.getOperand(0);
4481 return Op.getOperand(0);
4490bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsImpl(
SDValue In,
SDValue &Src,
4494 SelectVOP3ModsImpl(In, Src, Mods);
4496 bool IsExtractHigh =
false;
4498 Src.getOperand(0).getValueType() == VT) {
4499 Src = Src.getOperand(0);
4500 }
else if (VT == MVT::bf16) {
4508 if (Src.getValueType() != VT &&
4509 (VT != MVT::bf16 || Src.getValueType() != MVT::i32))
4512 Src = stripBitcast(Src);
4518 SelectVOP3ModsImpl(Src, Src, ModsTmp);
4533 if (Src.getValueSizeInBits() == 16) {
4542 Src.getOperand(0).getValueType() == MVT::i32) {
4543 Src = Src.getOperand(0);
4547 if (Subtarget->useRealTrue16Insts())
4549 Src = createVOP3PSrc32FromLo16(Src, In,
CurDAG, Subtarget);
4550 }
else if (IsExtractHigh)
4556bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsExt(
SDValue In,
SDValue &Src,
4559 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16))
4561 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4565bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixMods(
SDValue In,
SDValue &Src,
4568 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16);
4569 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4573bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsExtNeg(
SDValue In,
SDValue &Src,
4576 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16))
4583bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsNeg(
SDValue In,
SDValue &Src,
4586 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16);
4592bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16ModsExt(
SDValue In,
SDValue &Src,
4595 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16))
4597 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4601bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16Mods(
SDValue In,
SDValue &Src,
4604 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16);
4605 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4609bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16ModsExtNeg(
4612 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16))
4619bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16ModsNeg(
SDValue In,
SDValue &Src,
4622 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16);
4632 unsigned NumOpcodes = 0;
4645 const uint8_t SrcBits[3] = { 0xf0, 0xcc, 0xaa };
4648 if (
C->isAllOnes()) {
4658 for (
unsigned I = 0;
I < Src.size(); ++
I) {
4672 if (Src.size() == 3) {
4678 if (
C->isAllOnes()) {
4680 for (
unsigned I = 0;
I < Src.size(); ++
I) {
4681 if (Src[
I] ==
LHS) {
4693 Bits = SrcBits[Src.size()];
4698 switch (In.getOpcode()) {
4706 if (!getOperandBits(
LHS, LHSBits) ||
4707 !getOperandBits(
RHS, RHSBits)) {
4708 Src = std::move(Backup);
4709 return std::make_pair(0, 0);
4730 uint8_t LHSBitsOrig = LHSBits;
4731 uint8_t RHSBitsOrig = RHSBits;
4735 NumOpcodes += LHSOp.first;
4736 LHSBits = LHSOp.second;
4743 NumOpcodes += RHSOp.first;
4744 RHSBits = RHSOp.second;
4748 auto dependsOnSlot = [](
uint8_t TT,
int Slot) ->
bool {
4749 if (Slot < 0 || Slot > 2)
4751 const uint8_t Masks[3] = {0x0f, 0x33, 0x55};
4752 const int Shifts[3] = {4, 2, 1};
4753 return ((TT ^ (TT >> Shifts[Slot])) & Masks[Slot]) != 0;
4759 const uint8_t SrcBitsConst[3] = {0xf0, 0xcc, 0xaa};
4766 NegatedInner =
Op.getOperand(0);
4767 for (
int I = 0;
I < (int)S.size();
I++) {
4768 if (Bits == SrcBitsConst[
I] && S[
I] ==
Op)
4770 if (IsNegationOp && Bits == (
uint8_t)~SrcBitsConst[
I] &&
4771 S[
I] == NegatedInner)
4782 for (
int I = 0;
I < (int)SrcAfterLHS.
size() &&
I < 3;
I++) {
4783 if (
I < (
int)Src.size() && Src[
I] != SrcAfterLHS[
I] &&
4784 dependsOnSlot(LHSBits,
I)) {
4793 if (!Stale && !RHSOp.first) {
4794 int Slot = findSlot(RHSBitsOrig,
RHS, SrcBeforeRecurse);
4796 (Slot >= (
int)Src.size() || Src[Slot] != SrcBeforeRecurse[Slot]))
4802 if (!Stale && !LHSOp.first) {
4803 int Slot = findSlot(LHSBitsOrig,
LHS, SrcBeforeRecurse);
4805 (Slot >= (
int)Src.size() || Src[Slot] != SrcBeforeRecurse[Slot]))
4810 Src = std::move(SrcBeforeRecurse);
4811 LHSBits = LHSBitsOrig;
4812 RHSBits = RHSBitsOrig;
4818 return std::make_pair(0, 0);
4822 switch (In.getOpcode()) {
4824 TTbl = LHSBits & RHSBits;
4827 TTbl = LHSBits | RHSBits;
4830 TTbl = LHSBits ^ RHSBits;
4836 return std::make_pair(NumOpcodes + 1, TTbl);
4843 unsigned NumOpcodes;
4845 std::tie(NumOpcodes, TTbl) =
BitOp3_Op(In, Src);
4849 if (NumOpcodes < 2 || Src.empty())
4855 if (NumOpcodes < 4 && !In->isDivergent())
4858 if (NumOpcodes == 2 &&
In.getValueType() == MVT::i32) {
4863 (
In.getOperand(0).getOpcode() ==
In.getOpcode() ||
4864 In.getOperand(1).getOpcode() ==
In.getOpcode()))
4878 while (Src.size() < 3)
4879 Src.push_back(Src[0]);
4885 Tbl =
CurDAG->getTargetConstant(TTbl, SDLoc(In), MVT::i32);
4891 return CurDAG->getPOISON(MVT::i32);
4894 return CurDAG->getUNDEF(MVT::i32);
4898 return CurDAG->getConstant(
C->getZExtValue() << 16, SL, MVT::i32);
4903 return CurDAG->getConstant(
4904 C->getValueAPF().bitcastToAPInt().getZExtValue() << 16, SL, MVT::i32);
4914bool AMDGPUDAGToDAGISel::isVGPRImm(
const SDNode *
N)
const {
4915 assert(
CurDAG->getTarget().getTargetTriple().isAMDGCN());
4917 const SIRegisterInfo *SIRI = Subtarget->getRegisterInfo();
4918 const SIInstrInfo *SII = Subtarget->getInstrInfo();
4921 bool AllUsesAcceptSReg =
true;
4923 Limit < 10 && U !=
E; ++U, ++Limit) {
4925 getOperandRegClass(
U->getUser(),
U->getOperandNo());
4933 if (RC != &AMDGPU::VS_32RegClass && RC != &AMDGPU::VS_64RegClass &&
4934 RC != &AMDGPU::VS_64_Align2RegClass) {
4935 AllUsesAcceptSReg =
false;
4936 SDNode *
User =
U->getUser();
4937 if (
User->isMachineOpcode()) {
4938 unsigned Opc =
User->getMachineOpcode();
4939 const MCInstrDesc &
Desc = SII->get(
Opc);
4940 if (
Desc.isCommutable()) {
4941 unsigned OpIdx =
Desc.getNumDefs() +
U->getOperandNo();
4944 unsigned CommutedOpNo = CommuteIdx1 -
Desc.getNumDefs();
4946 getOperandRegClass(
U->getUser(), CommutedOpNo);
4947 if (CommutedRC == &AMDGPU::VS_32RegClass ||
4948 CommutedRC == &AMDGPU::VS_64RegClass ||
4949 CommutedRC == &AMDGPU::VS_64_Align2RegClass)
4950 AllUsesAcceptSReg =
true;
4958 if (!AllUsesAcceptSReg)
4962 return !AllUsesAcceptSReg && (Limit < 10);
4968 bool IsModified =
false;
4974 while (Position !=
CurDAG->allnodes_end()) {
4981 if (ResNode !=
Node) {
4987 CurDAG->RemoveDeadNodes();
4988 }
while (IsModified);
4993 std::vector<SDValue> &OutOps) {
4994 switch (ConstraintID) {
4996 OutOps.push_back(
Op);
5002 MVT VT =
Op.getSimpleValueType();
5005 assert(VRC &&
"Expected valid VGPR class for RF constraint operand");
5009 CurDAG->getMachineNode(AMDGPU::COPY_TO_REGCLASS,
DL, VT, {
Op, RCVal});
5010 OutOps.push_back(
SDValue(Copy, 0));
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool getBaseWithOffsetUsingSplitOR(SelectionDAG &DAG, SDValue Addr, SDValue &N0, SDValue &N1)
static SDValue SelectSAddrFI(SelectionDAG *CurDAG, SDValue SAddr)
static SDValue matchExtFromI32orI32(SDValue Op, bool IsSigned, const SelectionDAG *DAG)
static MemSDNode * findMemSDNode(SDNode *N)
static bool IsCopyFromSGPR(const SIRegisterInfo &TRI, SDValue Val)
static SDValue combineBallotPattern(SDValue VCMP, bool &Negate)
static SDValue matchBF16FPExtendLike(SDValue Op, bool &IsExtractHigh)
static void checkWMMAElementsModifiersF16(BuildVectorSDNode *BV, std::function< bool(SDValue)> ModifierCheck)
Defines an instruction selector for the AMDGPU target.
Contains the definition of a TargetInstrInfo class that is common to all AMD GPUs.
static bool isNoUnsignedWrap(MachineInstr *Addr)
static bool isExtractHiElt(MachineRegisterInfo &MRI, Register In, Register &Out)
static std::pair< unsigned, uint8_t > BitOp3_Op(Register R, SmallVectorImpl< Register > &Src, const MachineRegisterInfo &MRI)
static unsigned gwsIntrinToOpcode(unsigned IntrID)
Base class for AMDGPU specific classes of TargetSubtarget.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const HexagonInstrInfo * TII
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
SmallVector< MachineOperand, 4 > Cond
Register const TargetRegisterInfo * TRI
Promote Memory to Register
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Provides R600 specific target descriptions.
Interface definition for R600RegisterInfo.
MachineRegisterInfo & MRI
SI DAG Lowering interface definition.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
AMDGPUDAGToDAGISelLegacy(TargetMachine &TM, CodeGenOptLevel OptLevel)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
AMDGPU specific code to select AMDGPU machine instructions for SelectionDAG operations.
bool isSDWAOperand(const SDNode *N) const
void SelectBuildVector(SDNode *N, unsigned RegClassID)
void Select(SDNode *N) override
Main hook for targets to transform nodes into machine nodes.
bool widenRegionLoad16(SDNode *N) const
bool runOnMachineFunction(MachineFunction &MF) override
void SelectVectorShuffle(SDNode *N)
void PreprocessISelDAG() override
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
AMDGPUDAGToDAGISel()=delete
void PostprocessISelDAG() override
PostprocessISelDAG() - This hook allows the target to hack on the graph right after selection.
bool SelectInlineAsmMemoryOperand(const SDValue &Op, InlineAsm::ConstraintCode ConstraintID, std::vector< SDValue > &OutOps) override
SelectInlineAsmMemoryOperand - Select the specified address as a target addressing mode,...
bool matchLoadD16FromBuildVector(SDNode *N) const
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
AMDGPUISelDAGToDAGPass(TargetMachine &TM)
static unsigned getNumIndexableVGPRs(const MachineFunction &MF)
static SDValue stripBitcast(SDValue Val)
static constexpr const fltSemantics & IEEEhalf()
static constexpr const fltSemantics & BFloat()
uint64_t getZExtValue() const
Get zero extended value.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
int64_t getSExtValue() const
Get sign extended value.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
A "pseudo-class" with methods for operating on BUILD_VECTORs.
LLVM_ABI SDValue getSplatValue(const APInt &DemandedElts, BitVector *UndefElements=nullptr) const
Returns the demanded splatted value or a null value if this is not a splat.
uint64_t getZExtValue() const
const APInt & getAPIntValue() const
int64_t getSExtValue() const
Analysis pass which computes a DominatorTree.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionPass class - This class is used to implement most global optimizations.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
void checkSubtargetFeatures(const Function &F) const
Diagnose inconsistent subtarget features before attempting to codegen function F.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
This class is used to represent ISD::LOAD nodes.
const SDValue & getBasePtr() const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Analysis pass that exposes the LoopInfo for a function.
SmallVector< LoopT *, 4 > getLoopsInPreorder() const
Return all of the loops in the function in preorder across the loop nests, with siblings in forward p...
The legacy pass manager's analysis pass to compute loop information.
unsigned getID() const
getID() - Return the register class ID number.
LLVM_ABI StringRef getString() const
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
static MVT getIntegerVT(unsigned BitWidth)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
An SDNode that represents everything that will be needed to construct a MachineInstr.
This is an abstract virtual class for memory operations.
unsigned getAddressSpace() const
Return the address space for the associated pointer.
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
const SDValue & getChain() const
EVT getMemoryVT() const
Return the type of the in-memory value.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
Wrapper class representing virtual and physical registers.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
const APInt & getAsAPIntVal() const
Helper method returns the APInt value of a ConstantSDNode.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
SDNodeFlags getFlags() const
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
unsigned getNumOperands() const
Return the number of values used by this operation.
const SDValue & getOperand(unsigned Num) const
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
bool isAnyAdd() const
Returns true if the node type is ADD or PTRADD.
static use_iterator use_end()
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned i) const
ISD::CondCode getOperandCondCode(unsigned i) const
uint64_t getConstantOperandVal(unsigned i) const
unsigned getOpcode() const
static unsigned getMaxMUBUFImmOffset(const GCNSubtarget &ST)
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx0, unsigned &SrcOpIdx1) const override
static LLVM_READONLY const TargetRegisterClass * getSGPRClassForBitWidth(unsigned BitWidth)
static unsigned getSubRegFromChannel(uint64_t Channel, uint64_t NumRegs=1)
static bool isSGPRClass(const TargetRegisterClass *RC)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
SelectionDAGISelLegacy(char &ID, std::unique_ptr< SelectionDAGISel > S)
SelectionDAGISelPass(std::unique_ptr< SelectionDAGISel > Selector)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
std::unique_ptr< FunctionLoweringInfo > FuncInfo
const TargetLowering * TLI
const TargetInstrInfo * TII
void ReplaceUses(SDValue F, SDValue T)
ReplaceUses - replace all uses of the old node F with the use of the new node T.
void ReplaceNode(SDNode *F, SDNode *T)
Replace all uses of F with T, then remove F from the DAG.
SelectionDAGISel(TargetMachine &tm, CodeGenOptLevel OL=CodeGenOptLevel::Default)
virtual bool runOnMachineFunction(MachineFunction &mf)
const TargetLowering * getTargetLowering() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI 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),...
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
SDValue getTargetFrameIndex(int FI, EVT VT)
LLVM_ABI bool SignBitIsZero(SDValue Op, unsigned Depth=0) const
Return true if the sign bit of Op is known to be zero.
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI bool isBaseWithConstantOffset(SDValue Op) const
Return true if the specified operand is an ISD::ADD with a ConstantSDNode on the right-hand side,...
MachineFunction & getMachineFunction() const
ilist< SDNode >::iterator allnodes_iterator
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
static const unsigned CommuteAnyOperandIndex
Primary interface to the complete machine description for the target machine.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CONSTANT_ADDRESS_32BIT
Address space for 32-bit constant memory.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::optional< int64_t > getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST, int64_t ByteOffset)
bool isGFX12Plus(const MCSubtargetInfo &STI)
constexpr int64_t getNullPointerValue(unsigned AS)
Get the null pointer value for the given address space.
bool isValid32BitLiteral(uint64_t Val, bool IsFP64)
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
bool hasSMRDSignedImmOffset(const MCSubtargetInfo &ST)
std::optional< int64_t > getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset, bool IsBuffer, bool HasSOffset)
bool isExtendedGlobalAddrSpace(unsigned AS)
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
@ PTRADD
PTRADD represents pointer arithmetic semantics, for targets that opt in using shouldPreservePtrArith(...
@ POISON
POISON - A poison node.
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
@ ADD
Simple integer binary arithmetic operators.
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
@ FADD
Simple binary floating point operators.
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
@ CONVERGENCECTRL_GLUE
This does not correspond to any convergence control intrinsic.
@ SIGN_EXTEND
Conversion operators.
@ SCALAR_TO_VECTOR
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
@ UNDEF
UNDEF - An undefined node.
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
@ SHL
Shift and rotation operations.
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ FMINNUM
FMINNUM/FMAXNUM - Same semantics as the llvm.minnum/maxnum intrinsics.
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
@ BRCOND
BRCOND - Conditional branch.
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
bool isExtOpcode(unsigned Opcode)
LLVM_ABI bool isBuildVectorAllZeros(SDValue V)
Return true if the specified value is a BUILD_VECTOR where all of the elements are 0 or undef.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
@ User
could "use" a pointer
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
@ Known
Known to have no common set bits.
@ Undef
Value of the register doesn't matter.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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...
LLVM_ABI LLT getLLTForMVT(MVT Ty)
Get a rough equivalent of an LLT for a given MVT.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
bool isBoolSGPR(SDValue V)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
@ Off
Use window algorithm after SMS algorithm fails.
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool getConstantValue(SDValue N, uint32_t &Out)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
CodeGenOptLevel
Code generation optimization level.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionPass * createAMDGPUISelDag(TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a AMDGPU-specific.
@ SMax
Signed integer max implemented in terms of select(cmp()).
@ And
Bitwise or logical AND of integers.
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
unsigned M0(unsigned Val)
LLVM_ABI ConstantSDNode * isConstOrConstSplat(SDValue N, bool AllowUndefs=false, bool AllowTruncation=false)
Returns the SDNode if it is a constant splat BuildVector or constant int.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
LLVM_ABI bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
MCRegisterClass TargetRegisterClass
Implement std::hash so that hash_code can be used in STL containers.
EVT changeTypeToInteger() const
Return the type converted to an equivalently sized integer or vector with integer element type.
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
uint64_t getScalarSizeInBits() const
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
bool isVector() const
Return true if this is a vector value type.
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false, bool SelfAdd=false)
Compute knownbits resulting from addition of LHS and RHS.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
static unsigned getSubRegFromChannel(unsigned Channel)
bool hasNoUnsignedWrap() const
This represents a list of ValueType's that has been intern'd by a SelectionDAG.