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())
1663 Addr = Expand32BitAddress(Addr);
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;
1675 if (
CurDAG->isBaseWithConstantOffset(Addr)) {
1688 Addr64 =
CurDAG->getTargetConstant(1,
DL, MVT::i1);
1694 Ptr =
SDValue(buildSMovImm64(
DL, 0, MVT::v2i32), 0);
1710 Ptr =
SDValue(buildSMovImm64(
DL, 0, MVT::v2i32), 0);
1712 Addr64 =
CurDAG->getTargetConstant(1,
DL, MVT::i1);
1716 VAddr =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1726 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1727 if (
TII->isLegalMUBUFImmOffset(
C1->getZExtValue())) {
1737 AMDGPU::S_MOV_B32,
DL, MVT::i32,
1738 CurDAG->getTargetConstant(
C1->getZExtValue(),
DL, MVT::i32)),
1743bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(
SDValue Addr,
SDValue &SRsrc,
1746 SDValue Ptr, Offen, Idxen, Addr64;
1750 if (!Subtarget->hasAddr64())
1753 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset,
Offset, Offen, Idxen, Addr64))
1757 if (
C->getSExtValue()) {
1770std::pair<SDValue, SDValue> AMDGPUDAGToDAGISel::foldFrameIndex(
SDValue N)
const {
1775 FI ?
CurDAG->getTargetFrameIndex(FI->getIndex(), FI->getValueType(0)) :
N;
1781 return std::pair(TFI,
CurDAG->getTargetConstant(0,
DL, MVT::i32));
1784bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(
SDNode *Parent,
1791 const SIMachineFunctionInfo *
Info =
MF.getInfo<SIMachineFunctionInfo>();
1793 Rsrc =
CurDAG->getRegister(
Info->getScratchRSrcReg(), MVT::v4i32);
1796 int64_t
Imm = CAddr->getSExtValue();
1797 const int64_t NullPtr =
1800 if (
Imm != NullPtr) {
1803 CurDAG->getTargetConstant(
Imm & ~MaxOffset,
DL, MVT::i32);
1804 MachineSDNode *MovHighBits =
CurDAG->getMachineNode(
1805 AMDGPU::V_MOV_B32_e32,
DL, MVT::i32, HighBits);
1806 VAddr =
SDValue(MovHighBits, 0);
1808 SOffset =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1809 ImmOffset =
CurDAG->getTargetConstant(
Imm & MaxOffset,
DL, MVT::i32);
1814 if (
CurDAG->isBaseWithConstantOffset(Addr)) {
1835 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1836 if (
TII->isLegalMUBUFImmOffset(
C1) &&
1837 (!Subtarget->privateMemoryResourceIsRangeChecked() ||
1838 CurDAG->SignBitIsZero(N0))) {
1839 std::tie(VAddr, SOffset) = foldFrameIndex(N0);
1840 ImmOffset =
CurDAG->getTargetConstant(
C1,
DL, MVT::i32);
1846 std::tie(VAddr, SOffset) = foldFrameIndex(Addr);
1847 ImmOffset =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1855 if (!
Reg.isPhysical())
1857 const auto *RC =
TRI.getPhysRegBaseClass(
Reg);
1858 return RC &&
TRI.isSGPRClass(RC);
1861bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffset(
SDNode *Parent,
1866 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
1867 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1869 const SIMachineFunctionInfo *
Info =
MF.getInfo<SIMachineFunctionInfo>();
1874 SRsrc =
CurDAG->getRegister(
Info->getScratchRSrcReg(), MVT::v4i32);
1880 ConstantSDNode *CAddr;
1893 SOffset =
CurDAG->getTargetConstant(0,
DL, MVT::i32);
1898 SRsrc =
CurDAG->getRegister(
Info->getScratchRSrcReg(), MVT::v4i32);
1904bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1907 SDValue Ptr, VAddr, Offen, Idxen, Addr64;
1908 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1910 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset,
Offset, Offen, Idxen, Addr64))
1929bool AMDGPUDAGToDAGISel::SelectBUFSOffset(
SDValue ByteOffsetNode,
1931 if (Subtarget->hasRestrictedSOffset() &&
isNullConstant(ByteOffsetNode)) {
1932 SOffset =
CurDAG->getRegister(AMDGPU::SGPR_NULL, MVT::i32);
1936 SOffset = ByteOffsetNode;
1954bool AMDGPUDAGToDAGISel::SelectFlatOffsetImpl(
1958 int64_t OffsetVal = 0;
1962 Addr = Expand32BitAddress(Addr);
1964 bool CanHaveFlatSegmentOffsetBug =
1965 Subtarget->hasFlatSegmentOffsetBug() &&
1966 FlatVariant == FlatAddrSpace::FLAT &&
1969 if (Subtarget->hasFlatInstOffsets() && !CanHaveFlatSegmentOffsetBug) {
1971 if (isBaseWithConstantOffset64(Addr, N0, N1) &&
1972 (FlatVariant != FlatAddrSpace::FlatScratch ||
1973 isFlatScratchBaseLegal(Addr))) {
1981 if (COffsetVal == 0 || FlatVariant != FlatAddrSpace::FLAT || IsInBounds) {
1982 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
1983 if (
TII->isLegalFLATOffset(COffsetVal, AS, FlatVariant)) {
1985 OffsetVal = COffsetVal;
2000 std::tie(OffsetVal, RemainderOffset) =
2001 TII->splitFlatOffset(COffsetVal, AS, FlatVariant);
2004 getMaterializedScalarImm32(
Lo_32(RemainderOffset),
DL);
2011 unsigned AddOp = AMDGPU::V_ADD_CO_U32_e32;
2012 if (Subtarget->hasAddNoCarryInsts()) {
2013 AddOp = AMDGPU::V_ADD_U32_e64;
2022 CurDAG->getTargetConstant(AMDGPU::sub0,
DL, MVT::i32);
2024 CurDAG->getTargetConstant(AMDGPU::sub1,
DL, MVT::i32);
2026 SDNode *N0Lo =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
2027 DL, MVT::i32, N0, Sub0);
2028 SDNode *N0Hi =
CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
2029 DL, MVT::i32, N0, Sub1);
2032 getMaterializedScalarImm32(
Hi_32(RemainderOffset),
DL);
2034 SDVTList VTs =
CurDAG->getVTList(MVT::i32, MVT::i1);
2037 CurDAG->getMachineNode(AMDGPU::V_ADD_CO_U32_e64,
DL, VTs,
2038 {AddOffsetLo,
SDValue(N0Lo, 0), Clamp});
2040 SDNode *Addc =
CurDAG->getMachineNode(
2041 AMDGPU::V_ADDC_U32_e64,
DL, VTs,
2045 CurDAG->getTargetConstant(AMDGPU::VReg_64RegClassID,
DL,
2050 MVT::i64, RegSequenceArgs),
2059 Offset =
CurDAG->getSignedTargetConstant(OffsetVal, SDLoc(), MVT::i32);
2063bool AMDGPUDAGToDAGISel::SelectFlatOffset(
SDNode *
N,
SDValue Addr,
2066 return SelectFlatOffsetImpl(
N, Addr, VAddr,
Offset,
2070bool AMDGPUDAGToDAGISel::SelectGlobalOffset(
SDNode *
N,
SDValue Addr,
2073 return SelectFlatOffsetImpl(
N, Addr, VAddr,
Offset,
2077bool AMDGPUDAGToDAGISel::SelectScratchOffset(
SDNode *
N,
SDValue Addr,
2080 return SelectFlatOffsetImpl(
N, Addr, VAddr,
Offset,
2088 if (
Op.getValueType() == MVT::i32)
2103bool AMDGPUDAGToDAGISel::SelectGlobalSAddr(
SDNode *
N,
SDValue Addr,
2106 bool NeedIOffset)
const {
2108 int64_t ImmOffset = 0;
2109 ScaleOffset =
false;
2111 Addr = Expand32BitAddress(Addr);
2117 if (isBaseWithConstantOffset64(Addr,
LHS,
RHS)) {
2119 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
2123 FlatAddrSpace::FlatGlobal)) {
2125 ImmOffset = COffsetVal;
2126 }
else if (!
LHS->isDivergent()) {
2127 if (COffsetVal != 0) {
2132 int64_t SplitImmOffset = 0, RemainderOffset = COffsetVal;
2134 std::tie(SplitImmOffset, RemainderOffset) =
TII->splitFlatOffset(
2138 if (Subtarget->hasSignedGVSOffset() ?
isInt<32>(RemainderOffset)
2140 SDNode *VMov =
CurDAG->getMachineNode(
2141 AMDGPU::V_MOV_B32_e32, SL, MVT::i32,
2142 CurDAG->getTargetConstant(
Lo_32(RemainderOffset), SDLoc(),
2146 Offset =
CurDAG->getSignedTargetConstant(SplitImmOffset, SDLoc(),
2157 unsigned NumLiterals =
2158 !
TII->isInlineConstant(APInt(32,
Lo_32(COffsetVal))) +
2159 !
TII->isInlineConstant(APInt(32,
Hi_32(COffsetVal)));
2160 if (Subtarget->getConstantBusLimit(AMDGPU::V_ADD_U32_e64) > NumLiterals)
2169 if (!
LHS->isDivergent()) {
2172 ScaleOffset = SelectScaleOffset(
N,
RHS, Subtarget->hasSignedGVSOffset());
2174 RHS, Subtarget->hasSignedGVSOffset(),
CurDAG)) {
2181 if (!SAddr && !
RHS->isDivergent()) {
2183 ScaleOffset = SelectScaleOffset(
N,
LHS, Subtarget->hasSignedGVSOffset());
2185 LHS, Subtarget->hasSignedGVSOffset(),
CurDAG)) {
2192 Offset =
CurDAG->getSignedTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2197 if (Subtarget->hasScaleOffset() &&
2198 (Addr.
getOpcode() == (Subtarget->hasSignedGVSOffset()
2213 Offset =
CurDAG->getTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2225 CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32, SDLoc(Addr), MVT::i32,
2226 CurDAG->getTargetConstant(0, SDLoc(), MVT::i32));
2228 Offset =
CurDAG->getSignedTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2232bool AMDGPUDAGToDAGISel::SelectGlobalSAddr(
SDNode *
N,
SDValue Addr,
2237 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2245bool AMDGPUDAGToDAGISel::SelectGlobalSAddrCPol(
SDNode *
N,
SDValue Addr,
2250 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2255 N->getConstantOperandVal(
N->getNumOperands() - 1) & ~AMDGPU::CPol::SCAL;
2261bool AMDGPUDAGToDAGISel::SelectGlobalSAddrCPolM0(
SDNode *
N,
SDValue Addr,
2267 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2272 N->getConstantOperandVal(
N->getNumOperands() - 2) & ~AMDGPU::CPol::SCAL;
2278bool AMDGPUDAGToDAGISel::SelectGlobalSAddrGLC(
SDNode *
N,
SDValue Addr,
2283 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset,
Offset, ScaleOffset))
2287 CPol =
CurDAG->getTargetConstant(CPolVal, SDLoc(), MVT::i32);
2291bool AMDGPUDAGToDAGISel::SelectGlobalSAddrNoIOffset(
SDNode *
N,
SDValue Addr,
2297 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset, DummyOffset, ScaleOffset,
2303 N->getConstantOperandVal(
N->getNumOperands() - 1) & ~AMDGPU::CPol::SCAL;
2309bool AMDGPUDAGToDAGISel::SelectGlobalSAddrNoIOffsetM0(
SDNode *
N,
SDValue Addr,
2315 if (!SelectGlobalSAddr(
N, Addr, SAddr, VOffset, DummyOffset, ScaleOffset,
2336 FI->getValueType(0));
2346bool AMDGPUDAGToDAGISel::SelectScratchSAddr(
SDNode *Parent,
SDValue Addr,
2355 int64_t COffsetVal = 0;
2357 if (
CurDAG->isBaseWithConstantOffset(Addr) && isFlatScratchBaseLegal(Addr)) {
2366 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
2369 FlatAddrSpace::FlatScratch)) {
2370 int64_t SplitImmOffset, RemainderOffset;
2371 std::tie(SplitImmOffset, RemainderOffset) =
TII->splitFlatOffset(
2374 COffsetVal = SplitImmOffset;
2378 ? getMaterializedScalarImm32(
Lo_32(RemainderOffset),
DL)
2379 :
CurDAG->getSignedTargetConstant(RemainderOffset,
DL, MVT::i32);
2380 SAddr =
SDValue(
CurDAG->getMachineNode(AMDGPU::S_ADD_I32,
DL, MVT::i32,
2385 Offset =
CurDAG->getSignedTargetConstant(COffsetVal,
DL, MVT::i32);
2391bool AMDGPUDAGToDAGISel::checkFlatScratchSVSSwizzleBug(
2393 if (!Subtarget->hasFlatScratchSVSSwizzleBug())
2399 KnownBits VKnown =
CurDAG->computeKnownBits(VAddr);
2406 return (VMax & 3) + (
SMax & 3) >= 4;
2409bool AMDGPUDAGToDAGISel::SelectScratchSVAddr(
SDNode *
N,
SDValue Addr,
2413 int64_t ImmOffset = 0;
2417 if (isBaseWithConstantOffset64(Addr,
LHS,
RHS)) {
2419 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
2424 ImmOffset = COffsetVal;
2425 }
else if (!
LHS->isDivergent() && COffsetVal > 0) {
2429 int64_t SplitImmOffset, RemainderOffset;
2430 std::tie(SplitImmOffset, RemainderOffset) =
2435 SDNode *VMov =
CurDAG->getMachineNode(
2436 AMDGPU::V_MOV_B32_e32, SL, MVT::i32,
2437 CurDAG->getTargetConstant(RemainderOffset, SDLoc(), MVT::i32));
2440 if (!isFlatScratchBaseLegal(Addr))
2442 if (checkFlatScratchSVSSwizzleBug(VAddr, SAddr, SplitImmOffset))
2444 Offset =
CurDAG->getTargetConstant(SplitImmOffset, SDLoc(), MVT::i32);
2445 CPol =
CurDAG->getTargetConstant(0, SDLoc(), MVT::i32);
2457 if (!
LHS->isDivergent() &&
RHS->isDivergent()) {
2460 }
else if (!
RHS->isDivergent() &&
LHS->isDivergent()) {
2467 if (OrigAddr != Addr) {
2468 if (!isFlatScratchBaseLegalSVImm(OrigAddr))
2471 if (!isFlatScratchBaseLegalSV(OrigAddr))
2475 if (checkFlatScratchSVSSwizzleBug(VAddr, SAddr, ImmOffset))
2478 Offset =
CurDAG->getSignedTargetConstant(ImmOffset, SDLoc(), MVT::i32);
2480 bool ScaleOffset = SelectScaleOffset(
N, VAddr,
true );
2489bool AMDGPUDAGToDAGISel::isSOffsetLegalWithImmOffset(
SDValue *SOffset,
2492 int64_t ImmOffset)
const {
2493 if (!IsBuffer && !Imm32Only && ImmOffset < 0 &&
2495 KnownBits SKnown =
CurDAG->computeKnownBits(*SOffset);
2507 bool IsSigned,
bool IsSMEM)
const {
2508 bool ScaleOffset =
false;
2509 if (!Subtarget->hasScaleOffset() || !
Offset)
2523 (IsSigned &&
Offset.getOpcode() == AMDGPUISD::MUL_I24) ||
2524 Offset.getOpcode() == AMDGPUISD::MUL_U24 ||
2525 (
Offset.isMachineOpcode() &&
2526 Offset.getMachineOpcode() ==
2527 (IsSigned ? AMDGPU::S_MUL_I64_I32_PSEUDO
2528 : AMDGPU::S_MUL_U64_U32_PSEUDO))) {
2530 ScaleOffset =
C->getZExtValue() ==
Size;
2539 if (
Off.getValueType() == MVT::i64) {
2541 if (
Known.countMaxActiveBits() + Bits > 32)
2545 SDNodeFlags
Flags =
Off->getFlags();
2547 if (IsSigned && !
Flags.hasNoSignedWrap() &&
2548 CurDAG->ComputeNumSignBits(Idx) <= Bits)
2550 if (!IsSigned && !
Flags.hasNoUnsignedWrap() &&
2551 CurDAG->computeKnownBits(Idx).countMinLeadingZeros() < Bits)
2562bool AMDGPUDAGToDAGISel::SelectSMRDOffset(
SDNode *
N,
SDValue ByteOffsetNode,
2564 bool Imm32Only,
bool IsBuffer,
2565 bool HasSOffset, int64_t ImmOffset,
2566 bool *ScaleOffset)
const {
2568 "Cannot match both soffset and offset at the same time!");
2573 *ScaleOffset = SelectScaleOffset(
N, ByteOffsetNode,
false ,
2584 *SOffset = ByteOffsetNode;
2585 return isSOffsetLegalWithImmOffset(SOffset, Imm32Only, IsBuffer,
2591 return isSOffsetLegalWithImmOffset(SOffset, Imm32Only, IsBuffer,
2598 SDLoc SL(ByteOffsetNode);
2602 int64_t ByteOffset = IsBuffer ?
C->getZExtValue() :
C->getSExtValue();
2604 *Subtarget, ByteOffset, IsBuffer, HasSOffset);
2605 if (EncodedOffset &&
Offset && !Imm32Only) {
2606 *
Offset =
CurDAG->getSignedTargetConstant(*EncodedOffset, SL, MVT::i32);
2615 if (EncodedOffset &&
Offset && Imm32Only) {
2616 *
Offset =
CurDAG->getTargetConstant(*EncodedOffset, SL, MVT::i32);
2624 SDValue C32Bit =
CurDAG->getTargetConstant(ByteOffset, SL, MVT::i32);
2626 CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL, MVT::i32, C32Bit), 0);
2633SDValue AMDGPUDAGToDAGISel::Expand32BitAddress(
SDValue Addr)
const {
2641 const SIMachineFunctionInfo *
Info =
MF.getInfo<SIMachineFunctionInfo>();
2642 unsigned AddrHiVal =
Info->get32BitAddressHighBits();
2643 SDValue AddrHi =
CurDAG->getTargetConstant(AddrHiVal, SL, MVT::i32);
2646 CurDAG->getTargetConstant(AMDGPU::SReg_64_XEXECRegClassID, SL, MVT::i32),
2648 CurDAG->getTargetConstant(AMDGPU::sub0, SL, MVT::i32),
2649 SDValue(
CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL, MVT::i32, AddrHi),
2651 CurDAG->getTargetConstant(AMDGPU::sub1, SL, MVT::i32),
2654 return SDValue(
CurDAG->getMachineNode(AMDGPU::REG_SEQUENCE, SL, MVT::i64,
2661bool AMDGPUDAGToDAGISel::SelectSMRDBaseOffset(
SDNode *
N,
SDValue Addr,
2664 bool IsBuffer,
bool HasSOffset,
2666 bool *ScaleOffset)
const {
2668 assert(!Imm32Only && !IsBuffer);
2671 if (!SelectSMRDBaseOffset(
N, Addr,
B,
nullptr,
Offset,
false,
false,
true))
2676 ImmOff =
C->getSExtValue();
2678 return SelectSMRDBaseOffset(
N,
B, SBase, SOffset,
nullptr,
false,
false,
2679 true, ImmOff, ScaleOffset);
2699 if (SelectSMRDOffset(
N, N1, SOffset,
Offset, Imm32Only, IsBuffer, HasSOffset,
2700 ImmOffset, ScaleOffset)) {
2704 if (SelectSMRDOffset(
N, N0, SOffset,
Offset, Imm32Only, IsBuffer, HasSOffset,
2705 ImmOffset, ScaleOffset)) {
2714 bool Imm32Only,
bool *ScaleOffset)
const {
2715 if (SelectSMRDBaseOffset(
N, Addr, SBase, SOffset,
Offset, Imm32Only,
2718 SBase = Expand32BitAddress(SBase);
2723 SBase = Expand32BitAddress(Addr);
2724 *
Offset =
CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
2731bool AMDGPUDAGToDAGISel::SelectSMRDImm(
SDValue Addr,
SDValue &SBase,
2733 return SelectSMRD(
nullptr, Addr, SBase,
nullptr,
2737bool AMDGPUDAGToDAGISel::SelectSMRDImm32(
SDValue Addr,
SDValue &SBase,
2740 return SelectSMRD(
nullptr, Addr, SBase,
nullptr,
2747 if (!SelectSMRD(
N, Addr, SBase, &SOffset,
nullptr,
2748 false, &ScaleOffset))
2752 SDLoc(
N), MVT::i32);
2756bool AMDGPUDAGToDAGISel::SelectSMRDSgprImm(
SDNode *
N,
SDValue Addr,
2761 if (!SelectSMRD(
N, Addr, SBase, &SOffset, &
Offset,
false, &ScaleOffset))
2765 SDLoc(
N), MVT::i32);
2770 return SelectSMRDOffset(
nullptr,
N,
nullptr, &
Offset,
2774bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm32(
SDValue N,
2777 return SelectSMRDOffset(
nullptr,
N,
nullptr, &
Offset,
2781bool AMDGPUDAGToDAGISel::SelectSMRDBufferSgprImm(
SDValue N,
SDValue &SOffset,
2785 return N.getValueType() == MVT::i32 &&
2786 SelectSMRDBaseOffset(
nullptr,
N, SOffset,
2791bool AMDGPUDAGToDAGISel::SelectMOVRELOffset(
SDValue Index,
2796 if (
CurDAG->isBaseWithConstantOffset(Index)) {
2805 if (
C1->getSExtValue() <= 0 ||
CurDAG->SignBitIsZero(N0) ||
2821SDNode *AMDGPUDAGToDAGISel::getBFE32(
bool IsSigned,
const SDLoc &
DL,
2825 unsigned Opcode = IsSigned ? AMDGPU::V_BFE_I32_e64 : AMDGPU::V_BFE_U32_e64;
2829 return CurDAG->getMachineNode(Opcode,
DL, MVT::i32, Val,
Off, W);
2831 unsigned Opcode = IsSigned ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32;
2835 uint32_t PackedVal =
Offset | (Width << 16);
2836 SDValue PackedConst =
CurDAG->getTargetConstant(PackedVal,
DL, MVT::i32);
2838 return CurDAG->getMachineNode(Opcode,
DL, MVT::i32, Val, PackedConst);
2841void AMDGPUDAGToDAGISel::SelectS_BFEFromShifts(
SDNode *
N) {
2846 const SDValue &Shl =
N->getOperand(0);
2851 uint32_t BVal =
B->getZExtValue();
2852 uint32_t CVal =
C->getZExtValue();
2854 if (0 < BVal && BVal <= CVal && CVal < 32) {
2864void AMDGPUDAGToDAGISel::SelectS_BFE(
SDNode *
N) {
2865 switch (
N->getOpcode()) {
2867 if (
N->getOperand(0).getOpcode() ==
ISD::SRL) {
2870 const SDValue &Srl =
N->getOperand(0);
2874 if (Shift && Mask) {
2876 uint32_t MaskVal =
Mask->getZExtValue();
2888 if (
N->getOperand(0).getOpcode() ==
ISD::AND) {
2895 if (Shift && Mask) {
2897 uint32_t MaskVal =
Mask->getZExtValue() >> ShiftVal;
2906 }
else if (
N->getOperand(0).getOpcode() ==
ISD::SHL) {
2907 SelectS_BFEFromShifts(
N);
2912 if (
N->getOperand(0).getOpcode() ==
ISD::SHL) {
2913 SelectS_BFEFromShifts(
N);
2928 unsigned Width =
cast<VTSDNode>(
N->getOperand(1))->getVT().getSizeInBits();
2938bool AMDGPUDAGToDAGISel::isCBranchSCC(
const SDNode *
N)
const {
2940 if (!
N->hasOneUse())
2947 if (!
Cond.hasOneUse() ||
2951 MVT VT =
Cond.getOperand(0).getSimpleValueType();
2953 return VT == MVT::i16 || VT == MVT::i32 || VT == MVT::i64;
2958 if (VT == MVT::i64) {
2961 Subtarget->hasScalarCompareEq64();
2964 if ((VT == MVT::f16 || VT == MVT::f32) && Subtarget->hasSALUFloatInsts())
2997void AMDGPUDAGToDAGISel::SelectBRCOND(
SDNode *
N) {
3000 if (
Cond.isUndef()) {
3001 CurDAG->SelectNodeTo(
N, AMDGPU::SI_BR_UNDEF, MVT::Other,
3002 N->getOperand(2),
N->getOperand(0));
3006 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
3008 bool UseSCCBr = isCBranchSCC(
N) && isUniformBr(
N);
3009 bool AndExec = !UseSCCBr;
3010 bool Negate =
false;
3013 Cond->getOperand(0)->getOpcode() == AMDGPUISD::SETCC) {
3015 auto CC =
Cond->getOperandCondCode(2);
3028 bool NegatedBallot =
false;
3031 UseSCCBr = !BallotCond->isDivergent();
3032 Negate = Negate ^ NegatedBallot;
3047 UseSCCBr ? (Negate ? AMDGPU::S_CBRANCH_SCC0 : AMDGPU::S_CBRANCH_SCC1)
3048 : (Negate ? AMDGPU::S_CBRANCH_VCCZ : AMDGPU::S_CBRANCH_VCCNZ);
3049 Register CondReg = UseSCCBr ? AMDGPU::SCC :
TRI->getVCC();
3068 Subtarget->isWave32() ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64, SL,
3070 CurDAG->getRegister(Subtarget->isWave32() ? AMDGPU::EXEC_LO
3078 CurDAG->SelectNodeTo(
N, BrOp, MVT::Other,
3083void AMDGPUDAGToDAGISel::SelectFP_EXTEND(
SDNode *
N) {
3084 if (Subtarget->hasSALUFloatInsts() &&
N->getValueType(0) == MVT::f32 &&
3085 !
N->isDivergent()) {
3087 if (Src.getValueType() == MVT::f16) {
3089 CurDAG->SelectNodeTo(
N, AMDGPU::S_CVT_HI_F32_F16,
N->getVTList(),
3099void AMDGPUDAGToDAGISel::SelectDSAppendConsume(
SDNode *
N,
unsigned IntrID) {
3102 unsigned Opc = IntrID == Intrinsic::amdgcn_ds_append ?
3103 AMDGPU::DS_APPEND : AMDGPU::DS_CONSUME;
3108 MachineMemOperand *MMO =
M->getMemOperand();
3112 if (
CurDAG->isBaseWithConstantOffset(Ptr)) {
3117 if (isDSOffsetLegal(PtrBase, OffsetVal.
getZExtValue())) {
3118 N = glueCopyToM0(
N, PtrBase);
3119 Offset =
CurDAG->getTargetConstant(OffsetVal, SDLoc(), MVT::i32);
3124 N = glueCopyToM0(
N, Ptr);
3125 Offset =
CurDAG->getTargetConstant(0, SDLoc(), MVT::i32);
3130 CurDAG->getTargetConstant(IsGDS, SDLoc(), MVT::i32),
3135 SDNode *Selected =
CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(),
Ops);
3141void AMDGPUDAGToDAGISel::SelectDSBvhStackIntrinsic(
SDNode *
N,
unsigned IntrID) {
3144 case Intrinsic::amdgcn_ds_bvh_stack_rtn:
3145 case Intrinsic::amdgcn_ds_bvh_stack_push4_pop1_rtn:
3146 Opc = AMDGPU::DS_BVH_STACK_RTN_B32;
3148 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop1_rtn:
3149 Opc = AMDGPU::DS_BVH_STACK_PUSH8_POP1_RTN_B32;
3151 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop2_rtn:
3152 Opc = AMDGPU::DS_BVH_STACK_PUSH8_POP2_RTN_B64;
3155 SDValue Ops[] = {
N->getOperand(2),
N->getOperand(3),
N->getOperand(4),
3156 N->getOperand(5),
N->getOperand(0)};
3159 MachineMemOperand *MMO =
M->getMemOperand();
3160 SDNode *Selected =
CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(),
Ops);
3164void AMDGPUDAGToDAGISel::SelectTensorLoadStore(
SDNode *
N,
unsigned IntrID) {
3165 bool IsLoad = IntrID == Intrinsic::amdgcn_tensor_load_to_lds;
3167 IsLoad ? AMDGPU::TENSOR_LOAD_TO_LDS_d4 : AMDGPU::TENSOR_STORE_FROM_LDS_d4;
3179 Opc = IsLoad ? AMDGPU::TENSOR_LOAD_TO_LDS_d2
3180 : AMDGPU::TENSOR_STORE_FROM_LDS_d2;
3192 (void)
CurDAG->SelectNodeTo(
N,
Opc, MVT::Other, TensorOps);
3197 case Intrinsic::amdgcn_ds_gws_init:
3198 return AMDGPU::DS_GWS_INIT;
3199 case Intrinsic::amdgcn_ds_gws_barrier:
3200 return AMDGPU::DS_GWS_BARRIER;
3201 case Intrinsic::amdgcn_ds_gws_sema_v:
3202 return AMDGPU::DS_GWS_SEMA_V;
3203 case Intrinsic::amdgcn_ds_gws_sema_br:
3204 return AMDGPU::DS_GWS_SEMA_BR;
3205 case Intrinsic::amdgcn_ds_gws_sema_p:
3206 return AMDGPU::DS_GWS_SEMA_P;
3207 case Intrinsic::amdgcn_ds_gws_sema_release_all:
3208 return AMDGPU::DS_GWS_SEMA_RELEASE_ALL;
3214void AMDGPUDAGToDAGISel::SelectDS_GWS(
SDNode *
N,
unsigned IntrID) {
3215 if (!Subtarget->hasGWS() ||
3216 (IntrID == Intrinsic::amdgcn_ds_gws_sema_release_all &&
3217 !Subtarget->hasGWSSemaReleaseAll())) {
3224 const bool HasVSrc =
N->getNumOperands() == 4;
3225 assert(HasVSrc ||
N->getNumOperands() == 3);
3228 SDValue BaseOffset =
N->getOperand(HasVSrc ? 3 : 2);
3231 MachineMemOperand *MMO =
M->getMemOperand();
3244 glueCopyToM0(
N,
CurDAG->getTargetConstant(0, SL, MVT::i32));
3245 ImmOffset = ConstOffset->getZExtValue();
3247 if (
CurDAG->isBaseWithConstantOffset(BaseOffset)) {
3256 =
CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL, MVT::i32,
3260 =
CurDAG->getMachineNode(AMDGPU::S_LSHL_B32, SL, MVT::i32,
3262 CurDAG->getTargetConstant(16, SL, MVT::i32));
3263 glueCopyToM0(
N,
SDValue(M0Base, 0));
3267 SDValue OffsetField =
CurDAG->getTargetConstant(ImmOffset, SL, MVT::i32);
3271 const MCInstrDesc &InstrDesc =
TII->get(
Opc);
3272 int Data0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::data0);
3278 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
3281 MVT DataVT =
Data.getValueType().getSimpleVT();
3282 if (
TRI->isTypeLegalForClass(*DataRC, DataVT)) {
3284 Ops.push_back(
N->getOperand(2));
3290 CurDAG->getTargetConstant(AMDGPU::sub0, SL, MVT::i32),
3292 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, SL, MVT::i32),
3294 CurDAG->getTargetConstant(AMDGPU::sub1, SL, MVT::i32)};
3297 SL, MVT::v2i32, RegSeqOps),
3302 Ops.push_back(OffsetField);
3303 Ops.push_back(Chain);
3305 SDNode *Selected =
CurDAG->SelectNodeTo(
N,
Opc,
N->getVTList(),
Ops);
3309void AMDGPUDAGToDAGISel::SelectInterpP1F16(
SDNode *
N) {
3310 if (Subtarget->getLDSBankCount() != 16) {
3340 SDVTList VTs =
CurDAG->getVTList(MVT::f32, MVT::Other);
3343 CurDAG->getMachineNode(AMDGPU::V_INTERP_MOV_F32,
DL, VTs, {
3344 CurDAG->getTargetConstant(2,
DL, MVT::i32),
3350 SDNode *InterpP1LV =
3351 CurDAG->getMachineNode(AMDGPU::V_INTERP_P1LV_F16,
DL, MVT::f32, {
3352 CurDAG->getTargetConstant(0,
DL, MVT::i32),
3356 CurDAG->getTargetConstant(0,
DL, MVT::i32),
3359 CurDAG->getTargetConstant(0,
DL, MVT::i1),
3360 CurDAG->getTargetConstant(0,
DL, MVT::i32),
3367void AMDGPUDAGToDAGISel::SelectINTRINSIC_W_CHAIN(
SDNode *
N) {
3368 unsigned IntrID =
N->getConstantOperandVal(1);
3370 case Intrinsic::amdgcn_ds_append:
3371 case Intrinsic::amdgcn_ds_consume: {
3372 if (
N->getValueType(0) != MVT::i32)
3374 SelectDSAppendConsume(
N, IntrID);
3377 case Intrinsic::amdgcn_ds_bvh_stack_rtn:
3378 case Intrinsic::amdgcn_ds_bvh_stack_push4_pop1_rtn:
3379 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop1_rtn:
3380 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop2_rtn:
3381 SelectDSBvhStackIntrinsic(
N, IntrID);
3383 case Intrinsic::amdgcn_init_whole_wave:
3384 CurDAG->getMachineFunction()
3385 .getInfo<SIMachineFunctionInfo>()
3386 ->setInitWholeWave();
3393void AMDGPUDAGToDAGISel::SelectINTRINSIC_WO_CHAIN(
SDNode *
N) {
3394 unsigned IntrID =
N->getConstantOperandVal(0);
3395 unsigned Opcode = AMDGPU::INSTRUCTION_LIST_END;
3396 SDNode *ConvGlueNode =
N->getGluedNode();
3402 CurDAG->getMachineNode(TargetOpcode::CONVERGENCECTRL_GLUE, {},
3403 MVT::Glue,
SDValue(ConvGlueNode, 0));
3405 ConvGlueNode =
nullptr;
3408 case Intrinsic::amdgcn_wqm:
3409 Opcode = AMDGPU::WQM;
3411 case Intrinsic::amdgcn_softwqm:
3412 Opcode = AMDGPU::SOFT_WQM;
3414 case Intrinsic::amdgcn_wwm:
3415 case Intrinsic::amdgcn_strict_wwm:
3416 Opcode = AMDGPU::STRICT_WWM;
3418 case Intrinsic::amdgcn_strict_wqm:
3419 Opcode = AMDGPU::STRICT_WQM;
3421 case Intrinsic::amdgcn_interp_p1_f16:
3422 SelectInterpP1F16(
N);
3424 case Intrinsic::amdgcn_permlane16_swap:
3425 case Intrinsic::amdgcn_permlane32_swap: {
3426 if ((IntrID == Intrinsic::amdgcn_permlane16_swap &&
3427 !Subtarget->hasPermlane16Swap()) ||
3428 (IntrID == Intrinsic::amdgcn_permlane32_swap &&
3429 !Subtarget->hasPermlane32Swap())) {
3434 Opcode = IntrID == Intrinsic::amdgcn_permlane16_swap
3435 ? AMDGPU::V_PERMLANE16_SWAP_B32_e64
3436 : AMDGPU::V_PERMLANE32_SWAP_B32_e64;
3440 NewOps.push_back(
SDValue(ConvGlueNode, 0));
3442 bool FI =
N->getConstantOperandVal(3);
3443 NewOps[2] =
CurDAG->getTargetConstant(
3446 CurDAG->SelectNodeTo(
N, Opcode,
N->getVTList(), NewOps);
3454 if (Opcode != AMDGPU::INSTRUCTION_LIST_END) {
3456 CurDAG->SelectNodeTo(
N, Opcode,
N->getVTList(), {Src});
3461 NewOps.push_back(
SDValue(ConvGlueNode, 0));
3462 CurDAG->MorphNodeTo(
N,
N->getOpcode(),
N->getVTList(), NewOps);
3466void AMDGPUDAGToDAGISel::SelectINTRINSIC_VOID(
SDNode *
N) {
3467 unsigned IntrID =
N->getConstantOperandVal(1);
3469 case Intrinsic::amdgcn_ds_gws_init:
3470 case Intrinsic::amdgcn_ds_gws_barrier:
3471 case Intrinsic::amdgcn_ds_gws_sema_v:
3472 case Intrinsic::amdgcn_ds_gws_sema_br:
3473 case Intrinsic::amdgcn_ds_gws_sema_p:
3474 case Intrinsic::amdgcn_ds_gws_sema_release_all:
3475 SelectDS_GWS(
N, IntrID);
3477 case Intrinsic::amdgcn_tensor_load_to_lds:
3478 case Intrinsic::amdgcn_tensor_store_from_lds:
3479 SelectTensorLoadStore(
N, IntrID);
3488void AMDGPUDAGToDAGISel::SelectWAVE_ADDRESS(
SDNode *
N) {
3490 CurDAG->getTargetConstant(Subtarget->getWavefrontSizeLog2(), SDLoc(
N), MVT::i32);
3491 CurDAG->SelectNodeTo(
N, AMDGPU::S_LSHR_B32,
N->getVTList(),
3492 {N->getOperand(0), Log2WaveSize});
3495void AMDGPUDAGToDAGISel::SelectSTACKRESTORE(
SDNode *
N) {
3510 Subtarget->getWavefrontSizeLog2(), SL, MVT::i32);
3512 if (
N->isDivergent()) {
3513 SrcVal =
SDValue(
CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL,
3518 CopyVal =
SDValue(
CurDAG->getMachineNode(AMDGPU::S_LSHL_B32, SL, MVT::i32,
3519 {SrcVal, Log2WaveSize}),
3523 SDValue CopyToSP =
CurDAG->getCopyToReg(
N->getOperand(0), SL,
SP, CopyVal);
3527void AMDGPUDAGToDAGISel::SelectWRITE_REGISTER(
SDNode *
N) {
3534 CurDAG->getMachineFunction());
3538 "invalid register \"" + Twine(RegStr->
getString()) +
3539 "\" for llvm.write_register",
3540 Fn,
N->getDebugLoc()));
3552 }
else if (VT == MVT::i32) {
3553 CopyVal =
SDValue(
CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL,
3559 CurDAG->getTargetExtractSubreg(AMDGPU::sub0, SL, MVT::i32, SrcVal);
3561 CurDAG->getTargetExtractSubreg(AMDGPU::sub1, SL, MVT::i32, SrcVal);
3563 CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL, MVT::i32,
Lo),
3566 CurDAG->getMachineNode(AMDGPU::V_READFIRSTLANE_B32, SL, MVT::i32,
Hi),
3568 CopyVal = emitRegSequence(*
CurDAG, AMDGPU::SReg_64RegClassID, VT, {
Lo,
Hi},
3569 {AMDGPU::sub0, AMDGPU::sub1}, SL);
3576bool AMDGPUDAGToDAGISel::SelectVOP3ModsImpl(
SDValue In,
SDValue &Src,
3578 bool IsCanonicalizing,
3579 bool AllowAbs)
const {
3585 Src = Src.getOperand(0);
3586 }
else if (Src.getOpcode() ==
ISD::FSUB && IsCanonicalizing) {
3590 if (
LHS &&
LHS->isZero()) {
3592 Src = Src.getOperand(1);
3596 if (AllowAbs && Src.getOpcode() ==
ISD::FABS) {
3598 Src = Src.getOperand(0);
3611 if (IsCanonicalizing)
3626 EVT VT = Src.getValueType();
3628 (VT != MVT::i32 && VT != MVT::v2i32 && VT != MVT::i64))
3635 auto ReplaceSrc = [&]() ->
SDValue {
3637 return Src.getOperand(0);
3642 Src.getValueType(),
LHS, Index);
3668 if (SelectVOP3ModsImpl(In, Src, Mods,
true,
3670 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3677bool AMDGPUDAGToDAGISel::SelectVOP3ModsNonCanonicalizing(
3680 if (SelectVOP3ModsImpl(In, Src, Mods,
false,
3682 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3689bool AMDGPUDAGToDAGISel::SelectVOP3BMods(
SDValue In,
SDValue &Src,
3692 if (SelectVOP3ModsImpl(In, Src, Mods,
3695 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3702bool AMDGPUDAGToDAGISel::SelectVOP3NoMods(
SDValue In,
SDValue &Src)
const {
3710bool AMDGPUDAGToDAGISel::SelectVOP3NoOpSelMods(
SDValue In,
SDValue &Src)
const {
3715 return SelectVOP3NoMods(In, Src);
3718bool AMDGPUDAGToDAGISel::SelectVINTERPModsImpl(
SDValue In,
SDValue &Src,
3722 if (SelectVOP3ModsImpl(In, Src, Mods,
3727 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3734bool AMDGPUDAGToDAGISel::SelectVINTERPMods(
SDValue In,
SDValue &Src,
3736 return SelectVINTERPModsImpl(In, Src, SrcMods,
false);
3739bool AMDGPUDAGToDAGISel::SelectVINTERPModsHi(
SDValue In,
SDValue &Src,
3741 return SelectVINTERPModsImpl(In, Src, SrcMods,
true);
3744bool AMDGPUDAGToDAGISel::SelectVOP3Mods0(
SDValue In,
SDValue &Src,
3748 Clamp =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3749 Omod =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3751 return SelectVOP3Mods(In, Src, SrcMods);
3754bool AMDGPUDAGToDAGISel::SelectVOP3BMods0(
SDValue In,
SDValue &Src,
3758 Clamp =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3759 Omod =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3761 return SelectVOP3BMods(In, Src, SrcMods);
3764bool AMDGPUDAGToDAGISel::SelectVOP3OMods(
SDValue In,
SDValue &Src,
3769 Clamp =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3770 Omod =
CurDAG->getTargetConstant(0,
DL, MVT::i1);
3775bool AMDGPUDAGToDAGISel::SelectVOP3PModsPkFmaOpSel0(
SDValue In,
SDValue &Src,
3777 return SelectVOP3PMods(In, Src, SrcMods,
false,
3778 Subtarget->hasPkF32InvalidOpSel() &&
3779 In.getValueType() == MVT::v2f32);
3782bool AMDGPUDAGToDAGISel::SelectVOP3PModsPkAddMulOpSel0(
SDValue In,
SDValue &Src,
3784 if (!SelectVOP3PMods(In, Src, SrcMods))
3787 return !Subtarget->hasPkF32InvalidOpSel() ||
3788 In.getValueType() != MVT::v2f32 ||
3793bool AMDGPUDAGToDAGISel::SelectVOP3PMods(
SDValue In,
SDValue &Src,
3795 bool NoOpSel0)
const {
3802 Src = Src.getOperand(0);
3806 bool HasOpSel = Src.getValueSizeInBits() != 128;
3809 (!IsDOT || !Subtarget->hasDOTOpSelHazard()) &&
3810 (!NoOpSel0 || !isLoEltExtractHi(Src))) {
3811 unsigned VecMods = Mods;
3813 SDValue Lo = stripBitcast(Src.getOperand(0));
3814 SDValue Hi = stripBitcast(Src.getOperand(1));
3817 Lo = stripBitcast(
Lo.getOperand(0));
3822 Hi = stripBitcast(
Hi.getOperand(0));
3834 unsigned VecSize = Src.getValueSizeInBits();
3835 Lo = stripExtractLoElt(
Lo);
3836 Hi = stripExtractLoElt(
Hi);
3838 if (
Lo.getValueSizeInBits() > VecSize) {
3839 Lo =
CurDAG->getTargetExtractSubreg(
3840 (VecSize > 32) ? AMDGPU::sub0_sub1 : AMDGPU::sub0, SDLoc(In),
3844 if (
Hi.getValueSizeInBits() > VecSize) {
3845 Hi =
CurDAG->getTargetExtractSubreg(
3846 (VecSize > 32) ? AMDGPU::sub0_sub1 : AMDGPU::sub0, SDLoc(In),
3850 assert(
Lo.getValueSizeInBits() <= VecSize &&
3851 Hi.getValueSizeInBits() <= VecSize);
3853 if (
Lo ==
Hi && !isInlineImmediate(
Lo.getNode())) {
3857 if (VecSize ==
Lo.getValueSizeInBits()) {
3859 }
else if (VecSize == 32) {
3860 Src = createVOP3PSrc32FromLo16(
Lo, Src,
CurDAG, Subtarget);
3862 assert((
Lo.getValueSizeInBits() == 32 && VecSize == 64) ||
3863 (
Lo.getValueSizeInBits() == 64 && VecSize == 128));
3867 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, SL,
3868 Lo.getValueType()), 0);
3869 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
3874 auto RC =
Lo->isDivergent() ?
TRI->getVGPRClassForBitWidth(VecSize)
3875 :
TRI->getSGPRClassForBitWidth(VecSize);
3876 unsigned NumRegs =
Lo.getValueSizeInBits() == 32 ? 1 : 2;
3878 CurDAG->getTargetConstant(RC->getID(), SL, MVT::i32),
Lo,
3879 CurDAG->getTargetConstant(
TRI->getSubRegFromChannel(0, NumRegs), SL,
3884 CurDAG->getTargetConstant(
3885 TRI->getSubRegFromChannel(NumRegs, NumRegs), SL, MVT::i32)};
3887 Src =
SDValue(
CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, SL,
3888 Src.getValueType(),
Ops), 0);
3892 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3898 .bitcastToAPInt().getZExtValue();
3900 Src =
CurDAG->getTargetConstant(
Lit, SDLoc(In), MVT::i64);
3901 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3908 Src.getNumOperands() == 2) {
3913 assert(Src.getValueSizeInBits() != 128 &&
3914 "<2 x 64> VECTOR_SHUFFLE should not be legal.");
3917 ArrayRef<int>
Mask = SVN->getMask();
3919 if (Mask[0] < 2 && Mask[1] < 2 && (!NoOpSel0 || Mask[0] != 1)) {
3921 SDValue ShuffleSrc = SVN->getOperand(0);
3934 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3942 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3946bool AMDGPUDAGToDAGISel::SelectVOP3PModsDOT(
SDValue In,
SDValue &Src,
3948 return SelectVOP3PMods(In, Src, SrcMods,
true);
3951bool AMDGPUDAGToDAGISel::SelectVOP3PNoModsDOT(
SDValue In,
SDValue &Src)
const {
3953 SelectVOP3PMods(In, SrcTmp, SrcModsTmp,
true);
3962bool AMDGPUDAGToDAGISel::SelectVOP3PModsF32(
SDValue In,
SDValue &Src,
3964 SelectVOP3Mods(In, Src, SrcMods);
3967 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3971bool AMDGPUDAGToDAGISel::SelectVOP3PNoModsF32(
SDValue In,
SDValue &Src)
const {
3973 SelectVOP3PModsF32(In, SrcTmp, SrcModsTmp);
3982bool AMDGPUDAGToDAGISel::SelectWMMAOpSelVOP3PMods(
SDValue In,
3985 assert(
C->getAPIntValue().getBitWidth() == 1 &&
"expected i1 value");
3988 unsigned SrcVal =
C->getZExtValue();
3992 Src =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
3999 unsigned DstRegClass;
4001 switch (Elts.
size()) {
4003 DstRegClass = AMDGPU::VReg_256RegClassID;
4007 DstRegClass = AMDGPU::VReg_128RegClassID;
4011 DstRegClass = AMDGPU::VReg_64RegClassID;
4019 Ops.push_back(
CurDAG->getTargetConstant(DstRegClass,
DL, MVT::i32));
4020 for (
unsigned i = 0; i < Elts.
size(); ++i) {
4021 Ops.push_back(Elts[i]);
4022 Ops.push_back(
CurDAG->getTargetConstant(
4025 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
DL, DstTy,
Ops);
4032 assert(
"unhandled Reg sequence size" &&
4033 (Elts.
size() == 8 || Elts.
size() == 16));
4037 for (
unsigned i = 0; i < Elts.
size(); i += 2) {
4038 SDValue LoSrc = stripExtractLoElt(stripBitcast(Elts[i]));
4043 if (Subtarget->useRealTrue16Insts()) {
4048 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
DL, MVT::i16),
4051 emitRegSequence(*
CurDAG, AMDGPU::VGPR_32RegClassID, MVT::i32,
4052 {Elts[i],
Undef}, {AMDGPU::lo16, AMDGPU::hi16},
DL);
4053 Elts[i + 1] = emitRegSequence(*
CurDAG, AMDGPU::VGPR_32RegClassID,
4054 MVT::i32, {Elts[i + 1],
Undef},
4055 {AMDGPU::lo16, AMDGPU::hi16},
DL);
4057 SDValue PackLoLo =
CurDAG->getTargetConstant(0x05040100,
DL, MVT::i32);
4059 CurDAG->getMachineNode(AMDGPU::V_PERM_B32_e64,
DL, MVT::i32,
4060 {Elts[i + 1], Elts[i], PackLoLo});
4064 return buildRegSequence32(PackedElts,
DL);
4070 unsigned ElementSize)
const {
4071 if (ElementSize == 16)
4072 return buildRegSequence16(Elts,
DL);
4073 if (ElementSize == 32)
4074 return buildRegSequence32(Elts,
DL);
4078void AMDGPUDAGToDAGISel::selectWMMAModsNegAbs(
unsigned ModOpcode,
4082 unsigned ElementSize)
const {
4087 for (
auto El : Elts) {
4090 NegAbsElts.
push_back(El->getOperand(0));
4092 if (Elts.size() != NegAbsElts.
size()) {
4094 Src =
SDValue(buildRegSequence(Elts,
DL, ElementSize), 0);
4098 Src =
SDValue(buildRegSequence(NegAbsElts,
DL, ElementSize), 0);
4104 Src =
SDValue(buildRegSequence(Elts,
DL, ElementSize), 0);
4112 std::function<
bool(
SDValue)> ModifierCheck) {
4116 for (
unsigned i = 0; i < F16Pair->getNumOperands(); ++i) {
4117 SDValue ElF16 = stripBitcast(F16Pair->getOperand(i));
4118 if (!ModifierCheck(ElF16))
4125bool AMDGPUDAGToDAGISel::SelectWMMAModsF16Neg(
SDValue In,
SDValue &Src,
4143 Src =
SDValue(buildRegSequence16(EltsF16, SDLoc(In)), 0);
4162 Src =
SDValue(buildRegSequence32(EltsV2F16, SDLoc(In)), 0);
4168 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4172bool AMDGPUDAGToDAGISel::SelectWMMAModsF16NegAbs(
SDValue In,
SDValue &Src,
4183 if (EltsF16.
empty())
4193 selectWMMAModsNegAbs(ModOpcode, Mods, EltsF16, Src, SDLoc(In), 16);
4203 if (EltsV2F16.
empty())
4212 selectWMMAModsNegAbs(ModOpcode, Mods, EltsV2F16, Src, SDLoc(In), 32);
4215 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4219bool AMDGPUDAGToDAGISel::SelectWMMAModsF32NegAbs(
SDValue In,
SDValue &Src,
4229 unsigned ModOpcode =
4240 selectWMMAModsNegAbs(ModOpcode, Mods, EltsF32, Src, SDLoc(In), 32);
4243 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4247bool AMDGPUDAGToDAGISel::SelectWMMAVISrc(
SDValue In,
SDValue &Src)
const {
4249 BitVector UndefElements;
4251 if (isInlineImmediate(
Splat.getNode())) {
4253 unsigned Imm =
C->getAPIntValue().getSExtValue();
4254 Src =
CurDAG->getTargetConstant(
Imm, SDLoc(In), MVT::i32);
4258 unsigned Imm =
C->getValueAPF().bitcastToAPInt().getSExtValue();
4259 Src =
CurDAG->getTargetConstant(
Imm, SDLoc(In), MVT::i32);
4267 SDValue SplatSrc32 = stripBitcast(In);
4269 if (
SDValue Splat32 = SplatSrc32BV->getSplatValue()) {
4270 SDValue SplatSrc16 = stripBitcast(Splat32);
4273 const SIInstrInfo *
TII = Subtarget->getInstrInfo();
4274 std::optional<APInt> RawValue;
4276 RawValue =
C->getValueAPF().bitcastToAPInt();
4278 RawValue =
C->getAPIntValue();
4280 if (RawValue.has_value()) {
4281 EVT VT =
In.getValueType().getScalarType();
4287 if (
TII->isInlineConstant(FloatVal)) {
4288 Src =
CurDAG->getTargetConstant(RawValue.value(), SDLoc(In),
4293 if (
TII->isInlineConstant(RawValue.value())) {
4294 Src =
CurDAG->getTargetConstant(RawValue.value(), SDLoc(In),
4307 if (
CurDAG->isConstantIntBuildVectorOrConstantInt(SplatSrc32)) {
4312 int64_t LoImm = Lo32->getAPIntValue().getSExtValue();
4313 int64_t HiImm = Hi32->getAPIntValue().getSExtValue();
4314 int64_t Imm64I = (HiImm << 32) + LoImm;
4316 if (!isInlineImmediate(APInt(64, Imm64I)))
4319 }
else if (Imm64I != Imm64)
4323 Src =
CurDAG->getTargetConstant(Imm64, SDLoc(In), MVT::i64);
4330bool AMDGPUDAGToDAGISel::SelectSWMMACIndex8(
SDValue In,
SDValue &Src,
4336 const llvm::SDValue &ShiftSrc =
In.getOperand(0);
4345 IndexKey =
CurDAG->getTargetConstant(
Key, SDLoc(In), MVT::i32);
4349bool AMDGPUDAGToDAGISel::SelectSWMMACIndex16(
SDValue In,
SDValue &Src,
4355 const llvm::SDValue &ShiftSrc =
In.getOperand(0);
4364 IndexKey =
CurDAG->getTargetConstant(
Key, SDLoc(In), MVT::i32);
4368bool AMDGPUDAGToDAGISel::SelectSWMMACIndex32(
SDValue In,
SDValue &Src,
4376 const SDValue &ExtendSrc =
In.getOperand(0);
4380 const SDValue &CastSrc =
In.getOperand(0);
4384 if (
Zero &&
Zero->getZExtValue() == 0)
4395 Src = ExtractVecEltSrc;
4399 IndexKey =
CurDAG->getTargetConstant(
Key, SDLoc(In), MVT::i32);
4403bool AMDGPUDAGToDAGISel::SelectVOP3OpSel(
SDValue In,
SDValue &Src,
4407 if (!Subtarget->useRealTrue16Insts() &&
In.getValueSizeInBits() == 16 &&
4410 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4414bool AMDGPUDAGToDAGISel::SelectVOP3OpSelMods(
SDValue In,
SDValue &Src,
4417 if (!SelectVOP3ModsImpl(In, Src, Mods,
true,
4421 if (!Subtarget->useRealTrue16Insts() &&
In.getValueSizeInBits() == 16 &&
4425 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4438 Op =
Op.getOperand(0);
4440 IsExtractHigh =
false;
4443 if (!Low16 || !Low16->isZero())
4445 Op = stripBitcast(
Op.getOperand(1));
4446 if (
Op.getValueType() != MVT::bf16)
4451 if (
Op.getValueType() != MVT::i32)
4456 if (Mask->getZExtValue() == 0xffff0000) {
4457 IsExtractHigh =
true;
4458 return Op.getOperand(0);
4467 return Op.getOperand(0);
4476bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsImpl(
SDValue In,
SDValue &Src,
4480 SelectVOP3ModsImpl(In, Src, Mods);
4482 bool IsExtractHigh =
false;
4484 Src.getOperand(0).getValueType() == VT) {
4485 Src = Src.getOperand(0);
4486 }
else if (VT == MVT::bf16) {
4494 if (Src.getValueType() != VT &&
4495 (VT != MVT::bf16 || Src.getValueType() != MVT::i32))
4498 Src = stripBitcast(Src);
4504 SelectVOP3ModsImpl(Src, Src, ModsTmp);
4519 if (Src.getValueSizeInBits() == 16) {
4528 Src.getOperand(0).getValueType() == MVT::i32) {
4529 Src = Src.getOperand(0);
4533 if (Subtarget->useRealTrue16Insts())
4535 Src = createVOP3PSrc32FromLo16(Src, In,
CurDAG, Subtarget);
4536 }
else if (IsExtractHigh)
4542bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsExt(
SDValue In,
SDValue &Src,
4545 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16))
4547 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4551bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixMods(
SDValue In,
SDValue &Src,
4554 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16);
4555 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4559bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsExtNeg(
SDValue In,
SDValue &Src,
4562 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16))
4569bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsNeg(
SDValue In,
SDValue &Src,
4572 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::f16);
4578bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16ModsExt(
SDValue In,
SDValue &Src,
4581 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16))
4583 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4587bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16Mods(
SDValue In,
SDValue &Src,
4590 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16);
4591 SrcMods =
CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
4595bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16ModsExtNeg(
4598 if (!SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16))
4605bool AMDGPUDAGToDAGISel::SelectVOP3PMadMixBF16ModsNeg(
SDValue In,
SDValue &Src,
4608 SelectVOP3PMadMixModsImpl(In, Src, Mods, MVT::bf16);
4618 unsigned NumOpcodes = 0;
4631 const uint8_t SrcBits[3] = { 0xf0, 0xcc, 0xaa };
4634 if (
C->isAllOnes()) {
4644 for (
unsigned I = 0;
I < Src.size(); ++
I) {
4658 if (Src.size() == 3) {
4664 if (
C->isAllOnes()) {
4666 for (
unsigned I = 0;
I < Src.size(); ++
I) {
4667 if (Src[
I] ==
LHS) {
4679 Bits = SrcBits[Src.size()];
4684 switch (In.getOpcode()) {
4692 if (!getOperandBits(
LHS, LHSBits) ||
4693 !getOperandBits(
RHS, RHSBits)) {
4694 Src = std::move(Backup);
4695 return std::make_pair(0, 0);
4716 uint8_t LHSBitsOrig = LHSBits;
4717 uint8_t RHSBitsOrig = RHSBits;
4721 NumOpcodes += LHSOp.first;
4722 LHSBits = LHSOp.second;
4729 NumOpcodes += RHSOp.first;
4730 RHSBits = RHSOp.second;
4734 auto dependsOnSlot = [](
uint8_t TT,
int Slot) ->
bool {
4735 if (Slot < 0 || Slot > 2)
4737 const uint8_t Masks[3] = {0x0f, 0x33, 0x55};
4738 const int Shifts[3] = {4, 2, 1};
4739 return ((TT ^ (TT >> Shifts[Slot])) & Masks[Slot]) != 0;
4745 const uint8_t SrcBitsConst[3] = {0xf0, 0xcc, 0xaa};
4752 NegatedInner =
Op.getOperand(0);
4753 for (
int I = 0;
I < (int)S.size();
I++) {
4754 if (Bits == SrcBitsConst[
I] && S[
I] ==
Op)
4756 if (IsNegationOp && Bits == (
uint8_t)~SrcBitsConst[
I] &&
4757 S[
I] == NegatedInner)
4768 for (
int I = 0;
I < (int)SrcAfterLHS.
size() &&
I < 3;
I++) {
4769 if (
I < (
int)Src.size() && Src[
I] != SrcAfterLHS[
I] &&
4770 dependsOnSlot(LHSBits,
I)) {
4779 if (!Stale && !RHSOp.first) {
4780 int Slot = findSlot(RHSBitsOrig,
RHS, SrcBeforeRecurse);
4782 (Slot >= (
int)Src.size() || Src[Slot] != SrcBeforeRecurse[Slot]))
4788 if (!Stale && !LHSOp.first) {
4789 int Slot = findSlot(LHSBitsOrig,
LHS, SrcBeforeRecurse);
4791 (Slot >= (
int)Src.size() || Src[Slot] != SrcBeforeRecurse[Slot]))
4796 Src = std::move(SrcBeforeRecurse);
4797 LHSBits = LHSBitsOrig;
4798 RHSBits = RHSBitsOrig;
4804 return std::make_pair(0, 0);
4808 switch (In.getOpcode()) {
4810 TTbl = LHSBits & RHSBits;
4813 TTbl = LHSBits | RHSBits;
4816 TTbl = LHSBits ^ RHSBits;
4822 return std::make_pair(NumOpcodes + 1, TTbl);
4829 unsigned NumOpcodes;
4831 std::tie(NumOpcodes, TTbl) =
BitOp3_Op(In, Src);
4835 if (NumOpcodes < 2 || Src.empty())
4841 if (NumOpcodes < 4 && !In->isDivergent())
4844 if (NumOpcodes == 2 &&
In.getValueType() == MVT::i32) {
4849 (
In.getOperand(0).getOpcode() ==
In.getOpcode() ||
4850 In.getOperand(1).getOpcode() ==
In.getOpcode()))
4864 while (Src.size() < 3)
4865 Src.push_back(Src[0]);
4871 Tbl =
CurDAG->getTargetConstant(TTbl, SDLoc(In), MVT::i32);
4877 return CurDAG->getPOISON(MVT::i32);
4880 return CurDAG->getUNDEF(MVT::i32);
4884 return CurDAG->getConstant(
C->getZExtValue() << 16, SL, MVT::i32);
4889 return CurDAG->getConstant(
4890 C->getValueAPF().bitcastToAPInt().getZExtValue() << 16, SL, MVT::i32);
4900bool AMDGPUDAGToDAGISel::isVGPRImm(
const SDNode *
N)
const {
4901 assert(
CurDAG->getTarget().getTargetTriple().isAMDGCN());
4903 const SIRegisterInfo *SIRI = Subtarget->getRegisterInfo();
4904 const SIInstrInfo *SII = Subtarget->getInstrInfo();
4907 bool AllUsesAcceptSReg =
true;
4909 Limit < 10 && U !=
E; ++U, ++Limit) {
4911 getOperandRegClass(
U->getUser(),
U->getOperandNo());
4919 if (RC != &AMDGPU::VS_32RegClass && RC != &AMDGPU::VS_64RegClass &&
4920 RC != &AMDGPU::VS_64_Align2RegClass) {
4921 AllUsesAcceptSReg =
false;
4922 SDNode *
User =
U->getUser();
4923 if (
User->isMachineOpcode()) {
4924 unsigned Opc =
User->getMachineOpcode();
4925 const MCInstrDesc &
Desc = SII->get(
Opc);
4926 if (
Desc.isCommutable()) {
4927 unsigned OpIdx =
Desc.getNumDefs() +
U->getOperandNo();
4930 unsigned CommutedOpNo = CommuteIdx1 -
Desc.getNumDefs();
4932 getOperandRegClass(
U->getUser(), CommutedOpNo);
4933 if (CommutedRC == &AMDGPU::VS_32RegClass ||
4934 CommutedRC == &AMDGPU::VS_64RegClass ||
4935 CommutedRC == &AMDGPU::VS_64_Align2RegClass)
4936 AllUsesAcceptSReg =
true;
4944 if (!AllUsesAcceptSReg)
4948 return !AllUsesAcceptSReg && (Limit < 10);
4954 bool IsModified =
false;
4960 while (Position !=
CurDAG->allnodes_end()) {
4967 if (ResNode !=
Node) {
4973 CurDAG->RemoveDeadNodes();
4974 }
while (IsModified);
4979 std::vector<SDValue> &OutOps) {
4980 switch (ConstraintID) {
4982 OutOps.push_back(
Op);
4988 MVT VT =
Op.getSimpleValueType();
4991 assert(VRC &&
"Expected valid VGPR class for RF constraint operand");
4995 CurDAG->getMachineNode(AMDGPU::COPY_TO_REGCLASS,
DL, VT, {
Op, RCVal});
4996 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[]
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.
SmallVector< MachineOperand, 4 > Cond
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.
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.