41#include "llvm/IR/IntrinsicsAMDGPU.h"
42#include "llvm/IR/IntrinsicsR600.h"
53#define DEBUG_TYPE "si-lower"
59 cl::desc(
"Do not align and prefetch loops"),
63 "amdgpu-use-divergent-register-indexing",
cl::Hidden,
64 cl::desc(
"Use indirect register addressing for divergent indexes"),
71 cl::desc(
"Generate ISD::PTRADD nodes for 64-bit pointer arithmetic in the "
86 unsigned NumSGPRs = AMDGPU::SGPR_32RegClass.getNumRegs();
87 for (
unsigned Reg = 0;
Reg < NumSGPRs; ++
Reg) {
89 return AMDGPU::SGPR0 +
Reg;
161 if (Subtarget->has16BitInsts()) {
162 if (Subtarget->useRealTrue16Insts()) {
204 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
205 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
206 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32,
207 MVT::i1, MVT::v32i32},
211 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
212 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
213 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32,
214 MVT::i1, MVT::v32i32},
221 ISD::FMINIMUM, ISD::FMAXIMUM, ISD::FSQRT, ISD::FCBRT,
222 ISD::FSIN, ISD::FCOS, ISD::FPOW, ISD::FPOWI,
223 ISD::FLDEXP, ISD::FFREXP, ISD::FLOG, ISD::FLOG2,
224 ISD::FLOG10, ISD::FEXP, ISD::FEXP2, ISD::FEXP10,
225 ISD::FCEIL, ISD::FTRUNC, ISD::FRINT, ISD::FNEARBYINT,
283 {MVT::f32, MVT::i32, MVT::i64, MVT::f64, MVT::i1},
Expand);
290 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
291 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
292 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32},
295 {MVT::v2f32, MVT::v3f32, MVT::v4f32, MVT::v5f32,
296 MVT::v6f32, MVT::v7f32, MVT::v8f32, MVT::v9f32,
297 MVT::v10f32, MVT::v11f32, MVT::v12f32, MVT::v16f32},
301 {MVT::v2i1, MVT::v4i1, MVT::v2i8, MVT::v4i8, MVT::v2i16,
302 MVT::v3i16, MVT::v4i16, MVT::Other},
307 {MVT::i1, MVT::i32, MVT::i64, MVT::f32, MVT::f64},
Expand);
323 {MVT::v8i32, MVT::v8f32, MVT::v9i32, MVT::v9f32, MVT::v10i32,
324 MVT::v10f32, MVT::v11i32, MVT::v11f32, MVT::v12i32, MVT::v12f32,
325 MVT::v16i32, MVT::v16f32, MVT::v2i64, MVT::v2f64, MVT::v4i16,
326 MVT::v4f16, MVT::v4bf16, MVT::v3i64, MVT::v3f64, MVT::v6i32,
327 MVT::v6f32, MVT::v4i64, MVT::v4f64, MVT::v8i64, MVT::v8f64,
328 MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16, MVT::v16f16,
329 MVT::v16bf16, MVT::v16i64, MVT::v16f64, MVT::v32i32, MVT::v32f32,
330 MVT::v32i16, MVT::v32f16, MVT::v32bf16}) {
362 for (
MVT Vec64 : {MVT::v2i64, MVT::v2f64}) {
376 for (
MVT Vec64 : {MVT::v3i64, MVT::v3f64}) {
390 for (
MVT Vec64 : {MVT::v4i64, MVT::v4f64}) {
404 for (
MVT Vec64 : {MVT::v8i64, MVT::v8f64}) {
418 for (
MVT Vec64 : {MVT::v16i64, MVT::v16f64}) {
433 {MVT::v4i32, MVT::v4f32, MVT::v8i32, MVT::v8f32,
434 MVT::v16i32, MVT::v16f32, MVT::v32i32, MVT::v32f32},
437 if (Subtarget->hasPkMovB32()) {
458 {MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::v2i8, MVT::v4i8,
459 MVT::v8i8, MVT::v4i16, MVT::v4f16, MVT::v4bf16},
464 {MVT::v3i32, MVT::v3f32, MVT::v4i32, MVT::v4f32},
Custom);
468 {MVT::v5i32, MVT::v5f32, MVT::v6i32, MVT::v6f32,
469 MVT::v7i32, MVT::v7f32, MVT::v8i32, MVT::v8f32,
470 MVT::v9i32, MVT::v9f32, MVT::v10i32, MVT::v10f32,
471 MVT::v11i32, MVT::v11f32, MVT::v12i32, MVT::v12f32},
495 if (Subtarget->hasSMemRealTime() ||
500 if (Subtarget->has16BitInsts()) {
507 if (Subtarget->hasMadMacF32Insts())
510 if (!Subtarget->hasBFI())
514 if (!Subtarget->hasBCNT(32))
517 if (!Subtarget->hasBCNT(64))
520 if (Subtarget->hasFFBH())
523 if (Subtarget->hasFFBL())
534 if (Subtarget->hasBFE())
538 if (Subtarget->hasIntClamp())
541 if (Subtarget->hasAddNoCarry())
546 {ISD::FMINNUM, ISD::FMAXNUM, ISD::FMINIMUMNUM, ISD::FMAXIMUMNUM},
547 {MVT::f32, MVT::f64},
Custom);
553 {MVT::f32, MVT::f64},
Legal);
555 if (Subtarget->haveRoundOpsF64())
578 if (Subtarget->has16BitInsts()) {
627 ISD::FSIN, ISD::FROUND},
631 if (Subtarget->hasBF16TransInsts())
650 {MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::v4i16, MVT::v4f16,
651 MVT::v4bf16, MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16,
652 MVT::v16f16, MVT::v16bf16, MVT::v32i16, MVT::v32f16}) {
785 {MVT::v2f16, MVT::v2bf16, MVT::v4f16, MVT::v4bf16,
786 MVT::v8f16, MVT::v8bf16, MVT::v16f16, MVT::v16bf16,
787 MVT::v32f16, MVT::v32bf16},
791 {ISD::FMAXNUM, ISD::FMINNUM, ISD::FMINIMUMNUM, ISD::FMAXIMUMNUM},
797 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
801 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
805 {MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16, MVT::v16f16,
806 MVT::v16bf16, MVT::v32i16, MVT::v32f16, MVT::v32bf16}) {
814 if (Subtarget->hasVOP3PInsts()) {
825 {MVT::v2i16, MVT::v2f16, MVT::v2bf16},
Custom);
828 {MVT::v4f16, MVT::v4i16, MVT::v4bf16, MVT::v8f16,
829 MVT::v8i16, MVT::v8bf16, MVT::v16f16, MVT::v16i16,
830 MVT::v16bf16, MVT::v32f16, MVT::v32i16, MVT::v32bf16},
833 for (
MVT VT : {MVT::v4i16, MVT::v8i16, MVT::v16i16, MVT::v32i16})
841 for (
MVT VT : {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16})
847 {ISD::FMAXNUM, ISD::FMINNUM, ISD::FMINIMUMNUM, ISD::FMAXIMUMNUM},
848 {MVT::v2f16, MVT::v4f16},
Custom);
854 if (Subtarget->hasPackedFP32Ops()) {
858 {MVT::v4f32, MVT::v8f32, MVT::v16f32, MVT::v32f32},
865 if (Subtarget->has16BitInsts()) {
878 {MVT::v4i16, MVT::v4f16, MVT::v4bf16, MVT::v2i8, MVT::v4i8,
879 MVT::v8i8, MVT::v8i16, MVT::v8f16, MVT::v8bf16,
880 MVT::v16i16, MVT::v16f16, MVT::v16bf16, MVT::v32i16,
881 MVT::v32f16, MVT::v32bf16},
886 if (Subtarget->hasVectorMulU64())
888 else if (Subtarget->hasScalarSMulU64())
891 if (Subtarget->hasMad64_32())
894 if (Subtarget->hasSafeSmemPrefetch() || Subtarget->hasVmemPrefInsts())
897 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
899 {MVT::f16, MVT::f32, MVT::f64, MVT::v2f16},
Legal);
902 if (Subtarget->hasMinimum3Maximum3F32())
905 if (Subtarget->hasMinimum3Maximum3PKF16()) {
909 if (!Subtarget->hasMinimum3Maximum3F16())
914 if (Subtarget->hasVOP3PInsts()) {
917 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
921 if (Subtarget->hasIntMinMax64())
926 {MVT::Other, MVT::f32, MVT::v4f32, MVT::i16, MVT::f16,
927 MVT::bf16, MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::i128,
932 {MVT::v2f16, MVT::v2i16, MVT::v2bf16, MVT::v3f16,
933 MVT::v3i16, MVT::v4f16, MVT::v4i16, MVT::v4bf16,
934 MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::Other, MVT::f16,
935 MVT::i16, MVT::bf16, MVT::i8, MVT::i128},
939 {MVT::Other, MVT::v2i16, MVT::v2f16, MVT::v2bf16,
940 MVT::v3i16, MVT::v3f16, MVT::v4f16, MVT::v4i16,
941 MVT::v4bf16, MVT::v8i16, MVT::v8f16, MVT::v8bf16,
942 MVT::f16, MVT::i16, MVT::bf16, MVT::i8, MVT::i128},
957 if (Subtarget->hasBF16ConversionInsts()) {
962 if (Subtarget->hasBF16PackedInsts()) {
968 if (Subtarget->hasBF16TransInsts()) {
972 if (Subtarget->hasCvtPkF16F32Inst()) {
974 {MVT::v2f16, MVT::v4f16, MVT::v8f16, MVT::v16f16},
1024 if (Subtarget->has16BitInsts() && !Subtarget->hasMed3_16())
1033 ISD::ATOMIC_CMP_SWAP,
1034 ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS,
1036 ISD::ATOMIC_LOAD_ADD,
1037 ISD::ATOMIC_LOAD_SUB,
1038 ISD::ATOMIC_LOAD_AND,
1039 ISD::ATOMIC_LOAD_OR,
1040 ISD::ATOMIC_LOAD_XOR,
1041 ISD::ATOMIC_LOAD_NAND,
1042 ISD::ATOMIC_LOAD_MIN,
1043 ISD::ATOMIC_LOAD_MAX,
1044 ISD::ATOMIC_LOAD_UMIN,
1045 ISD::ATOMIC_LOAD_UMAX,
1046 ISD::ATOMIC_LOAD_FADD,
1047 ISD::ATOMIC_LOAD_FMIN,
1048 ISD::ATOMIC_LOAD_FMAX,
1049 ISD::ATOMIC_LOAD_UINC_WRAP,
1050 ISD::ATOMIC_LOAD_UDEC_WRAP,
1063 static const MCPhysReg RCRegs[] = {AMDGPU::MODE};
1076 EVT DestVT,
EVT SrcVT)
const {
1078 ((((Opcode ==
ISD::FMAD && Subtarget->hasMadMixInsts()) ||
1079 (Opcode ==
ISD::FMA && Subtarget->hasFmaMixInsts())) &&
1081 (Opcode ==
ISD::FMA && Subtarget->hasFmaMixBF16Insts() &&
1088 LLT DestTy,
LLT SrcTy)
const {
1089 return ((Opcode == TargetOpcode::G_FMAD && Subtarget->hasMadMixInsts()) ||
1090 (Opcode == TargetOpcode::G_FMA && Subtarget->hasFmaMixInsts())) &&
1092 SrcTy.getScalarSizeInBits() == 16 &&
1113 if (Subtarget->has16BitInsts()) {
1116 return (ScalarVT == MVT::bf16 ? MVT::i32 : MVT::v2f16);
1118 return VT.
isInteger() ? MVT::i32 : MVT::f32;
1122 return Subtarget->has16BitInsts() ? MVT::i16 : MVT::i32;
1144 if (
Size == 16 && Subtarget->has16BitInsts())
1145 return (NumElts + 1) / 2;
1151 return NumElts * ((
Size + 31) / 32);
1160 unsigned &NumIntermediates,
MVT &RegisterVT)
const {
1168 if (
Size == 16 && Subtarget->has16BitInsts()) {
1169 if (ScalarVT == MVT::bf16) {
1170 RegisterVT = MVT::i32;
1171 IntermediateVT = MVT::v2bf16;
1173 RegisterVT = VT.
isInteger() ? MVT::v2i16 : MVT::v2f16;
1174 IntermediateVT = RegisterVT;
1176 NumIntermediates = (NumElts + 1) / 2;
1177 return NumIntermediates;
1182 IntermediateVT = RegisterVT;
1183 NumIntermediates = NumElts;
1184 return NumIntermediates;
1189 RegisterVT = MVT::i16;
1190 IntermediateVT = ScalarVT;
1191 NumIntermediates = NumElts;
1192 return NumIntermediates;
1196 RegisterVT = MVT::i32;
1197 IntermediateVT = ScalarVT;
1198 NumIntermediates = NumElts;
1199 return NumIntermediates;
1203 RegisterVT = MVT::i32;
1204 IntermediateVT = RegisterVT;
1205 NumIntermediates = NumElts * ((
Size + 31) / 32);
1206 return NumIntermediates;
1211 Context, CC, VT, IntermediateVT, NumIntermediates, RegisterVT);
1216 unsigned MaxNumLanes) {
1217 assert(MaxNumLanes != 0);
1221 unsigned NumElts = std::min(MaxNumLanes, VT->getNumElements());
1232 unsigned MaxNumLanes) {
1238 assert(ST->getNumContainedTypes() == 2 &&
1239 ST->getContainedType(1)->isIntegerTy(32));
1253 return MVT::amdgpuBufferFatPointer;
1255 DL.getPointerSizeInBits(AS) == 192)
1256 return MVT::amdgpuBufferStridedPointer;
1265 DL.getPointerSizeInBits(AS) == 160) ||
1267 DL.getPointerSizeInBits(AS) == 192))
1274 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
1275 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
1276 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1278 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
1279 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
1280 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1281 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
1282 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
1284 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
1285 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
1286 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1287 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
1288 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
1290 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
1291 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128:
1292 case Intrinsic::amdgcn_global_store_async_from_lds_b128:
1293 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B:
1294 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B:
1333 unsigned IntrID)
const {
1335 if (CI.
hasMetadata(LLVMContext::MD_invariant_load))
1353 if (RsrcIntr->IsImage) {
1368 Info.ptrVal = RsrcArg;
1371 bool IsSPrefetch = IntrID == Intrinsic::amdgcn_s_buffer_prefetch_data;
1380 if (RsrcIntr->IsImage) {
1381 unsigned MaxNumLanes = 4;
1396 std::numeric_limits<unsigned>::max());
1406 if (RsrcIntr->IsImage) {
1427 if ((RsrcIntr->IsImage && BaseOpcode->
NoReturn) || IsSPrefetch) {
1429 Info.memVT = MVT::i32;
1436 case Intrinsic::amdgcn_raw_buffer_load_lds:
1437 case Intrinsic::amdgcn_raw_ptr_buffer_load_lds:
1438 case Intrinsic::amdgcn_struct_buffer_load_lds:
1439 case Intrinsic::amdgcn_struct_ptr_buffer_load_lds: {
1445 case Intrinsic::amdgcn_raw_atomic_buffer_load:
1446 case Intrinsic::amdgcn_raw_ptr_atomic_buffer_load:
1447 case Intrinsic::amdgcn_struct_atomic_buffer_load:
1448 case Intrinsic::amdgcn_struct_ptr_atomic_buffer_load: {
1451 std::numeric_limits<unsigned>::max());
1461 case Intrinsic::amdgcn_ds_ordered_add:
1462 case Intrinsic::amdgcn_ds_ordered_swap: {
1475 case Intrinsic::amdgcn_ds_add_gs_reg_rtn:
1476 case Intrinsic::amdgcn_ds_sub_gs_reg_rtn: {
1479 Info.ptrVal =
nullptr;
1484 case Intrinsic::amdgcn_ds_append:
1485 case Intrinsic::amdgcn_ds_consume: {
1498 case Intrinsic::amdgcn_ds_atomic_async_barrier_arrive_b64:
1499 case Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64: {
1500 Info.opc = (IntrID == Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64)
1505 Info.memVT = MVT::i64;
1511 case Intrinsic::amdgcn_global_atomic_csub: {
1520 case Intrinsic::amdgcn_image_bvh_dual_intersect_ray:
1521 case Intrinsic::amdgcn_image_bvh_intersect_ray:
1522 case Intrinsic::amdgcn_image_bvh8_intersect_ray: {
1525 MVT::getVT(IntrID == Intrinsic::amdgcn_image_bvh_intersect_ray
1528 ->getElementType(0));
1536 case Intrinsic::amdgcn_global_atomic_fmin_num:
1537 case Intrinsic::amdgcn_global_atomic_fmax_num:
1538 case Intrinsic::amdgcn_global_atomic_ordered_add_b64:
1539 case Intrinsic::amdgcn_flat_atomic_fmin_num:
1540 case Intrinsic::amdgcn_flat_atomic_fmax_num:
1541 case Intrinsic::amdgcn_atomic_cond_sub_u32: {
1551 case Intrinsic::amdgcn_flat_load_monitor_b32:
1552 case Intrinsic::amdgcn_flat_load_monitor_b64:
1553 case Intrinsic::amdgcn_flat_load_monitor_b128:
1554 case Intrinsic::amdgcn_global_load_monitor_b32:
1555 case Intrinsic::amdgcn_global_load_monitor_b64:
1556 case Intrinsic::amdgcn_global_load_monitor_b128:
1557 case Intrinsic::amdgcn_cluster_load_b32:
1558 case Intrinsic::amdgcn_cluster_load_b64:
1559 case Intrinsic::amdgcn_cluster_load_b128:
1560 case Intrinsic::amdgcn_ds_load_tr6_b96:
1561 case Intrinsic::amdgcn_ds_load_tr4_b64:
1562 case Intrinsic::amdgcn_ds_load_tr8_b64:
1563 case Intrinsic::amdgcn_ds_load_tr16_b128:
1564 case Intrinsic::amdgcn_global_load_tr6_b96:
1565 case Intrinsic::amdgcn_global_load_tr4_b64:
1566 case Intrinsic::amdgcn_global_load_tr_b64:
1567 case Intrinsic::amdgcn_global_load_tr_b128:
1568 case Intrinsic::amdgcn_ds_read_tr4_b64:
1569 case Intrinsic::amdgcn_ds_read_tr6_b96:
1570 case Intrinsic::amdgcn_ds_read_tr8_b64:
1571 case Intrinsic::amdgcn_ds_read_tr16_b64: {
1579 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
1580 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
1581 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B: {
1589 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
1590 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
1591 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
1599 case Intrinsic::amdgcn_ds_gws_init:
1600 case Intrinsic::amdgcn_ds_gws_barrier:
1601 case Intrinsic::amdgcn_ds_gws_sema_v:
1602 case Intrinsic::amdgcn_ds_gws_sema_br:
1603 case Intrinsic::amdgcn_ds_gws_sema_p:
1604 case Intrinsic::amdgcn_ds_gws_sema_release_all: {
1614 Info.memVT = MVT::i32;
1616 Info.align =
Align(4);
1618 if (IntrID == Intrinsic::amdgcn_ds_gws_barrier)
1624 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
1625 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
1626 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
1627 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
1628 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
1629 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
1630 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
1631 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128: {
1638 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1639 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1640 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1641 case Intrinsic::amdgcn_global_store_async_from_lds_b128: {
1648 case Intrinsic::amdgcn_load_to_lds:
1649 case Intrinsic::amdgcn_global_load_lds: {
1657 case Intrinsic::amdgcn_ds_bvh_stack_rtn:
1658 case Intrinsic::amdgcn_ds_bvh_stack_push4_pop1_rtn:
1659 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop1_rtn:
1660 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop2_rtn: {
1670 Info.memVT = MVT::i32;
1672 Info.align =
Align(4);
1677 case Intrinsic::amdgcn_s_prefetch_data:
1678 case Intrinsic::amdgcn_flat_prefetch:
1679 case Intrinsic::amdgcn_global_prefetch: {
1694 case Intrinsic::amdgcn_addrspacecast_nonnull: {
1697 unsigned SrcAS =
I.getOperand(0)->getType()->getPointerAddressSpace();
1698 unsigned DstAS =
I.getType()->getPointerAddressSpace();
1710 Type *&AccessTy)
const {
1712 switch (
II->getIntrinsicID()) {
1713 case Intrinsic::amdgcn_atomic_cond_sub_u32:
1714 case Intrinsic::amdgcn_cluster_load_b128:
1715 case Intrinsic::amdgcn_cluster_load_b64:
1716 case Intrinsic::amdgcn_cluster_load_b32:
1717 case Intrinsic::amdgcn_ds_append:
1718 case Intrinsic::amdgcn_ds_consume:
1719 case Intrinsic::amdgcn_ds_load_tr8_b64:
1720 case Intrinsic::amdgcn_ds_load_tr16_b128:
1721 case Intrinsic::amdgcn_ds_load_tr4_b64:
1722 case Intrinsic::amdgcn_ds_load_tr6_b96:
1723 case Intrinsic::amdgcn_ds_read_tr4_b64:
1724 case Intrinsic::amdgcn_ds_read_tr6_b96:
1725 case Intrinsic::amdgcn_ds_read_tr8_b64:
1726 case Intrinsic::amdgcn_ds_read_tr16_b64:
1727 case Intrinsic::amdgcn_ds_ordered_add:
1728 case Intrinsic::amdgcn_ds_ordered_swap:
1729 case Intrinsic::amdgcn_ds_atomic_async_barrier_arrive_b64:
1730 case Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64:
1731 case Intrinsic::amdgcn_flat_atomic_fmax_num:
1732 case Intrinsic::amdgcn_flat_atomic_fmin_num:
1733 case Intrinsic::amdgcn_flat_load_monitor_b128:
1734 case Intrinsic::amdgcn_flat_load_monitor_b32:
1735 case Intrinsic::amdgcn_flat_load_monitor_b64:
1736 case Intrinsic::amdgcn_global_atomic_csub:
1737 case Intrinsic::amdgcn_global_atomic_fmax_num:
1738 case Intrinsic::amdgcn_global_atomic_fmin_num:
1739 case Intrinsic::amdgcn_global_atomic_ordered_add_b64:
1740 case Intrinsic::amdgcn_global_load_monitor_b128:
1741 case Intrinsic::amdgcn_global_load_monitor_b32:
1742 case Intrinsic::amdgcn_global_load_monitor_b64:
1743 case Intrinsic::amdgcn_global_load_tr_b64:
1744 case Intrinsic::amdgcn_global_load_tr_b128:
1745 case Intrinsic::amdgcn_global_load_tr4_b64:
1746 case Intrinsic::amdgcn_global_load_tr6_b96:
1747 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1748 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1749 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1750 case Intrinsic::amdgcn_global_store_async_from_lds_b128:
1751 Ptr =
II->getArgOperand(0);
1753 case Intrinsic::amdgcn_load_to_lds:
1754 case Intrinsic::amdgcn_global_load_lds:
1755 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
1756 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
1757 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
1758 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
1759 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
1760 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
1761 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
1762 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128:
1763 Ptr =
II->getArgOperand(1);
1768 AccessTy =
II->getType();
1774 unsigned AddrSpace)
const {
1775 if (!Subtarget->hasFlatInstOffsets()) {
1786 return AM.
Scale == 0 &&
1787 (AM.
BaseOffs == 0 || Subtarget->getInstrInfo()->isLegalFLATOffset(
1788 AM.
BaseOffs, AddrSpace, FlatVariant));
1792 if (Subtarget->hasFlatGlobalInsts())
1795 if (!Subtarget->hasAddr64() || Subtarget->useFlatForGlobal()) {
1808 return isLegalMUBUFAddressingMode(AM);
1811bool SITargetLowering::isLegalMUBUFAddressingMode(
const AddrMode &AM)
const {
1822 if (!
TII->isLegalMUBUFImmOffset(AM.BaseOffs))
1834 if (AM.HasBaseReg) {
1866 return isLegalMUBUFAddressingMode(AM);
1868 if (!Subtarget->hasScalarSubwordLoads()) {
1873 if (Ty->isSized() &&
DL.getTypeStoreSize(Ty) < 4)
1921 return Subtarget->enableFlatScratch()
1923 : isLegalMUBUFAddressingMode(AM);
1970 unsigned Size,
unsigned AddrSpace,
Align Alignment,
1979 if (!Subtarget->hasUnalignedDSAccessEnabled() && Alignment <
Align(4))
1982 Align RequiredAlignment(
1984 if (Subtarget->hasLDSMisalignedBug() &&
Size > 32 &&
1985 Alignment < RequiredAlignment)
2000 if (!Subtarget->hasUsableDSOffset() && Alignment <
Align(8))
2006 RequiredAlignment =
Align(4);
2008 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2024 *IsFast = (Alignment >= RequiredAlignment) ? 64
2025 : (Alignment <
Align(4)) ? 32
2032 if (!Subtarget->hasDS96AndDS128())
2038 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2047 *IsFast = (Alignment >= RequiredAlignment) ? 96
2048 : (Alignment <
Align(4)) ? 32
2055 if (!Subtarget->hasDS96AndDS128() || !Subtarget->useDS128())
2061 RequiredAlignment =
Align(8);
2063 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2072 *IsFast = (Alignment >= RequiredAlignment) ? 128
2073 : (Alignment <
Align(4)) ? 32
2090 *IsFast = (Alignment >= RequiredAlignment) ?
Size : 0;
2092 return Alignment >= RequiredAlignment ||
2093 Subtarget->hasUnalignedDSAccessEnabled();
2101 bool AlignedBy4 = Alignment >=
Align(4);
2102 if (Subtarget->hasUnalignedScratchAccessEnabled()) {
2104 *IsFast = AlignedBy4 ?
Size : 1;
2109 *IsFast = AlignedBy4;
2120 return Alignment >=
Align(4) ||
2121 Subtarget->hasUnalignedBufferAccessEnabled();
2133 if (!Subtarget->hasRelaxedBufferOOBMode() &&
2148 return Size >= 32 && Alignment >=
Align(4);
2153 unsigned *IsFast)
const {
2155 Alignment, Flags, IsFast);
2160 const AttributeList &FuncAttributes)
const {
2166 if (
Op.size() >= 16 &&
2170 if (
Op.size() >= 8 &&
Op.isDstAligned(
Align(4)))
2188 unsigned DestAS)
const {
2191 Subtarget->hasGloballyAddressableScratch()) {
2221 unsigned Index)
const {
2237 if (Subtarget->has16BitInsts() && VT == MVT::i16) {
2264 auto [InputPtrReg, RC, ArgTy] =
2274 Chain, SL,
MRI.getLiveInVirtReg(InputPtrReg->getRegister()), PtrVT);
2280 const SDLoc &SL)
const {
2287 const SDLoc &SL)
const {
2290 std::optional<uint32_t> KnownSize =
2292 if (KnownSize.has_value())
2318 Val = getFPExtOrFPRound(DAG, Val, SL, VT);
2327SDValue SITargetLowering::lowerKernargMemParameter(
2339 int64_t OffsetDiff =
Offset - AlignDownOffset;
2345 SDValue Ptr = lowerKernArgParameterPtr(DAG, SL, Chain, AlignDownOffset);
2354 ArgVal = DAG.
getNode(ISD::BITCAST, SL, MemVT, ArgVal);
2355 ArgVal = convertArgType(DAG, VT, MemVT, SL, ArgVal,
Signed, Arg);
2365 SDValue Val = convertArgType(DAG, VT, MemVT, SL, Load,
Signed, Arg);
2374 const SDLoc &SL)
const {
2384 return DAG.
getNode(ISD::BITCAST, SL, ValVT, Val);
2443 ExtType, SL, VA.
getLocVT(), Chain, FIN,
2446 SDValue ConvertedVal = convertABITypeToValueType(DAG, ArgValue, VA, SL);
2447 if (ConvertedVal == ArgValue)
2448 return ConvertedVal;
2453SDValue SITargetLowering::lowerWorkGroupId(
2458 if (!Subtarget->hasClusters())
2459 return getPreloadedValue(DAG, MFI, VT, WorkGroupIdPV);
2467 SDValue ClusterIdXYZ = getPreloadedValue(DAG, MFI, VT, WorkGroupIdPV);
2468 SDLoc SL(ClusterIdXYZ);
2469 SDValue ClusterMaxIdXYZ = getPreloadedValue(DAG, MFI, VT, ClusterMaxIdPV);
2472 SDValue ClusterWorkGroupIdXYZ =
2473 getPreloadedValue(DAG, MFI, VT, ClusterWorkGroupIdPV);
2483 return ClusterIdXYZ;
2485 using namespace AMDGPU::Hwreg;
2489 DAG.
getMachineNode(AMDGPU::S_GETREG_B32_const, SL, VT, ClusterIdField);
2500SDValue SITargetLowering::getPreloadedValue(
2503 const ArgDescriptor *
Reg =
nullptr;
2504 const TargetRegisterClass *RC;
2508 const ArgDescriptor WorkGroupIDX =
2516 const ArgDescriptor WorkGroupIDZ =
2518 const ArgDescriptor ClusterWorkGroupIDX =
2520 const ArgDescriptor ClusterWorkGroupIDY =
2522 const ArgDescriptor ClusterWorkGroupIDZ =
2524 const ArgDescriptor ClusterWorkGroupMaxIDX =
2526 const ArgDescriptor ClusterWorkGroupMaxIDY =
2528 const ArgDescriptor ClusterWorkGroupMaxIDZ =
2530 const ArgDescriptor ClusterWorkGroupMaxFlatID =
2533 auto LoadConstant = [&](
unsigned N) {
2537 if (Subtarget->hasArchitectedSGPRs() &&
2544 Reg = &WorkGroupIDX;
2545 RC = &AMDGPU::SReg_32RegClass;
2549 Reg = &WorkGroupIDY;
2550 RC = &AMDGPU::SReg_32RegClass;
2554 Reg = &WorkGroupIDZ;
2555 RC = &AMDGPU::SReg_32RegClass;
2559 if (HasFixedDims && ClusterDims.
getDims()[0] == 1)
2560 return LoadConstant(0);
2561 Reg = &ClusterWorkGroupIDX;
2562 RC = &AMDGPU::SReg_32RegClass;
2566 if (HasFixedDims && ClusterDims.
getDims()[1] == 1)
2567 return LoadConstant(0);
2568 Reg = &ClusterWorkGroupIDY;
2569 RC = &AMDGPU::SReg_32RegClass;
2573 if (HasFixedDims && ClusterDims.
getDims()[2] == 1)
2574 return LoadConstant(0);
2575 Reg = &ClusterWorkGroupIDZ;
2576 RC = &AMDGPU::SReg_32RegClass;
2581 return LoadConstant(ClusterDims.
getDims()[0] - 1);
2582 Reg = &ClusterWorkGroupMaxIDX;
2583 RC = &AMDGPU::SReg_32RegClass;
2588 return LoadConstant(ClusterDims.
getDims()[1] - 1);
2589 Reg = &ClusterWorkGroupMaxIDY;
2590 RC = &AMDGPU::SReg_32RegClass;
2595 return LoadConstant(ClusterDims.
getDims()[2] - 1);
2596 Reg = &ClusterWorkGroupMaxIDZ;
2597 RC = &AMDGPU::SReg_32RegClass;
2601 Reg = &ClusterWorkGroupMaxFlatID;
2602 RC = &AMDGPU::SReg_32RegClass;
2633 for (
unsigned I = 0,
E = Ins.size(), PSInputNum = 0;
I !=
E; ++
I) {
2637 "vector type argument should have been split");
2642 bool SkipArg = !Arg->
Used && !
Info->isPSInputAllocated(PSInputNum);
2650 "unexpected vector split in ps argument type");
2664 Info->markPSInputAllocated(PSInputNum);
2666 Info->markPSInputEnabled(PSInputNum);
2682 if (Info.hasWorkItemIDX()) {
2688 (Subtarget->hasPackedTID() && Info.hasWorkItemIDY()) ? 0x3ff : ~0u;
2692 if (Info.hasWorkItemIDY()) {
2693 assert(Info.hasWorkItemIDX());
2694 if (Subtarget->hasPackedTID()) {
2695 Info.setWorkItemIDY(
2698 unsigned Reg = AMDGPU::VGPR1;
2706 if (Info.hasWorkItemIDZ()) {
2707 assert(Info.hasWorkItemIDX() && Info.hasWorkItemIDY());
2708 if (Subtarget->hasPackedTID()) {
2709 Info.setWorkItemIDZ(
2712 unsigned Reg = AMDGPU::VGPR2;
2732 if (RegIdx == ArgVGPRs.
size()) {
2739 unsigned Reg = ArgVGPRs[RegIdx];
2751 unsigned NumArgRegs) {
2754 if (RegIdx == ArgSGPRs.
size())
2757 unsigned Reg = ArgSGPRs[RegIdx];
2799 const unsigned Mask = 0x3ff;
2802 if (Info.hasWorkItemIDX()) {
2804 Info.setWorkItemIDX(Arg);
2807 if (Info.hasWorkItemIDY()) {
2809 Info.setWorkItemIDY(Arg);
2812 if (Info.hasWorkItemIDZ())
2824 const unsigned Mask = 0x3ff;
2833 auto &
ArgInfo = Info.getArgInfo();
2845 if (Info.hasImplicitArgPtr())
2853 if (Info.hasWorkGroupIDX())
2856 if (Info.hasWorkGroupIDY())
2859 if (Info.hasWorkGroupIDZ())
2862 if (Info.hasLDSKernelId())
2873 Register ImplicitBufferPtrReg = Info.addImplicitBufferPtr(
TRI);
2874 MF.
addLiveIn(ImplicitBufferPtrReg, &AMDGPU::SGPR_64RegClass);
2880 Register PrivateSegmentBufferReg = Info.addPrivateSegmentBuffer(
TRI);
2881 MF.
addLiveIn(PrivateSegmentBufferReg, &AMDGPU::SGPR_128RegClass);
2886 Register DispatchPtrReg = Info.addDispatchPtr(
TRI);
2887 MF.
addLiveIn(DispatchPtrReg, &AMDGPU::SGPR_64RegClass);
2893 MF.
addLiveIn(QueuePtrReg, &AMDGPU::SGPR_64RegClass);
2899 Register InputPtrReg = Info.addKernargSegmentPtr(
TRI);
2908 MF.
addLiveIn(DispatchIDReg, &AMDGPU::SGPR_64RegClass);
2913 Register FlatScratchInitReg = Info.addFlatScratchInit(
TRI);
2914 MF.
addLiveIn(FlatScratchInitReg, &AMDGPU::SGPR_64RegClass);
2919 Register PrivateSegmentSizeReg = Info.addPrivateSegmentSize(
TRI);
2920 MF.
addLiveIn(PrivateSegmentSizeReg, &AMDGPU::SGPR_32RegClass);
2935 unsigned LastExplicitArgOffset = Subtarget->getExplicitKernelArgOffset();
2937 bool InPreloadSequence =
true;
2939 bool AlignedForImplictArgs =
false;
2940 unsigned ImplicitArgOffset = 0;
2941 for (
auto &Arg :
F.args()) {
2942 if (!InPreloadSequence || !Arg.hasInRegAttr())
2945 unsigned ArgIdx = Arg.getArgNo();
2948 if (InIdx < Ins.size() &&
2949 (!Ins[InIdx].isOrigArg() || Ins[InIdx].getOrigArgIndex() != ArgIdx))
2952 for (; InIdx < Ins.size() && Ins[InIdx].isOrigArg() &&
2953 Ins[InIdx].getOrigArgIndex() == ArgIdx;
2955 assert(ArgLocs[ArgIdx].isMemLoc());
2956 auto &ArgLoc = ArgLocs[InIdx];
2958 unsigned ArgOffset = ArgLoc.getLocMemOffset();
2960 unsigned NumAllocSGPRs =
2961 alignTo(ArgLoc.getLocVT().getFixedSizeInBits(), 32) / 32;
2964 if (Arg.hasAttribute(
"amdgpu-hidden-argument")) {
2965 if (!AlignedForImplictArgs) {
2967 alignTo(LastExplicitArgOffset,
2968 Subtarget->getAlignmentForImplicitArgPtr()) -
2969 LastExplicitArgOffset;
2970 AlignedForImplictArgs =
true;
2972 ArgOffset += ImplicitArgOffset;
2976 if (ArgLoc.getLocVT().getStoreSize() < 4 && Alignment < 4) {
2977 assert(InIdx >= 1 &&
"No previous SGPR");
2978 Info.getArgInfo().PreloadKernArgs[InIdx].Regs.push_back(
2979 Info.getArgInfo().PreloadKernArgs[InIdx - 1].Regs[0]);
2983 unsigned Padding = ArgOffset - LastExplicitArgOffset;
2984 unsigned PaddingSGPRs =
alignTo(Padding, 4) / 4;
2987 InPreloadSequence =
false;
2993 TRI.getSGPRClassForBitWidth(NumAllocSGPRs * 32);
2995 Info.addPreloadedKernArg(
TRI, RC, NumAllocSGPRs, InIdx, PaddingSGPRs);
2997 if (PreloadRegs->
size() > 1)
2998 RC = &AMDGPU::SGPR_32RegClass;
2999 for (
auto &Reg : *PreloadRegs) {
3005 LastExplicitArgOffset = NumAllocSGPRs * 4 + ArgOffset;
3014 if (Info.hasLDSKernelId()) {
3015 Register Reg = Info.addLDSKernelId();
3016 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3025 bool IsShader)
const {
3026 bool HasArchitectedSGPRs = Subtarget->hasArchitectedSGPRs();
3027 if (Subtarget->hasUserSGPRInit16Bug() && !IsShader) {
3033 assert(!HasArchitectedSGPRs &&
"Unhandled feature for the subtarget");
3035 unsigned CurrentUserSGPRs = Info.getNumUserSGPRs();
3039 unsigned NumRequiredSystemSGPRs =
3040 Info.hasWorkGroupIDX() + Info.hasWorkGroupIDY() +
3041 Info.hasWorkGroupIDZ() + Info.hasWorkGroupInfo();
3042 for (
unsigned i = NumRequiredSystemSGPRs + CurrentUserSGPRs; i < 16; ++i) {
3043 Register Reg = Info.addReservedUserSGPR();
3044 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3049 if (!HasArchitectedSGPRs) {
3050 if (Info.hasWorkGroupIDX()) {
3051 Register Reg = Info.addWorkGroupIDX();
3052 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3056 if (Info.hasWorkGroupIDY()) {
3057 Register Reg = Info.addWorkGroupIDY();
3058 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3062 if (Info.hasWorkGroupIDZ()) {
3063 Register Reg = Info.addWorkGroupIDZ();
3064 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3069 if (Info.hasWorkGroupInfo()) {
3070 Register Reg = Info.addWorkGroupInfo();
3071 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3075 if (Info.hasPrivateSegmentWaveByteOffset()) {
3077 unsigned PrivateSegmentWaveByteOffsetReg;
3080 PrivateSegmentWaveByteOffsetReg =
3081 Info.getPrivateSegmentWaveByteOffsetSystemSGPR();
3085 if (PrivateSegmentWaveByteOffsetReg == AMDGPU::NoRegister) {
3087 Info.setPrivateSegmentWaveByteOffset(PrivateSegmentWaveByteOffsetReg);
3090 PrivateSegmentWaveByteOffsetReg = Info.addPrivateSegmentWaveByteOffset();
3092 MF.
addLiveIn(PrivateSegmentWaveByteOffsetReg, &AMDGPU::SGPR_32RegClass);
3093 CCInfo.
AllocateReg(PrivateSegmentWaveByteOffsetReg);
3096 assert(!Subtarget->hasUserSGPRInit16Bug() || IsShader ||
3097 Info.getNumPreloadedSGPRs() >= 16);
3112 if (HasStackObjects)
3113 Info.setHasNonSpillStackObjects(
true);
3118 HasStackObjects =
true;
3122 bool RequiresStackAccess = HasStackObjects || MFI.
hasCalls();
3124 if (!ST.enableFlatScratch()) {
3125 if (RequiresStackAccess && ST.isAmdHsaOrMesa(MF.
getFunction())) {
3132 Info.setScratchRSrcReg(PrivateSegmentBufferReg);
3134 unsigned ReservedBufferReg =
TRI.reservedPrivateSegmentBufferReg(MF);
3144 Info.setScratchRSrcReg(ReservedBufferReg);
3163 if (!
MRI.isLiveIn(AMDGPU::SGPR32)) {
3164 Info.setStackPtrOffsetReg(AMDGPU::SGPR32);
3171 for (
unsigned Reg : AMDGPU::SGPR_32RegClass) {
3172 if (!
MRI.isLiveIn(
Reg)) {
3173 Info.setStackPtrOffsetReg(
Reg);
3178 if (
Info.getStackPtrOffsetReg() == AMDGPU::SP_REG)
3185 if (ST.getFrameLowering()->hasFP(MF)) {
3186 Info.setFrameOffsetReg(AMDGPU::SGPR33);
3202 const MCPhysReg *IStart =
TRI->getCalleeSavedRegsViaCopy(Entry->getParent());
3211 if (AMDGPU::SReg_64RegClass.
contains(*
I))
3212 RC = &AMDGPU::SGPR_64RegClass;
3213 else if (AMDGPU::SReg_32RegClass.
contains(*
I))
3214 RC = &AMDGPU::SGPR_32RegClass;
3220 Entry->addLiveIn(*
I);
3225 for (
auto *Exit : Exits)
3227 TII->get(TargetOpcode::COPY), *
I)
3242 bool IsError =
false;
3246 Fn,
"unsupported non-compute shaders with HSA",
DL.getDebugLoc()));
3264 !Info->hasLDSKernelId() && !Info->hasWorkItemIDX() &&
3265 !Info->hasWorkItemIDY() && !Info->hasWorkItemIDZ());
3267 if (!Subtarget->enableFlatScratch())
3272 !Subtarget->hasArchitectedSGPRs())
3273 assert(!Info->hasWorkGroupIDX() && !Info->hasWorkGroupIDY() &&
3274 !Info->hasWorkGroupIDZ());
3277 bool IsWholeWaveFunc = Info->isWholeWaveFunction();
3295 if ((Info->getPSInputAddr() & 0x7F) == 0 ||
3296 ((Info->getPSInputAddr() & 0xF) == 0 && Info->isPSInputAllocated(11))) {
3299 Info->markPSInputAllocated(0);
3300 Info->markPSInputEnabled(0);
3302 if (Subtarget->isAmdPalOS()) {
3311 unsigned PsInputBits = Info->getPSInputAddr() & Info->getPSInputEnable();
3312 if ((PsInputBits & 0x7F) == 0 ||
3313 ((PsInputBits & 0xF) == 0 && (PsInputBits >> 11 & 1)))
3316 }
else if (IsKernel) {
3317 assert(Info->hasWorkGroupIDX() && Info->hasWorkItemIDX());
3319 Splits.
append(IsWholeWaveFunc ? std::next(Ins.begin()) : Ins.begin(),
3329 if (IsKernel && Subtarget->hasKernargPreload())
3333 }
else if (!IsGraphics) {
3338 if (!Subtarget->enableFlatScratch())
3350 Info->setNumWaveDispatchSGPRs(
3352 Info->setNumWaveDispatchVGPRs(
3354 }
else if (Info->getNumKernargPreloadedSGPRs()) {
3355 Info->setNumWaveDispatchSGPRs(Info->getNumUserSGPRs());
3360 if (IsWholeWaveFunc) {
3362 {MVT::i1, MVT::Other}, Chain);
3374 for (
unsigned i = IsWholeWaveFunc ? 1 : 0, e = Ins.size(), ArgIdx = 0; i != e;
3385 if (IsEntryFunc && VA.
isMemLoc()) {
3408 if (Arg.
isOrigArg() && Info->getArgInfo().PreloadKernArgs.count(i)) {
3412 int64_t OffsetDiff =
Offset - AlignDownOffset;
3419 Info->getArgInfo().PreloadKernArgs.find(i)->getSecond().Regs[0];
3429 ArgVal = DAG.
getNode(ISD::BITCAST,
DL, MemVT, ArgVal);
3430 NewArg = convertArgType(DAG, VT, MemVT,
DL, ArgVal,
3431 Ins[i].Flags.isSExt(), &Ins[i]);
3439 Info->getArgInfo().PreloadKernArgs.find(i)->getSecond().Regs;
3442 if (PreloadRegs.
size() == 1) {
3443 Register VReg =
MRI.getLiveInVirtReg(PreloadRegs[0]);
3448 TRI->getRegSizeInBits(*RC)));
3456 for (
auto Reg : PreloadRegs) {
3463 PreloadRegs.size()),
3480 NewArg = convertArgType(DAG, VT, MemVT,
DL, NewArg,
3481 Ins[i].Flags.isSExt(), &Ins[i]);
3493 "hidden argument in kernel signature was not preloaded",
3499 lowerKernargMemParameter(DAG, VT, MemVT,
DL, Chain,
Offset,
3500 Alignment, Ins[i].Flags.isSExt(), &Ins[i]);
3520 if (!IsEntryFunc && VA.
isMemLoc()) {
3521 SDValue Val = lowerStackParameter(DAG, VA,
DL, Chain, Arg);
3532 if (AMDGPU::VGPR_32RegClass.
contains(Reg))
3533 RC = &AMDGPU::VGPR_32RegClass;
3534 else if (AMDGPU::SGPR_32RegClass.
contains(Reg))
3535 RC = &AMDGPU::SGPR_32RegClass;
3555 Val = convertABITypeToValueType(DAG, Val, VA,
DL);
3571 Info->setBytesInStackArgArea(StackArgSize);
3573 return Chains.
empty() ? Chain
3582 const Type *RetTy)
const {
3590 CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
3595 unsigned MaxNumVGPRs = Subtarget->getMaxNumVGPRs(MF);
3596 unsigned TotalNumVGPRs = Subtarget->getAddressableNumArchVGPRs();
3597 for (
unsigned i = MaxNumVGPRs; i < TotalNumVGPRs; ++i)
3598 if (CCInfo.
isAllocated(AMDGPU::VGPR_32RegClass.getRegister(i)))
3621 Info->setIfReturnsVoid(Outs.
empty());
3622 bool IsWaveEnd = Info->returnsVoid() && IsShader;
3641 for (
unsigned I = 0, RealRVLocIdx = 0, E = RVLocs.
size();
I != E;
3642 ++
I, ++RealRVLocIdx) {
3646 SDValue Arg = OutVals[RealRVLocIdx];
3669 ReadFirstLane, Arg);
3676 if (!Info->isEntryFunction()) {
3682 if (AMDGPU::SReg_64RegClass.
contains(*
I))
3684 else if (AMDGPU::SReg_32RegClass.
contains(*
I))
3785 auto &ArgUsageInfo =
3787 CalleeArgInfo = &ArgUsageInfo.lookupFuncArgInfo(*CalleeFunc);
3815 const auto [OutgoingArg, ArgRC, ArgTy] =
3820 const auto [IncomingArg, IncomingArgRC, Ty] =
3822 assert(IncomingArgRC == ArgRC);
3825 EVT ArgVT =
TRI->getSpillSize(*ArgRC) == 8 ? MVT::i64 : MVT::i32;
3833 InputReg = getImplicitArgPtr(DAG,
DL);
3835 std::optional<uint32_t> Id =
3837 if (Id.has_value()) {
3848 if (OutgoingArg->isRegister()) {
3849 RegsToPass.emplace_back(OutgoingArg->getRegister(), InputReg);
3850 if (!CCInfo.
AllocateReg(OutgoingArg->getRegister()))
3853 unsigned SpecialArgOffset =
3864 auto [OutgoingArg, ArgRC, Ty] =
3867 std::tie(OutgoingArg, ArgRC, Ty) =
3870 std::tie(OutgoingArg, ArgRC, Ty) =
3885 const bool NeedWorkItemIDX = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-x");
3886 const bool NeedWorkItemIDY = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-y");
3887 const bool NeedWorkItemIDZ = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-z");
3892 if (Subtarget->getMaxWorkitemID(
F, 0) != 0) {
3900 NeedWorkItemIDY && Subtarget->getMaxWorkitemID(
F, 1) != 0) {
3910 NeedWorkItemIDZ && Subtarget->getMaxWorkitemID(
F, 2) != 0) {
3919 if (!InputReg && (NeedWorkItemIDX || NeedWorkItemIDY || NeedWorkItemIDZ)) {
3920 if (!IncomingArgX && !IncomingArgY && !IncomingArgZ) {
3931 : IncomingArgY ? *IncomingArgY
3938 if (OutgoingArg->isRegister()) {
3940 RegsToPass.emplace_back(OutgoingArg->getRegister(), InputReg);
3966 if (Callee->isDivergent())
3973 const uint32_t *CallerPreserved =
TRI->getCallPreservedMask(MF, CallerCC);
3977 if (!CallerPreserved)
3980 bool CCMatch = CallerCC == CalleeCC;
3993 if (Arg.hasByValAttr())
4007 const uint32_t *CalleePreserved =
TRI->getCallPreservedMask(MF, CalleeCC);
4008 if (!
TRI->regmaskSubsetEqual(CallerPreserved, CalleePreserved))
4017 CCState CCInfo(CalleeCC, IsVarArg, MF, ArgLocs, Ctx);
4030 for (
const auto &[CCVA, ArgVal] :
zip_equal(ArgLocs, OutVals)) {
4032 if (!CCVA.isRegLoc())
4037 if (ArgVal->
isDivergent() &&
TRI->isSGPRPhysReg(CCVA.getLocReg())) {
4039 dbgs() <<
"Cannot tail call due to divergent outgoing argument in "
4063enum ChainCallArgIdx {
4085 bool UsesDynamicVGPRs =
false;
4086 if (IsChainCallConv) {
4091 auto RequestedExecIt =
4093 return Arg.OrigArgIndex == 2;
4095 assert(RequestedExecIt != CLI.
Outs.end() &&
"No node for EXEC");
4097 size_t SpecialArgsBeginIdx = RequestedExecIt - CLI.
Outs.begin();
4100 CLI.
Outs.erase(RequestedExecIt, CLI.
Outs.end());
4103 "Haven't popped all the special args");
4106 CLI.
Args[ChainCallArgIdx::Exec];
4107 if (!RequestedExecArg.
Ty->
isIntegerTy(Subtarget->getWavefrontSize()))
4115 ArgNode->getAPIntValue(),
DL, ArgNode->getValueType(0)));
4117 ChainCallSpecialArgs.
push_back(Arg.Node);
4120 PushNodeOrTargetConstant(RequestedExecArg);
4126 if (FlagsValue.
isZero()) {
4127 if (CLI.
Args.size() > ChainCallArgIdx::Flags + 1)
4129 "no additional args allowed if flags == 0");
4131 if (CLI.
Args.size() != ChainCallArgIdx::FallbackCallee + 1) {
4135 if (!Subtarget->isWave32()) {
4137 CLI, InVals,
"dynamic VGPR mode is only supported for wave32");
4140 UsesDynamicVGPRs =
true;
4141 std::for_each(CLI.
Args.begin() + ChainCallArgIdx::NumVGPRs,
4142 CLI.
Args.end(), PushNodeOrTargetConstant);
4151 bool IsSibCall =
false;
4165 "unsupported call to variadic function ");
4173 "unsupported required tail call to function ");
4178 Outs, OutVals, Ins, DAG);
4182 "site marked musttail or on llvm.amdgcn.cs.chain");
4189 if (!TailCallOpt && IsTailCall)
4229 auto *
TRI = Subtarget->getRegisterInfo();
4236 if (!IsSibCall || IsChainCallConv) {
4237 if (!Subtarget->enableFlatScratch()) {
4243 RegsToPass.emplace_back(IsChainCallConv
4244 ? AMDGPU::SGPR48_SGPR49_SGPR50_SGPR51
4245 : AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3,
4252 const unsigned NumSpecialInputs = RegsToPass.size();
4254 MVT PtrVT = MVT::i32;
4257 for (
unsigned i = 0, e = ArgLocs.
size(); i != e; ++i) {
4285 RegsToPass.push_back(std::pair(VA.
getLocReg(), Arg));
4293 int32_t
Offset = LocMemOffset;
4300 unsigned OpSize = Flags.isByVal() ? Flags.getByValSize()
4306 ? Flags.getNonZeroByValAlign()
4333 if (Outs[i].Flags.isByVal()) {
4335 DAG.
getConstant(Outs[i].Flags.getByValSize(),
DL, MVT::i32);
4338 Outs[i].Flags.getNonZeroByValAlign(),
4340 nullptr, std::nullopt, DstInfo,
4346 DAG.
getStore(Chain,
DL, Arg, DstAddr, DstInfo, Alignment);
4352 if (!MemOpChains.
empty())
4360 TokenGlue = DAG.
getNode(ISD::CONVERGENCECTRL_GLUE,
DL, MVT::Glue,
4368 unsigned ArgIdx = 0;
4369 for (
auto [Reg, Val] : RegsToPass) {
4370 if (ArgIdx++ >= NumSpecialInputs &&
4371 (IsChainCallConv || !Val->
isDivergent()) &&
TRI->isSGPRPhysReg(Reg)) {
4397 if (IsTailCall && !IsSibCall) {
4402 std::vector<SDValue>
Ops({Chain});
4408 Ops.push_back(Callee);
4425 Ops.push_back(Callee);
4436 if (IsChainCallConv)
4441 for (
auto &[Reg, Val] : RegsToPass)
4445 const uint32_t *Mask =
TRI->getCallPreservedMask(MF, CallConv);
4446 assert(Mask &&
"Missing call preserved mask for calling convention");
4456 MVT::Glue, GlueOps),
4461 Ops.push_back(InGlue);
4481 if (Info->isWholeWaveFunction())
4489 Chain =
Call.getValue(0);
4490 InGlue =
Call.getValue(1);
4492 uint64_t CalleePopBytes = NumBytes;
4513 EVT VT =
Op.getValueType();
4527 "Stack grows upwards for AMDGPU");
4529 Chain = BaseAddr.getValue(1);
4531 if (Alignment > StackAlign) {
4533 << Subtarget->getWavefrontSizeLog2();
4534 uint64_t StackAlignMask = ScaledAlignment - 1;
4541 assert(
Size.getValueType() == MVT::i32 &&
"Size must be 32-bit");
4547 DAG.
getConstant(Subtarget->getWavefrontSizeLog2(), dl, MVT::i32));
4558 DAG.
getConstant(Subtarget->getWavefrontSizeLog2(), dl, MVT::i32));
4574 if (
Op.getValueType() != MVT::i32)
4593 assert(
Op.getValueType() == MVT::i32);
4602 Op.getOperand(0), IntrinID, GetRoundBothImm);
4636 SDValue RoundModeTimesNumBits =
4656 TableEntry, EnumOffset);
4672 static_cast<uint32_t>(ConstMode->getZExtValue()),
4684 if (UseReducedTable) {
4690 SDValue RoundModeTimesNumBits =
4710 SDValue RoundModeTimesNumBits =
4719 NewMode = TruncTable;
4728 ReadFirstLaneID, NewMode);
4741 IntrinID, RoundBothImm, NewMode);
4747 if (
Op->isDivergent() &&
4748 (!Subtarget->hasVmemPrefInsts() || !
Op.getConstantOperandVal(4)))
4758 if (Subtarget->hasSafeSmemPrefetch())
4766 if (!Subtarget->hasSafeSmemPrefetch() && !
Op.getConstantOperandVal(4))
4775 SDValue Src =
Op.getOperand(IsStrict ? 1 : 0);
4776 EVT SrcVT = Src.getValueType();
4785 EVT DstVT =
Op.getValueType();
4789 return DAG.
getNode(ISD::BF16_TO_FP, SL, DstVT, BitCast);
4794 if (
Op.getValueType() != MVT::i64)
4808 Op.getOperand(0), IntrinID, ModeHwRegImm);
4810 Op.getOperand(0), IntrinID, TrapHwRegImm);
4817 SDValue Result = DAG.
getNode(ISD::BITCAST, SL, MVT::i64, CvtPtr);
4824 if (
Op.getOperand(1).getValueType() != MVT::i64)
4836 ReadFirstLaneID, NewModeReg);
4838 ReadFirstLaneID, NewTrapReg);
4840 unsigned ModeHwReg =
4843 unsigned TrapHwReg =
4851 IntrinID, ModeHwRegImm, NewModeReg);
4854 IntrinID, TrapHwRegImm, NewTrapReg);
4863 .
Case(
"m0", AMDGPU::M0)
4864 .
Case(
"exec", AMDGPU::EXEC)
4865 .
Case(
"exec_lo", AMDGPU::EXEC_LO)
4866 .
Case(
"exec_hi", AMDGPU::EXEC_HI)
4867 .
Case(
"flat_scratch", AMDGPU::FLAT_SCR)
4868 .
Case(
"flat_scratch_lo", AMDGPU::FLAT_SCR_LO)
4869 .
Case(
"flat_scratch_hi", AMDGPU::FLAT_SCR_HI)
4874 if (!Subtarget->hasFlatScrRegister() &&
4875 Subtarget->getRegisterInfo()->regsOverlap(Reg, AMDGPU::FLAT_SCR)) {
4877 "\" for subtarget."));
4882 case AMDGPU::EXEC_LO:
4883 case AMDGPU::EXEC_HI:
4884 case AMDGPU::FLAT_SCR_LO:
4885 case AMDGPU::FLAT_SCR_HI:
4890 case AMDGPU::FLAT_SCR:
4909 MI.setDesc(
TII->getKillTerminatorFromPseudo(
MI.getOpcode()));
4918static std::pair<MachineBasicBlock *, MachineBasicBlock *>
4940 auto Next = std::next(
I);
4951 MBB.addSuccessor(LoopBB);
4953 return std::pair(LoopBB, RemainderBB);
4960 auto I =
MI.getIterator();
4961 auto E = std::next(
I);
4983 Src->setIsKill(
false);
4993 BuildMI(*LoopBB, LoopBB->begin(),
DL,
TII->get(AMDGPU::S_SETREG_IMM32_B32))
4999 Register Reg =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5002 BuildMI(*LoopBB,
I,
DL,
TII->get(AMDGPU::S_GETREG_B32), Reg)
5026 unsigned InitReg,
unsigned ResultReg,
unsigned PhiReg,
5027 unsigned InitSaveExecReg,
int Offset,
bool UseGPRIdxMode,
5037 Register PhiExec =
MRI.createVirtualRegister(BoolRC);
5038 Register NewExec =
MRI.createVirtualRegister(BoolRC);
5040 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5041 Register CondReg =
MRI.createVirtualRegister(BoolRC);
5049 BuildMI(LoopBB,
I,
DL,
TII->get(TargetOpcode::PHI), PhiExec)
5056 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), CurrentIdxReg)
5060 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::V_CMP_EQ_U32_e64), CondReg)
5068 MRI.setSimpleHint(NewExec, CondReg);
5070 if (UseGPRIdxMode) {
5072 SGPRIdxReg = CurrentIdxReg;
5074 SGPRIdxReg =
MRI.createVirtualRegister(&AMDGPU::SGPR_32RegClass);
5075 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::S_ADD_I32), SGPRIdxReg)
5085 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::S_ADD_I32), AMDGPU::M0)
5116 unsigned InitResultReg,
unsigned PhiReg,
int Offset,
5117 bool UseGPRIdxMode,
Register &SGPRIdxReg) {
5125 const auto *BoolXExecRC =
TRI->getWaveMaskRegClass();
5127 Register SaveExec =
MRI.createVirtualRegister(BoolXExecRC);
5128 Register TmpExec =
MRI.createVirtualRegister(BoolXExecRC);
5144 InitResultReg, DstReg, PhiReg, TmpExec,
5145 Offset, UseGPRIdxMode, SGPRIdxReg);
5151 LoopBB->removeSuccessor(RemainderBB);
5153 LoopBB->addSuccessor(LandingPad);
5164static std::pair<unsigned, int>
5168 int NumElts =
TRI.getRegSizeInBits(*SuperRC) / 32;
5173 return std::pair(AMDGPU::sub0,
Offset);
5213 Register Tmp =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5230 Register SrcReg =
TII->getNamedOperand(
MI, AMDGPU::OpName::src)->getReg();
5231 int Offset =
TII->getNamedOperand(
MI, AMDGPU::OpName::offset)->getImm();
5240 const bool UseGPRIdxMode = ST.useVGPRIndexMode();
5243 if (
TII->getRegisterInfo().isSGPRClass(IdxRC)) {
5247 if (UseGPRIdxMode) {
5254 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
true);
5267 MI.eraseFromParent();
5276 Register PhiReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5277 Register InitReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5283 UseGPRIdxMode, SGPRIdxReg);
5287 if (UseGPRIdxMode) {
5289 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
true);
5291 BuildMI(*LoopBB, InsPt,
DL, GPRIDXDesc, Dst)
5296 BuildMI(*LoopBB, InsPt,
DL,
TII->get(AMDGPU::V_MOVRELS_B32_e32), Dst)
5301 MI.eraseFromParent();
5318 int Offset =
TII->getNamedOperand(
MI, AMDGPU::OpName::offset)->getImm();
5328 const bool UseGPRIdxMode = ST.useVGPRIndexMode();
5330 if (Idx->
getReg() == AMDGPU::NoRegister) {
5341 MI.eraseFromParent();
5346 if (
TII->getRegisterInfo().isSGPRClass(IdxRC)) {
5350 if (UseGPRIdxMode) {
5354 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
false);
5363 const MCInstrDesc &MovRelDesc =
TII->getIndirectRegWriteMovRelPseudo(
5364 TRI.getRegSizeInBits(*VecRC), 32,
false);
5370 MI.eraseFromParent();
5380 Register PhiReg =
MRI.createVirtualRegister(VecRC);
5384 UseGPRIdxMode, SGPRIdxReg);
5387 if (UseGPRIdxMode) {
5389 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
false);
5391 BuildMI(*LoopBB, InsPt,
DL, GPRIDXDesc, Dst)
5397 const MCInstrDesc &MovRelDesc =
TII->getIndirectRegWriteMovRelPseudo(
5398 TRI.getRegSizeInBits(*VecRC), 32,
false);
5399 BuildMI(*LoopBB, InsPt,
DL, MovRelDesc, Dst)
5405 MI.eraseFromParent();
5421 bool IsAdd = (
MI.getOpcode() == AMDGPU::S_ADD_U64_PSEUDO);
5422 if (ST.hasScalarAddSub64()) {
5423 unsigned Opc = IsAdd ? AMDGPU::S_ADD_U64 : AMDGPU::S_SUB_U64;
5433 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5434 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5437 MI,
MRI, Src0, BoolRC, AMDGPU::sub0, &AMDGPU::SReg_32RegClass);
5439 MI,
MRI, Src0, BoolRC, AMDGPU::sub1, &AMDGPU::SReg_32RegClass);
5442 MI,
MRI, Src1, BoolRC, AMDGPU::sub0, &AMDGPU::SReg_32RegClass);
5444 MI,
MRI, Src1, BoolRC, AMDGPU::sub1, &AMDGPU::SReg_32RegClass);
5446 unsigned LoOpc = IsAdd ? AMDGPU::S_ADD_U32 : AMDGPU::S_SUB_U32;
5447 unsigned HiOpc = IsAdd ? AMDGPU::S_ADDC_U32 : AMDGPU::S_SUBB_U32;
5456 MI.eraseFromParent();
5462 case AMDGPU::S_MIN_U32:
5463 return std::numeric_limits<uint32_t>::max();
5464 case AMDGPU::S_MIN_I32:
5465 return std::numeric_limits<int32_t>::max();
5466 case AMDGPU::S_MAX_U32:
5467 return std::numeric_limits<uint32_t>::min();
5468 case AMDGPU::S_MAX_I32:
5469 return std::numeric_limits<int32_t>::min();
5470 case AMDGPU::S_ADD_I32:
5471 case AMDGPU::S_SUB_I32:
5472 case AMDGPU::S_OR_B32:
5473 case AMDGPU::S_XOR_B32:
5474 return std::numeric_limits<uint32_t>::min();
5475 case AMDGPU::S_AND_B32:
5476 return std::numeric_limits<uint32_t>::max();
5479 "Unexpected opcode in getIdentityValueFor32BitWaveReduction");
5485 case AMDGPU::V_CMP_LT_U64_e64:
5486 return std::numeric_limits<uint64_t>::max();
5487 case AMDGPU::V_CMP_LT_I64_e64:
5488 return std::numeric_limits<int64_t>::max();
5489 case AMDGPU::V_CMP_GT_U64_e64:
5490 return std::numeric_limits<uint64_t>::min();
5491 case AMDGPU::V_CMP_GT_I64_e64:
5492 return std::numeric_limits<int64_t>::min();
5493 case AMDGPU::S_ADD_U64_PSEUDO:
5494 case AMDGPU::S_SUB_U64_PSEUDO:
5495 case AMDGPU::S_OR_B64:
5496 case AMDGPU::S_XOR_B64:
5497 return std::numeric_limits<uint64_t>::min();
5498 case AMDGPU::S_AND_B64:
5499 return std::numeric_limits<uint64_t>::max();
5502 "Unexpected opcode in getIdentityValueFor64BitWaveReduction");
5507 return Opc == AMDGPU::S_MIN_U32 ||
Opc == AMDGPU::S_MIN_I32 ||
5508 Opc == AMDGPU::S_MAX_U32 ||
Opc == AMDGPU::S_MAX_I32 ||
5509 Opc == AMDGPU::S_ADD_I32 ||
Opc == AMDGPU::S_SUB_I32 ||
5510 Opc == AMDGPU::S_AND_B32 ||
Opc == AMDGPU::S_OR_B32 ||
5511 Opc == AMDGPU::S_XOR_B32;
5525 bool isSGPR =
TRI->isSGPRClass(
MRI.getRegClass(SrcReg));
5530 case AMDGPU::S_MIN_U32:
5531 case AMDGPU::S_MIN_I32:
5532 case AMDGPU::S_MAX_U32:
5533 case AMDGPU::S_MAX_I32:
5534 case AMDGPU::S_AND_B32:
5535 case AMDGPU::S_OR_B32: {
5541 case AMDGPU::V_CMP_LT_U64_e64:
5542 case AMDGPU::V_CMP_LT_I64_e64:
5543 case AMDGPU::V_CMP_GT_U64_e64:
5544 case AMDGPU::V_CMP_GT_I64_e64:
5545 case AMDGPU::S_AND_B64:
5546 case AMDGPU::S_OR_B64: {
5552 case AMDGPU::S_XOR_B32:
5553 case AMDGPU::S_XOR_B64:
5554 case AMDGPU::S_ADD_I32:
5555 case AMDGPU::S_ADD_U64_PSEUDO:
5556 case AMDGPU::S_SUB_I32:
5557 case AMDGPU::S_SUB_U64_PSEUDO: {
5560 Register ExecMask =
MRI.createVirtualRegister(WaveMaskRegClass);
5562 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5564 bool IsWave32 = ST.isWave32();
5565 unsigned MovOpc = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
5566 MCRegister ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
5567 unsigned BitCountOpc =
5568 IsWave32 ? AMDGPU::S_BCNT1_I32_B32 : AMDGPU::S_BCNT1_I32_B64;
5572 auto NewAccumulator =
5577 case AMDGPU::S_XOR_B32:
5578 case AMDGPU::S_XOR_B64: {
5584 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5587 .
addReg(NewAccumulator->getOperand(0).getReg())
5590 if (
Opc == AMDGPU::S_XOR_B32) {
5596 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5598 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5602 TRI->getSubRegisterClass(SrcRC, AMDGPU::sub0);
5605 MI,
MRI,
MI.getOperand(1), SrcRC, AMDGPU::sub0, SrcSubRC);
5607 MI,
MRI,
MI.getOperand(1), SrcRC, AMDGPU::sub1, SrcSubRC);
5617 BuildMI(BB,
MI,
DL,
TII->get(TargetOpcode::REG_SEQUENCE), DstReg)
5625 case AMDGPU::S_SUB_I32: {
5626 Register NegatedVal =
MRI.createVirtualRegister(DstRegClass);
5634 .
addReg(NewAccumulator->getOperand(0).getReg());
5637 case AMDGPU::S_ADD_I32: {
5640 .
addReg(NewAccumulator->getOperand(0).getReg());
5643 case AMDGPU::S_ADD_U64_PSEUDO:
5644 case AMDGPU::S_SUB_U64_PSEUDO: {
5645 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5646 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5648 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5650 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5651 Register CarryReg =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5652 Register AddReg =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5654 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5656 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5660 TRI->getSubRegisterClass(Src1RC, AMDGPU::sub0);
5663 MI,
MRI,
MI.getOperand(1), Src1RC, AMDGPU::sub0, Src1SubRC);
5665 MI,
MRI,
MI.getOperand(1), Src1RC, AMDGPU::sub1, Src1SubRC);
5667 if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
5670 .
addReg(NewAccumulator->getOperand(0).getReg())
5680 Register LowOpcode =
Opc == AMDGPU::S_SUB_U64_PSEUDO
5682 : NewAccumulator->getOperand(0).getReg();
5693 Register HiVal =
Opc == AMDGPU::S_SUB_U64_PSEUDO ? AddReg : DestSub1;
5699 if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
5705 BuildMI(BB,
MI,
DL,
TII->get(TargetOpcode::REG_SEQUENCE), DstReg)
5737 Register LoopIterator =
MRI.createVirtualRegister(WaveMaskRegClass);
5738 Register IdentityValReg =
MRI.createVirtualRegister(DstRegClass);
5739 Register AccumulatorReg =
MRI.createVirtualRegister(DstRegClass);
5740 Register ActiveBitsReg =
MRI.createVirtualRegister(WaveMaskRegClass);
5741 Register NewActiveBitsReg =
MRI.createVirtualRegister(WaveMaskRegClass);
5742 Register FF1Reg =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5743 Register LaneValueReg =
MRI.createVirtualRegister(DstRegClass);
5745 bool IsWave32 = ST.isWave32();
5746 unsigned MovOpcForExec = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
5747 unsigned ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
5754 BuildMI(BB,
I,
DL,
TII->get(AMDGPU::S_MOV_B32), IdentityValReg)
5758 BuildMI(BB,
I,
DL,
TII->get(AMDGPU::S_MOV_B64_IMM_PSEUDO), IdentityValReg)
5767 I = ComputeLoop->begin();
5769 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::PHI), AccumulatorReg)
5773 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::PHI), ActiveBitsReg)
5777 I = ComputeLoop->end();
5780 unsigned SFFOpc = IsWave32 ? AMDGPU::S_FF1_I32_B32 : AMDGPU::S_FF1_I32_B64;
5784 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
5793 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5795 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5796 Register LaneValReg =
MRI.createVirtualRegister(&AMDGPU::SReg_64RegClass);
5799 TRI->getSubRegisterClass(SrcRC, AMDGPU::sub0);
5801 MI,
MRI,
MI.getOperand(1), SrcRC, AMDGPU::sub0, SrcSubRC);
5803 MI,
MRI,
MI.getOperand(1), SrcRC, AMDGPU::sub1, SrcSubRC);
5805 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
5809 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
5813 auto LaneValue =
BuildMI(*ComputeLoop,
I,
DL,
5814 TII->get(TargetOpcode::REG_SEQUENCE), LaneValReg)
5820 case AMDGPU::S_OR_B64:
5821 case AMDGPU::S_AND_B64:
5822 case AMDGPU::S_XOR_B64: {
5825 .
addReg(LaneValue->getOperand(0).getReg())
5829 case AMDGPU::V_CMP_GT_I64_e64:
5830 case AMDGPU::V_CMP_GT_U64_e64:
5831 case AMDGPU::V_CMP_LT_I64_e64:
5832 case AMDGPU::V_CMP_LT_U64_e64: {
5833 Register LaneMaskReg =
MRI.createVirtualRegister(WaveMaskRegClass);
5835 MRI.createVirtualRegister(WaveMaskRegClass);
5838 TRI->getSubRegisterClass(VregClass, AMDGPU::sub0);
5839 Register AccumulatorVReg =
MRI.createVirtualRegister(VregClass);
5842 VregClass, AMDGPU::sub0, VSubRegClass);
5845 VregClass, AMDGPU::sub1, VSubRegClass);
5846 BuildMI(*ComputeLoop,
I,
DL,
TII->get(TargetOpcode::REG_SEQUENCE),
5853 .
addReg(LaneValue->getOperand(0).getReg())
5854 .
addReg(AccumulatorVReg);
5856 unsigned AndOpc = IsWave32 ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64;
5857 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AndOpc), ComparisonResultReg)
5861 NewAccumulator =
BuildMI(*ComputeLoop,
I,
DL,
5862 TII->get(AMDGPU::S_CSELECT_B64), DstReg)
5863 .
addReg(LaneValue->getOperand(0).getReg())
5867 case AMDGPU::S_ADD_U64_PSEUDO:
5868 case AMDGPU::S_SUB_U64_PSEUDO: {
5871 .
addReg(LaneValue->getOperand(0).getReg());
5878 unsigned BITSETOpc =
5879 IsWave32 ? AMDGPU::S_BITSET0_B32 : AMDGPU::S_BITSET0_B64;
5880 BuildMI(*ComputeLoop,
I,
DL,
TII->get(BITSETOpc), NewActiveBitsReg)
5886 ActiveBits.addReg(NewActiveBitsReg).addMBB(ComputeLoop);
5889 unsigned CMPOpc = IsWave32 ? AMDGPU::S_CMP_LG_U32 : AMDGPU::S_CMP_LG_U64;
5891 .
addReg(NewActiveBitsReg)
5893 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::S_CBRANCH_SCC1))
5898 MI.eraseFromParent();
5910 switch (
MI.getOpcode()) {
5911 case AMDGPU::WAVE_REDUCE_UMIN_PSEUDO_U32:
5913 case AMDGPU::WAVE_REDUCE_UMIN_PSEUDO_U64:
5915 case AMDGPU::WAVE_REDUCE_MIN_PSEUDO_I32:
5917 case AMDGPU::WAVE_REDUCE_MIN_PSEUDO_I64:
5919 case AMDGPU::WAVE_REDUCE_UMAX_PSEUDO_U32:
5921 case AMDGPU::WAVE_REDUCE_UMAX_PSEUDO_U64:
5923 case AMDGPU::WAVE_REDUCE_MAX_PSEUDO_I32:
5925 case AMDGPU::WAVE_REDUCE_MAX_PSEUDO_I64:
5927 case AMDGPU::WAVE_REDUCE_ADD_PSEUDO_I32:
5929 case AMDGPU::WAVE_REDUCE_ADD_PSEUDO_U64:
5931 case AMDGPU::WAVE_REDUCE_SUB_PSEUDO_I32:
5933 case AMDGPU::WAVE_REDUCE_SUB_PSEUDO_U64:
5935 case AMDGPU::WAVE_REDUCE_AND_PSEUDO_B32:
5937 case AMDGPU::WAVE_REDUCE_AND_PSEUDO_B64:
5939 case AMDGPU::WAVE_REDUCE_OR_PSEUDO_B32:
5941 case AMDGPU::WAVE_REDUCE_OR_PSEUDO_B64:
5943 case AMDGPU::WAVE_REDUCE_XOR_PSEUDO_B32:
5945 case AMDGPU::WAVE_REDUCE_XOR_PSEUDO_B64:
5947 case AMDGPU::S_UADDO_PSEUDO:
5948 case AMDGPU::S_USUBO_PSEUDO: {
5955 unsigned Opc = (
MI.getOpcode() == AMDGPU::S_UADDO_PSEUDO)
5957 : AMDGPU::S_SUB_I32;
5968 MI.eraseFromParent();
5971 case AMDGPU::S_ADD_U64_PSEUDO:
5972 case AMDGPU::S_SUB_U64_PSEUDO: {
5975 case AMDGPU::V_ADD_U64_PSEUDO:
5976 case AMDGPU::V_SUB_U64_PSEUDO: {
5982 bool IsAdd = (
MI.getOpcode() == AMDGPU::V_ADD_U64_PSEUDO);
5988 if (ST.hasAddSubU64Insts()) {
5990 TII->get(IsAdd ? AMDGPU::V_ADD_U64_e64
5991 : AMDGPU::V_SUB_U64_e64),
5996 TII->legalizeOperands(*
I);
5997 MI.eraseFromParent();
6001 if (IsAdd && ST.hasLshlAddU64Inst()) {
6007 TII->legalizeOperands(*
Add);
6008 MI.eraseFromParent();
6012 const auto *CarryRC =
TRI->getWaveMaskRegClass();
6014 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6015 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6017 Register CarryReg =
MRI.createVirtualRegister(CarryRC);
6018 Register DeadCarryReg =
MRI.createVirtualRegister(CarryRC);
6022 : &AMDGPU::VReg_64RegClass;
6025 : &AMDGPU::VReg_64RegClass;
6028 TRI->getSubRegisterClass(Src0RC, AMDGPU::sub0);
6030 TRI->getSubRegisterClass(Src1RC, AMDGPU::sub1);
6033 MI,
MRI, Src0, Src0RC, AMDGPU::sub0, Src0SubRC);
6035 MI,
MRI, Src1, Src1RC, AMDGPU::sub0, Src1SubRC);
6038 MI,
MRI, Src0, Src0RC, AMDGPU::sub1, Src0SubRC);
6040 MI,
MRI, Src1, Src1RC, AMDGPU::sub1, Src1SubRC);
6043 IsAdd ? AMDGPU::V_ADD_CO_U32_e64 : AMDGPU::V_SUB_CO_U32_e64;
6050 unsigned HiOpc = IsAdd ? AMDGPU::V_ADDC_U32_e64 : AMDGPU::V_SUBB_U32_e64;
6064 TII->legalizeOperands(*LoHalf);
6065 TII->legalizeOperands(*HiHalf);
6066 MI.eraseFromParent();
6069 case AMDGPU::S_ADD_CO_PSEUDO:
6070 case AMDGPU::S_SUB_CO_PSEUDO: {
6084 unsigned Opc = (
MI.getOpcode() == AMDGPU::S_ADD_CO_PSEUDO)
6085 ? AMDGPU::S_ADDC_U32
6086 : AMDGPU::S_SUBB_U32;
6088 Register RegOp0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6089 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp0)
6094 Register RegOp1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6095 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp1)
6099 Register RegOp2 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6101 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp2)
6107 unsigned WaveSize =
TRI->getRegSizeInBits(*Src2RC);
6108 assert(WaveSize == 64 || WaveSize == 32);
6110 if (WaveSize == 64) {
6111 if (ST.hasScalarCompareEq64()) {
6117 TRI->getSubRegisterClass(Src2RC, AMDGPU::sub0);
6119 MII,
MRI, Src2, Src2RC, AMDGPU::sub0, SubRC);
6121 MII,
MRI, Src2, Src2RC, AMDGPU::sub1, SubRC);
6122 Register Src2_32 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6124 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::S_OR_B32), Src2_32)
6145 (WaveSize == 64) ? AMDGPU::S_CSELECT_B64 : AMDGPU::S_CSELECT_B32;
6151 MI.eraseFromParent();
6154 case AMDGPU::SI_INIT_M0: {
6157 TII->get(M0Init.
isReg() ? AMDGPU::COPY : AMDGPU::S_MOV_B32),
6160 MI.eraseFromParent();
6163 case AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM: {
6166 TII->get(AMDGPU::S_CMP_EQ_U32))
6171 case AMDGPU::GET_GROUPSTATICSIZE: {
6176 .
add(
MI.getOperand(0))
6178 MI.eraseFromParent();
6181 case AMDGPU::GET_SHADERCYCLESHILO: {
6196 Register RegHi1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6198 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES_HI, 0, 32));
6199 Register RegLo1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6201 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES, 0, 32));
6202 Register RegHi2 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6204 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES_HI, 0, 32));
6208 Register RegLo =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6213 .
add(
MI.getOperand(0))
6218 MI.eraseFromParent();
6221 case AMDGPU::SI_INDIRECT_SRC_V1:
6222 case AMDGPU::SI_INDIRECT_SRC_V2:
6223 case AMDGPU::SI_INDIRECT_SRC_V4:
6224 case AMDGPU::SI_INDIRECT_SRC_V8:
6225 case AMDGPU::SI_INDIRECT_SRC_V9:
6226 case AMDGPU::SI_INDIRECT_SRC_V10:
6227 case AMDGPU::SI_INDIRECT_SRC_V11:
6228 case AMDGPU::SI_INDIRECT_SRC_V12:
6229 case AMDGPU::SI_INDIRECT_SRC_V16:
6230 case AMDGPU::SI_INDIRECT_SRC_V32:
6232 case AMDGPU::SI_INDIRECT_DST_V1:
6233 case AMDGPU::SI_INDIRECT_DST_V2:
6234 case AMDGPU::SI_INDIRECT_DST_V4:
6235 case AMDGPU::SI_INDIRECT_DST_V8:
6236 case AMDGPU::SI_INDIRECT_DST_V9:
6237 case AMDGPU::SI_INDIRECT_DST_V10:
6238 case AMDGPU::SI_INDIRECT_DST_V11:
6239 case AMDGPU::SI_INDIRECT_DST_V12:
6240 case AMDGPU::SI_INDIRECT_DST_V16:
6241 case AMDGPU::SI_INDIRECT_DST_V32:
6243 case AMDGPU::SI_KILL_F32_COND_IMM_PSEUDO:
6244 case AMDGPU::SI_KILL_I1_PSEUDO:
6246 case AMDGPU::V_CNDMASK_B64_PSEUDO: {
6255 Register SrcCond =
MI.getOperand(3).getReg();
6257 Register DstLo =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6258 Register DstHi =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6259 const auto *CondRC =
TRI->getWaveMaskRegClass();
6260 Register SrcCondCopy =
MRI.createVirtualRegister(CondRC);
6264 : &AMDGPU::VReg_64RegClass;
6267 : &AMDGPU::VReg_64RegClass;
6270 TRI->getSubRegisterClass(Src0RC, AMDGPU::sub0);
6272 TRI->getSubRegisterClass(Src1RC, AMDGPU::sub1);
6275 MI,
MRI, Src0, Src0RC, AMDGPU::sub0, Src0SubRC);
6277 MI,
MRI, Src1, Src1RC, AMDGPU::sub0, Src1SubRC);
6280 MI,
MRI, Src0, Src0RC, AMDGPU::sub1, Src0SubRC);
6282 MI,
MRI, Src1, Src1RC, AMDGPU::sub1, Src1SubRC);
6303 MI.eraseFromParent();
6306 case AMDGPU::SI_BR_UNDEF: {
6310 .
add(
MI.getOperand(0));
6312 MI.eraseFromParent();
6315 case AMDGPU::ADJCALLSTACKUP:
6316 case AMDGPU::ADJCALLSTACKDOWN: {
6323 case AMDGPU::SI_CALL_ISEL: {
6327 unsigned ReturnAddrReg =
TII->getRegisterInfo().getReturnAddressReg(*MF);
6330 MIB =
BuildMI(*BB,
MI,
DL,
TII->get(AMDGPU::SI_CALL), ReturnAddrReg);
6336 MI.eraseFromParent();
6339 case AMDGPU::V_ADD_CO_U32_e32:
6340 case AMDGPU::V_SUB_CO_U32_e32:
6341 case AMDGPU::V_SUBREV_CO_U32_e32: {
6344 unsigned Opc =
MI.getOpcode();
6346 bool NeedClampOperand =
false;
6347 if (
TII->pseudoToMCOpcode(
Opc) == -1) {
6349 NeedClampOperand =
true;
6353 if (
TII->isVOP3(*
I)) {
6358 I.add(
MI.getOperand(1)).add(
MI.getOperand(2));
6359 if (NeedClampOperand)
6362 TII->legalizeOperands(*
I);
6364 MI.eraseFromParent();
6367 case AMDGPU::V_ADDC_U32_e32:
6368 case AMDGPU::V_SUBB_U32_e32:
6369 case AMDGPU::V_SUBBREV_U32_e32:
6372 TII->legalizeOperands(
MI);
6374 case AMDGPU::DS_GWS_INIT:
6375 case AMDGPU::DS_GWS_SEMA_BR:
6376 case AMDGPU::DS_GWS_BARRIER:
6377 TII->enforceOperandRCAlignment(
MI, AMDGPU::OpName::data0);
6379 case AMDGPU::DS_GWS_SEMA_V:
6380 case AMDGPU::DS_GWS_SEMA_P:
6381 case AMDGPU::DS_GWS_SEMA_RELEASE_ALL:
6389 case AMDGPU::S_SETREG_B32: {
6405 const unsigned SetMask = WidthMask <<
Offset;
6408 unsigned SetDenormOp = 0;
6409 unsigned SetRoundOp = 0;
6417 SetRoundOp = AMDGPU::S_ROUND_MODE;
6418 SetDenormOp = AMDGPU::S_DENORM_MODE;
6420 SetRoundOp = AMDGPU::S_ROUND_MODE;
6422 SetDenormOp = AMDGPU::S_DENORM_MODE;
6425 if (SetRoundOp || SetDenormOp) {
6428 if (Def && Def->isMoveImmediate() && Def->getOperand(1).isImm()) {
6429 unsigned ImmVal = Def->getOperand(1).getImm();
6443 MI.eraseFromParent();
6452 MI.setDesc(
TII->get(AMDGPU::S_SETREG_B32_mode));
6456 case AMDGPU::S_INVERSE_BALLOT_U32:
6457 case AMDGPU::S_INVERSE_BALLOT_U64:
6460 MI.setDesc(
TII->get(AMDGPU::COPY));
6462 case AMDGPU::ENDPGM_TRAP: {
6465 MI.setDesc(
TII->get(AMDGPU::S_ENDPGM));
6485 MI.eraseFromParent();
6488 case AMDGPU::SIMULATED_TRAP: {
6489 assert(Subtarget->hasPrivEnabledTrap2NopBug());
6492 TII->insertSimulatedTrap(
MRI, *BB,
MI,
MI.getDebugLoc());
6493 MI.eraseFromParent();
6496 case AMDGPU::SI_TCRETURN_GFX_WholeWave:
6497 case AMDGPU::SI_WHOLE_WAVE_FUNC_RETURN: {
6503 assert(Setup &&
"Couldn't find SI_SETUP_WHOLE_WAVE_FUNC");
6504 Register OriginalExec = Setup->getOperand(0).getReg();
6506 MI.getOperand(0).setReg(OriginalExec);
6543 return (VT == MVT::i16) ? MVT::i16 : MVT::i32;
6547 return (Ty.getScalarSizeInBits() <= 16 && Subtarget->has16BitInsts())
6574 if (!Subtarget->hasMadMacF32Insts())
6575 return Subtarget->hasFastFMAF32();
6581 return Subtarget->hasFastFMAF32() || Subtarget->hasDLInsts();
6584 return Subtarget->hasFastFMAF32() && Subtarget->hasDLInsts();
6600 switch (Ty.getScalarSizeInBits()) {
6618 if (Ty.getScalarSizeInBits() == 16)
6620 if (Ty.getScalarSizeInBits() == 32)
6621 return Subtarget->hasMadMacF32Insts() &&
6631 EVT VT =
N->getValueType(0);
6633 return Subtarget->hasMadMacF32Insts() &&
6635 if (VT == MVT::f16) {
6636 return Subtarget->hasMadF16() &&
6651 unsigned Opc =
Op.getOpcode();
6652 EVT VT =
Op.getValueType();
6653 assert(VT == MVT::v4i16 || VT == MVT::v4f16 || VT == MVT::v4f32 ||
6654 VT == MVT::v8i16 || VT == MVT::v8f16 || VT == MVT::v16i16 ||
6655 VT == MVT::v16f16 || VT == MVT::v8f32 || VT == MVT::v16f32 ||
6656 VT == MVT::v32f32 || VT == MVT::v32i16 || VT == MVT::v32f16);
6672 [[maybe_unused]]
EVT VT =
Op.getValueType();
6674 assert((VT == MVT::v2i32 || VT == MVT::v4i32 || VT == MVT::v8i32 ||
6675 VT == MVT::v16i32) &&
6676 "Unexpected ValueType.");
6685 unsigned Opc =
Op.getOpcode();
6686 EVT VT =
Op.getValueType();
6687 assert(VT == MVT::v4i16 || VT == MVT::v4f16 || VT == MVT::v4bf16 ||
6688 VT == MVT::v4f32 || VT == MVT::v8i16 || VT == MVT::v8f16 ||
6689 VT == MVT::v8bf16 || VT == MVT::v16i16 || VT == MVT::v16f16 ||
6690 VT == MVT::v16bf16 || VT == MVT::v8f32 || VT == MVT::v16f32 ||
6691 VT == MVT::v32f32 || VT == MVT::v32i16 || VT == MVT::v32f16 ||
6692 VT == MVT::v32bf16);
6700 DAG.
getNode(
Opc, SL, Lo0.getValueType(), Lo0, Lo1,
Op->getFlags());
6702 DAG.
getNode(
Opc, SL, Hi0.getValueType(), Hi0, Hi1,
Op->getFlags());
6709 unsigned Opc =
Op.getOpcode();
6710 EVT VT =
Op.getValueType();
6711 assert(VT == MVT::v4i16 || VT == MVT::v4f16 || VT == MVT::v8i16 ||
6712 VT == MVT::v8f16 || VT == MVT::v4f32 || VT == MVT::v16i16 ||
6713 VT == MVT::v16f16 || VT == MVT::v8f32 || VT == MVT::v16f32 ||
6714 VT == MVT::v32f32 || VT == MVT::v32f16 || VT == MVT::v32i16 ||
6715 VT == MVT::v4bf16 || VT == MVT::v8bf16 || VT == MVT::v16bf16 ||
6716 VT == MVT::v32bf16);
6721 : std::pair(Op0, Op0);
6730 DAG.
getNode(
Opc, SL, ResVT.first, Lo0, Lo1, Lo2,
Op->getFlags());
6732 DAG.
getNode(
Opc, SL, ResVT.second, Hi0, Hi1, Hi2,
Op->getFlags());
6738 switch (
Op.getOpcode()) {
6742 return LowerBRCOND(
Op, DAG);
6744 return LowerRETURNADDR(
Op, DAG);
6747 assert((!Result.getNode() || Result.getNode()->getNumValues() == 2) &&
6748 "Load should return a value and a chain");
6752 EVT VT =
Op.getValueType();
6754 return lowerFSQRTF32(
Op, DAG);
6756 return lowerFSQRTF64(
Op, DAG);
6761 return LowerTrig(
Op, DAG);
6763 return LowerSELECT(
Op, DAG);
6765 return LowerFDIV(
Op, DAG);
6767 return LowerFFREXP(
Op, DAG);
6768 case ISD::ATOMIC_CMP_SWAP:
6769 return LowerATOMIC_CMP_SWAP(
Op, DAG);
6771 return LowerSTORE(
Op, DAG);
6775 return LowerGlobalAddress(MFI,
Op, DAG);
6778 return LowerINTRINSIC_WO_CHAIN(
Op, DAG);
6780 return LowerINTRINSIC_W_CHAIN(
Op, DAG);
6782 return LowerINTRINSIC_VOID(
Op, DAG);
6783 case ISD::ADDRSPACECAST:
6784 return lowerADDRSPACECAST(
Op, DAG);
6786 return lowerINSERT_SUBVECTOR(
Op, DAG);
6788 return lowerINSERT_VECTOR_ELT(
Op, DAG);
6790 return lowerEXTRACT_VECTOR_ELT(
Op, DAG);
6792 return lowerVECTOR_SHUFFLE(
Op, DAG);
6794 return lowerSCALAR_TO_VECTOR(
Op, DAG);
6796 return lowerBUILD_VECTOR(
Op, DAG);
6799 return lowerFP_ROUND(
Op, DAG);
6801 return lowerTRAP(
Op, DAG);
6802 case ISD::DEBUGTRAP:
6803 return lowerDEBUGTRAP(
Op, DAG);
6812 return lowerFMINNUM_FMAXNUM(
Op, DAG);
6813 case ISD::FMINIMUMNUM:
6814 case ISD::FMAXIMUMNUM:
6815 return lowerFMINIMUMNUM_FMAXIMUMNUM(
Op, DAG);
6818 return lowerFMINIMUM_FMAXIMUM(
Op, DAG);
6821 return lowerFLDEXP(
Op, DAG);
6838 case ISD::FMINNUM_IEEE:
6839 case ISD::FMAXNUM_IEEE:
6846 return lowerFCOPYSIGN(
Op, DAG);
6848 return lowerMUL(
Op, DAG);
6851 return lowerXMULO(
Op, DAG);
6854 return lowerXMUL_LOHI(
Op, DAG);
6855 case ISD::DYNAMIC_STACKALLOC:
6857 case ISD::STACKSAVE:
6861 case ISD::SET_ROUNDING:
6865 case ISD::FP_EXTEND:
6868 case ISD::GET_FPENV:
6870 case ISD::SET_FPENV:
6889 EVT FittingLoadVT = LoadVT;
6914 return DAG.
getNode(ISD::BITCAST,
DL, FittingLoadVT, Result);
6918 return DAG.
getNode(ISD::BITCAST,
DL, FittingLoadVT, Result);
6921SDValue SITargetLowering::adjustLoadValueType(
unsigned Opcode,
MemSDNode *M,
6924 bool IsIntrinsic)
const {
6927 bool Unpacked = Subtarget->hasUnpackedD16VMem();
6928 EVT LoadVT =
M->getValueType(0);
6930 EVT EquivLoadVT = LoadVT;
6944 SDVTList VTList = DAG.
getVTList(EquivLoadVT, MVT::Other);
6948 M->getMemoryVT(),
M->getMemOperand());
6959 EVT LoadVT =
M->getValueType(0);
6965 assert(
M->getNumValues() == 2 ||
M->getNumValues() == 3);
6966 bool IsTFE =
M->getNumValues() == 3;
6979 return handleByteShortBufferLoads(DAG, LoadVT,
DL,
Ops,
M->getMemOperand(),
6983 return getMemIntrinsicNode(
Opc,
DL,
M->getVTList(),
Ops, IntVT,
6984 M->getMemOperand(), DAG);
6988 SDVTList VTList = DAG.
getVTList(CastVT, MVT::Other);
6990 M->getMemOperand(), DAG);
6998 EVT VT =
N->getValueType(0);
6999 unsigned CondCode =
N->getConstantOperandVal(3);
7010 EVT CmpVT =
LHS.getValueType();
7011 if (CmpVT == MVT::i16 && !TLI.
isTypeLegal(MVT::i16)) {
7012 unsigned PromoteOp =
7032 EVT VT =
N->getValueType(0);
7034 unsigned CondCode =
N->getConstantOperandVal(3);
7043 if (CmpVT == MVT::f16 && !TLI.
isTypeLegal(CmpVT)) {
7044 Src0 = DAG.
getNode(ISD::FP_EXTEND, SL, MVT::f32, Src0);
7045 Src1 = DAG.
getNode(ISD::FP_EXTEND, SL, MVT::f32, Src1);
7061 EVT VT =
N->getValueType(0);
7068 Src.getOperand(1), Src.getOperand(2));
7079 Exec = AMDGPU::EXEC_LO;
7081 Exec = AMDGPU::EXEC;
7098 EVT VT =
N->getValueType(0);
7100 unsigned IID =
N->getConstantOperandVal(0);
7101 bool IsPermLane16 = IID == Intrinsic::amdgcn_permlane16 ||
7102 IID == Intrinsic::amdgcn_permlanex16;
7103 bool IsSetInactive = IID == Intrinsic::amdgcn_set_inactive ||
7104 IID == Intrinsic::amdgcn_set_inactive_chain_arg;
7108 unsigned SplitSize = 32;
7109 if (IID == Intrinsic::amdgcn_update_dpp && (ValSize % 64 == 0) &&
7110 ST->hasDPALU_DPP() &&
7118 case Intrinsic::amdgcn_permlane16:
7119 case Intrinsic::amdgcn_permlanex16:
7120 case Intrinsic::amdgcn_update_dpp:
7125 case Intrinsic::amdgcn_writelane:
7128 case Intrinsic::amdgcn_readlane:
7129 case Intrinsic::amdgcn_set_inactive:
7130 case Intrinsic::amdgcn_set_inactive_chain_arg:
7131 case Intrinsic::amdgcn_mov_dpp8:
7134 case Intrinsic::amdgcn_readfirstlane:
7135 case Intrinsic::amdgcn_permlane64:
7145 if (
SDNode *GL =
N->getGluedNode()) {
7146 assert(GL->getOpcode() == ISD::CONVERGENCECTRL_GLUE);
7147 GL = GL->getOperand(0).getNode();
7148 Operands.push_back(DAG.
getNode(ISD::CONVERGENCECTRL_GLUE, SL, MVT::Glue,
7157 if (IID == Intrinsic::amdgcn_readlane || IID == Intrinsic::amdgcn_writelane ||
7158 IID == Intrinsic::amdgcn_mov_dpp8 ||
7159 IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16) {
7160 Src1 =
N->getOperand(2);
7161 if (IID == Intrinsic::amdgcn_writelane ||
7162 IID == Intrinsic::amdgcn_update_dpp || IsPermLane16)
7163 Src2 =
N->getOperand(3);
7166 if (ValSize == SplitSize) {
7176 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16) {
7181 if (IID == Intrinsic::amdgcn_writelane) {
7186 SDValue LaneOp = createLaneOp(Src0, Src1, Src2, MVT::i32);
7188 return IsFloat ? DAG.
getBitcast(VT, Trunc) : Trunc;
7191 if (ValSize % SplitSize != 0)
7195 EVT VT =
N->getValueType(0);
7199 unsigned NumOperands =
N->getNumOperands();
7201 SDNode *GL =
N->getGluedNode();
7206 for (
unsigned i = 0; i != NE; ++i) {
7207 for (
unsigned j = 0, e = GL ? NumOperands - 1 : NumOperands; j != e;
7209 SDValue Operand =
N->getOperand(j);
7224 DAG.
getNode(ISD::CONVERGENCECTRL_GLUE, SL, MVT::Glue,
7239 if (SplitSize == 32) {
7241 return unrollLaneOp(LaneOp.
getNode());
7247 unsigned SubVecNumElt =
7251 SDValue Src0SubVec, Src1SubVec, Src2SubVec;
7252 for (
unsigned i = 0, EltIdx = 0; i < ValSize / SplitSize; i++) {
7256 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive ||
7261 if (IID == Intrinsic::amdgcn_writelane)
7266 IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16
7267 ? createLaneOp(Src0SubVec, Src1SubVec, Src2, SubVecVT)
7268 : createLaneOp(Src0SubVec, Src1, Src2SubVec, SubVecVT));
7269 EltIdx += SubVecNumElt;
7283 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16)
7286 if (IID == Intrinsic::amdgcn_writelane)
7289 SDValue LaneOp = createLaneOp(Src0, Src1, Src2, VecVT);
7297 switch (
N->getOpcode()) {
7309 unsigned IID =
N->getConstantOperandVal(0);
7311 case Intrinsic::amdgcn_make_buffer_rsrc:
7312 Results.push_back(lowerPointerAsRsrcIntrin(
N, DAG));
7314 case Intrinsic::amdgcn_cvt_pkrtz: {
7320 Results.push_back(DAG.
getNode(ISD::BITCAST, SL, MVT::v2f16, Cvt));
7323 case Intrinsic::amdgcn_cvt_pknorm_i16:
7324 case Intrinsic::amdgcn_cvt_pknorm_u16:
7325 case Intrinsic::amdgcn_cvt_pk_i16:
7326 case Intrinsic::amdgcn_cvt_pk_u16: {
7332 if (IID == Intrinsic::amdgcn_cvt_pknorm_i16)
7334 else if (IID == Intrinsic::amdgcn_cvt_pknorm_u16)
7336 else if (IID == Intrinsic::amdgcn_cvt_pk_i16)
7341 EVT VT =
N->getValueType(0);
7346 Results.push_back(DAG.
getNode(ISD::BITCAST, SL, MVT::v2i16, Cvt));
7350 case Intrinsic::amdgcn_s_buffer_load: {
7356 if (!Subtarget->hasScalarSubwordLoads())
7362 EVT VT =
Op.getValueType();
7363 assert(VT == MVT::i8 &&
"Expected 8-bit s_buffer_load intrinsics.\n");
7375 if (!
Offset->isDivergent()) {
7394 LoadVal = handleByteShortBufferLoads(DAG, VT,
DL,
Ops, MMO);
7399 case Intrinsic::amdgcn_dead: {
7400 for (
unsigned I = 0, E =
N->getNumValues();
I < E; ++
I)
7411 for (
unsigned I = 0;
I < Res.getNumOperands();
I++) {
7412 Results.push_back(Res.getOperand(
I));
7416 Results.push_back(Res.getValue(1));
7425 EVT VT =
N->getValueType(0);
7430 EVT SelectVT = NewVT;
7431 if (NewVT.
bitsLT(MVT::i32)) {
7434 SelectVT = MVT::i32;
7440 if (NewVT != SelectVT)
7446 if (
N->getValueType(0) != MVT::v2f16)
7450 SDValue BC = DAG.
getNode(ISD::BITCAST, SL, MVT::i32,
N->getOperand(0));
7458 if (
N->getValueType(0) != MVT::v2f16)
7462 SDValue BC = DAG.
getNode(ISD::BITCAST, SL, MVT::i32,
N->getOperand(0));
7470 if (
N->getValueType(0) != MVT::f16)
7485 if (U.get() !=
Value)
7488 if (U.getUser()->getOpcode() == Opcode)
7494unsigned SITargetLowering::isCFIntrinsic(
const SDNode *Intr)
const {
7497 case Intrinsic::amdgcn_if:
7499 case Intrinsic::amdgcn_else:
7501 case Intrinsic::amdgcn_loop:
7503 case Intrinsic::amdgcn_end_cf:
7523 if (Subtarget->isAmdPalOS() || Subtarget->isMesa3DOS())
7550 SDNode *Intr = BRCOND.getOperand(1).getNode();
7563 assert(BR &&
"brcond missing unconditional branch user");
7567 unsigned CFNode = isCFIntrinsic(Intr);
7587 Ops.push_back(Target);
7610 for (
unsigned i = 1, e = Intr->
getNumValues() - 1; i != e; ++i) {
7629 MVT VT =
Op.getSimpleValueType();
7632 if (
Op.getConstantOperandVal(0) != 0)
7636 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
7638 if (
Info->isEntryFunction())
7655 return Op.getValueType().bitsLE(VT)
7663 EVT DstVT =
Op.getValueType();
7670 unsigned Opc =
Op.getOpcode();
7682 EVT SrcVT = Src.getValueType();
7683 EVT DstVT =
Op.getValueType();
7686 assert(Subtarget->hasCvtPkF16F32Inst() &&
"support v_cvt_pk_f16_f32");
7689 return SrcVT == MVT::v2f32 ?
Op : splitFP_ROUNDVectorOp(
Op, DAG);
7696 if (DstVT == MVT::f16) {
7701 if (!Subtarget->has16BitInsts()) {
7704 return DAG.
getNode(ISD::BITCAST,
DL, MVT::f16, Trunc);
7706 if (
Op->getFlags().hasApproximateFuncs()) {
7713 return DAG.
getNode(ISD::BITCAST,
DL, MVT::f16, Trunc);
7717 "custom lower FP_ROUND for f16 or bf16");
7718 assert(Subtarget->hasBF16ConversionInsts() &&
"f32 -> bf16 is legal");
7731 EVT VT =
Op.getValueType();
7733 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
7734 bool IsIEEEMode =
Info->getMode().IEEE;
7743 if (VT == MVT::v4f16 || VT == MVT::v8f16 || VT == MVT::v16f16 ||
7750SITargetLowering::lowerFMINIMUMNUM_FMAXIMUMNUM(
SDValue Op,
7752 EVT VT =
Op.getValueType();
7754 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
7755 bool IsIEEEMode =
Info->getMode().IEEE;
7760 if (VT == MVT::v4f16 || VT == MVT::v8f16 || VT == MVT::v16f16 ||
7768 EVT VT =
Op.getValueType();
7772 assert(!Subtarget->hasIEEEMinimumMaximumInsts() &&
7773 !Subtarget->hasMinimum3Maximum3F16() &&
7774 Subtarget->hasMinimum3Maximum3PKF16() && VT == MVT::f16 &&
7775 "should not need to widen f16 minimum/maximum to v2f16");
7789 DAG.
getNode(
Op.getOpcode(), SL, MVT::v2f16, WideSrc0, WideSrc1);
7797 EVT VT =
Op.getValueType();
7801 EVT ExpVT =
Exp.getValueType();
7802 if (ExpVT == MVT::i16)
7823 {
Op.getOperand(0),
Op.getOperand(1), TruncExp});
7826 return DAG.
getNode(ISD::FLDEXP,
DL, VT,
Op.getOperand(0), TruncExp);
7830 switch (
Op->getOpcode()) {
7860 DAGCombinerInfo &DCI)
const {
7861 const unsigned Opc =
Op.getOpcode();
7869 :
Op->getOperand(0).getValueType();
7872 if (DCI.isBeforeLegalizeOps() ||
7876 auto &DAG = DCI.DAG;
7882 LHS =
Op->getOperand(1);
7883 RHS =
Op->getOperand(2);
7885 LHS =
Op->getOperand(0);
7886 RHS =
Op->getOperand(1);
7925 if (MagVT == SignVT)
7932 SDValue SignAsInt32 = DAG.
getNode(ISD::BITCAST, SL, MVT::v2i32, Sign);
7935 SDValue SignAsHalf16 = DAG.
getNode(ISD::BITCAST, SL, MagVT, SignAsInt16);
7942 EVT VT =
Op.getValueType();
7948 assert(VT == MVT::i64 &&
"The following code is a special for s_mul_u64");
7975 if (
Op->isDivergent())
7988 if (Op0LeadingZeros >= 32 && Op1LeadingZeros >= 32)
7990 DAG.
getMachineNode(AMDGPU::S_MUL_U64_U32_PSEUDO, SL, VT, Op0, Op1), 0);
7993 if (Op0SignBits >= 33 && Op1SignBits >= 33)
7995 DAG.
getMachineNode(AMDGPU::S_MUL_I64_I32_PSEUDO, SL, VT, Op0, Op1), 0);
8001 EVT VT =
Op.getValueType();
8008 const APInt &
C = RHSC->getAPIntValue();
8010 if (
C.isPowerOf2()) {
8012 bool UseArithShift =
isSigned && !
C.isMinSignedValue();
8039 if (
Op->isDivergent()) {
8043 if (Subtarget->hasSMulHi()) {
8054 if (!Subtarget->isTrapHandlerEnabled() ||
8056 return lowerTrapEndpgm(
Op, DAG);
8058 return Subtarget->supportsGetDoorbellID() ? lowerTrapHsa(
Op, DAG)
8059 : lowerTrapHsaQueuePtr(
Op, DAG);
8069SITargetLowering::loadImplicitKernelArgument(
SelectionDAG &DAG,
MVT VT,
8071 ImplicitParameter Param)
const {
8091 loadImplicitKernelArgument(DAG, MVT::i64, SL,
Align(8),
QUEUE_PTR);
8094 SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8097 if (UserSGPR == AMDGPU::NoRegister) {
8123 if (Subtarget->hasPrivEnabledTrap2NopBug())
8136 if (!Subtarget->isTrapHandlerEnabled() ||
8140 "debugtrap handler not supported",
8151SDValue SITargetLowering::getSegmentAperture(
unsigned AS,
const SDLoc &
DL,
8153 if (Subtarget->hasApertureRegs()) {
8155 ? AMDGPU::SRC_SHARED_BASE
8156 : AMDGPU::SRC_PRIVATE_BASE;
8157 assert((ApertureRegNo != AMDGPU::SRC_PRIVATE_BASE ||
8158 !Subtarget->hasGloballyAddressableScratch()) &&
8159 "Cannot use src_private_base with globally addressable scratch!");
8180 return loadImplicitKernelArgument(DAG, MVT::i32,
DL,
Align(4), Param);
8184 SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8186 if (UserSGPR == AMDGPU::NoRegister) {
8220 return ConstVal->getSExtValue() != TM.getNullPointerValue(AddrSpace);
8231 const AMDGPUTargetMachine &TM =
8234 unsigned DestAS, SrcAS;
8236 bool IsNonNull =
false;
8238 SrcAS = ASC->getSrcAddressSpace();
8239 Src = ASC->getOperand(0);
8240 DestAS = ASC->getDestAddressSpace();
8243 Op.getConstantOperandVal(0) ==
8244 Intrinsic::amdgcn_addrspacecast_nonnull);
8245 Src =
Op->getOperand(1);
8246 SrcAS =
Op->getConstantOperandVal(2);
8247 DestAS =
Op->getConstantOperandVal(3);
8260 Subtarget->hasGloballyAddressableScratch()) {
8265 AMDGPU::S_MOV_B32, SL, MVT::i32,
8266 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE_LO, MVT::i32)),
8274 unsigned NullVal = TM.getNullPointerValue(DestAS);
8289 Subtarget->hasGloballyAddressableScratch()) {
8298 if (Subtarget->isWave64())
8304 57 - 32 - Subtarget->getWavefrontSizeLog2(), MVT::i32, SL);
8307 CvtPtr = DAG.
getNode(ISD::BITCAST, SL, MVT::i64, CvtPtr);
8312 AMDGPU::S_MOV_B64, SL, MVT::i64,
8313 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE, MVT::i64)),
8315 CvtPtr = DAG.
getNode(
ISD::ADD, SL, MVT::i64, CvtPtr, FlatScratchBase);
8317 SDValue Aperture = getSegmentAperture(SrcAS, SL, DAG);
8319 CvtPtr = DAG.
getNode(ISD::BITCAST, SL, MVT::i64, CvtPtr);
8325 unsigned NullVal = TM.getNullPointerValue(SrcAS);
8337 Op.getValueType() == MVT::i64) {
8338 const SIMachineFunctionInfo *
Info =
8342 return DAG.
getNode(ISD::BITCAST, SL, MVT::i64, Vec);
8346 Src.getValueType() == MVT::i64)
8366 EVT InsVT =
Ins.getValueType();
8374 assert(InsNumElts % 2 == 0 &&
"expect legal vector types");
8379 EVT NewInsVT = InsNumElts == 2 ? MVT::i32
8381 MVT::i32, InsNumElts / 2);
8383 Vec = DAG.
getNode(ISD::BITCAST, SL, NewVecVT, Vec);
8384 Ins = DAG.
getNode(ISD::BITCAST, SL, NewInsVT, Ins);
8386 for (
unsigned I = 0;
I != InsNumElts / 2; ++
I) {
8388 if (InsNumElts == 2) {
8398 return DAG.
getNode(ISD::BITCAST, SL, VecVT, Vec);
8401 for (
unsigned I = 0;
I != InsNumElts; ++
I) {
8424 if (NumElts == 4 && EltSize == 16 && KIdx) {
8432 SDValue LoVec = DAG.
getNode(ISD::BITCAST, SL, MVT::v2i16, LoHalf);
8433 SDValue HiVec = DAG.
getNode(ISD::BITCAST, SL, MVT::v2i16, HiHalf);
8435 unsigned Idx = KIdx->getZExtValue();
8436 bool InsertLo = Idx < 2;
8439 DAG.
getNode(ISD::BITCAST, SL, MVT::i16, InsVal),
8440 DAG.
getConstant(InsertLo ? Idx : (Idx - 2), SL, MVT::i32));
8442 InsHalf = DAG.
getNode(ISD::BITCAST, SL, MVT::i32, InsHalf);
8446 : DAG.getBuildVector(MVT::v2i32, SL, {LoHalf, InsHalf});
8459 assert(VecSize <= 64 &&
"Expected target vector size to be <= 64 bits");
8487 return DAG.
getNode(ISD::BITCAST, SL, VecVT, BFI);
8494 EVT ResultVT =
Op.getValueType();
8507 if (
SDValue Combined = performExtractVectorEltCombine(
Op.getNode(), DCI))
8510 if (VecSize == 128 || VecSize == 256 || VecSize == 512) {
8514 if (VecSize == 128) {
8522 }
else if (VecSize == 256) {
8525 for (
unsigned P = 0;
P < 4; ++
P) {
8531 Parts[0], Parts[1]));
8533 Parts[2], Parts[3]));
8539 for (
unsigned P = 0;
P < 8; ++
P) {
8546 Parts[0], Parts[1], Parts[2], Parts[3]));
8549 Parts[4], Parts[5], Parts[6], Parts[7]));
8569 Src = DAG.
getBitcast(Src.getValueType().changeTypeToInteger(), Src);
8584 if (ResultVT == MVT::f16 || ResultVT == MVT::bf16) {
8586 return DAG.
getNode(ISD::BITCAST, SL, ResultVT, Result);
8594 return Mask[Elt + 1] == Mask[Elt] + 1 && (Mask[Elt] % 2 == 0);
8599 return Mask[Elt] >= 0 && Mask[Elt + 1] >= 0 && (Mask[Elt] & 1) &&
8600 !(Mask[Elt + 1] & 1);
8606 EVT ResultVT =
Op.getValueType();
8609 const int NewSrcNumElts = 2;
8611 int SrcNumElts =
Op.getOperand(0).getValueType().getVectorNumElements();
8627 const bool ShouldUseConsecutiveExtract = EltVT.
getSizeInBits() == 16;
8649 if (ShouldUseConsecutiveExtract &&
8652 int VecIdx = Idx < SrcNumElts ? 0 : 1;
8653 int EltIdx = Idx < SrcNumElts ? Idx : Idx - SrcNumElts;
8665 if (Idx0 >= SrcNumElts) {
8670 if (Idx1 >= SrcNumElts) {
8675 int AlignedIdx0 = Idx0 & ~(NewSrcNumElts - 1);
8676 int AlignedIdx1 = Idx1 & ~(NewSrcNumElts - 1);
8684 int NewMaskIdx0 = Idx0 - AlignedIdx0;
8685 int NewMaskIdx1 = Idx1 - AlignedIdx1;
8690 if (SubVec0 != SubVec1) {
8691 NewMaskIdx1 += NewSrcNumElts;
8698 {NewMaskIdx0, NewMaskIdx1});
8703 int VecIdx0 = Idx0 < SrcNumElts ? 0 : 1;
8704 int VecIdx1 = Idx1 < SrcNumElts ? 0 : 1;
8705 int EltIdx0 = Idx0 < SrcNumElts ? Idx0 : Idx0 - SrcNumElts;
8706 int EltIdx1 = Idx1 < SrcNumElts ? Idx1 : Idx1 - SrcNumElts;
8725 EVT ResultVT =
Op.getValueType();
8741 EVT VT =
Op.getValueType();
8743 if (VT == MVT::v2f16 || VT == MVT::v2i16 || VT == MVT::v2bf16) {
8744 assert(!Subtarget->hasVOP3PInsts() &&
"this should be legal");
8753 return DAG.
getNode(ISD::BITCAST, SL, VT, ExtLo);
8762 return DAG.
getNode(ISD::BITCAST, SL, VT, ShlHi);
8769 return DAG.
getNode(ISD::BITCAST, SL, VT,
Or);
8778 for (
unsigned P = 0;
P < NumParts; ++
P) {
8780 PartVT, SL, {
Op.getOperand(
P * 2),
Op.getOperand(
P * 2 + 1)});
8786 return DAG.
getNode(ISD::BITCAST, SL, VT, Blend);
8799 if (!Subtarget->isAmdHsaOS())
8859 EVT PtrVT =
Op.getValueType();
8861 const GlobalValue *GV = GSD->
getGlobal();
8875 assert(PtrVT == MVT::i32 &&
"32-bit pointer is expected.");
8893 if (Subtarget->isAmdPalOS() || Subtarget->isMesa3DOS()) {
8894 if (Subtarget->has64BitLiterals()) {
8925 MachinePointerInfo PtrInfo =
8953 SDValue Param = lowerKernargMemParameter(
8964 "non-hsa intrinsic with hsa target",
DL.getDebugLoc()));
8972 "intrinsic not supported on subtarget",
DL.getDebugLoc()));
8980 unsigned NumElts = Elts.
size();
8982 if (NumElts <= 12) {
8991 for (
unsigned i = 0; i < Elts.
size(); ++i) {
8997 for (
unsigned i = Elts.
size(); i < NumElts; ++i)
9007 EVT SrcVT = Src.getValueType();
9028 bool Unpacked,
bool IsD16,
int DMaskPop,
9029 int NumVDataDwords,
bool IsAtomicPacked16Bit,
9033 EVT ReqRetVT = ResultTypes[0];
9035 int NumDataDwords = ((IsD16 && !Unpacked) || IsAtomicPacked16Bit)
9036 ? (ReqRetNumElts + 1) / 2
9039 int MaskPopDwords = (!IsD16 || Unpacked) ? DMaskPop : (DMaskPop + 1) / 2;
9050 if (DMaskPop > 0 &&
Data.getValueType() != MaskPopVT) {
9061 if (DataDwordVT.
isVector() && !IsAtomicPacked16Bit)
9063 NumDataDwords - MaskPopDwords);
9068 EVT LegalReqRetVT = ReqRetVT;
9070 if (!
Data.getValueType().isInteger())
9072 Data.getValueType().changeTypeToInteger(),
Data);
9093 if (Result->getNumValues() == 1)
9100 SDValue *LWE,
bool &IsTexFail) {
9120 unsigned DimIdx,
unsigned EndIdx,
9121 unsigned NumGradients) {
9123 for (
unsigned I = DimIdx;
I < EndIdx;
I++) {
9131 if (((
I + 1) >= EndIdx) ||
9132 ((NumGradients / 2) % 2 == 1 && (
I == DimIdx + (NumGradients / 2) - 1 ||
9133 I == DimIdx + NumGradients - 1))) {
9152 const AMDGPU::MIMGBaseOpcodeInfo *BaseOpcode =
9166 int NumVDataDwords = 0;
9167 bool AdjustRetType =
false;
9168 bool IsAtomicPacked16Bit =
false;
9171 const unsigned ArgOffset = WithChain ? 2 : 1;
9174 unsigned DMaskLanes = 0;
9176 if (BaseOpcode->Atomic) {
9177 VData =
Op.getOperand(2);
9179 IsAtomicPacked16Bit =
9180 (Intr->
BaseOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_F16 ||
9181 Intr->
BaseOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_BF16);
9184 if (BaseOpcode->AtomicX2) {
9191 ResultTypes[0] = Is64Bit ? MVT::v2i64 : MVT::v2i32;
9192 DMask = Is64Bit ? 0xf : 0x3;
9193 NumVDataDwords = Is64Bit ? 4 : 2;
9195 DMask = Is64Bit ? 0x3 : 0x1;
9196 NumVDataDwords = Is64Bit ? 2 : 1;
9199 DMask =
Op->getConstantOperandVal(ArgOffset + Intr->
DMaskIndex);
9202 if (BaseOpcode->Store) {
9203 VData =
Op.getOperand(2);
9207 if (!Subtarget->hasD16Images() || !BaseOpcode->HasD16)
9211 VData = handleD16VData(VData, DAG,
true);
9214 NumVDataDwords = (VData.
getValueType().getSizeInBits() + 31) / 32;
9215 }
else if (!BaseOpcode->NoReturn) {
9220 if (!Subtarget->hasD16Images() || !BaseOpcode->HasD16)
9228 (!LoadVT.
isVector() && DMaskLanes > 1))
9234 if (IsD16 && !Subtarget->hasUnpackedD16VMem() &&
9235 !(BaseOpcode->Gather4 && Subtarget->hasImageGather4D16Bug()))
9236 NumVDataDwords = (DMaskLanes + 1) / 2;
9238 NumVDataDwords = DMaskLanes;
9240 AdjustRetType =
true;
9244 unsigned VAddrEnd = ArgOffset + Intr->
VAddrEnd;
9251 MVT GradPackVectorVT = VAddrScalarVT == MVT::f16 ? MVT::v2f16 : MVT::v2i16;
9252 IsG16 = VAddrScalarVT == MVT::f16 || VAddrScalarVT == MVT::i16;
9254 VAddrVT =
Op.getOperand(ArgOffset + Intr->
CoordStart).getSimpleValueType();
9256 MVT AddrPackVectorVT = VAddrScalarVT == MVT::f16 ? MVT::v2f16 : MVT::v2i16;
9257 IsA16 = VAddrScalarVT == MVT::f16 || VAddrScalarVT == MVT::i16;
9261 if (IsA16 && (
Op.getOperand(ArgOffset +
I).getValueType() == MVT::f16)) {
9267 {
Op.getOperand(ArgOffset +
I), DAG.
getPOISON(MVT::f16)});
9271 "Bias needs to be converted to 16 bit in A16 mode");
9276 if (BaseOpcode->Gradients && !
ST->hasG16() && (IsA16 != IsG16)) {
9280 dbgs() <<
"Failed to lower image intrinsic: 16 bit addresses "
9281 "require 16 bit args for both gradients and addresses");
9286 if (!
ST->hasA16()) {
9287 LLVM_DEBUG(
dbgs() <<
"Failed to lower image intrinsic: Target does not "
9288 "support 16 bit addresses\n");
9298 if (BaseOpcode->Gradients && IsG16 &&
ST->hasG16()) {
9300 const AMDGPU::MIMGG16MappingInfo *G16MappingInfo =
9302 IntrOpcode = G16MappingInfo->
G16;
9325 for (
unsigned I = ArgOffset + Intr->
CoordStart;
I < VAddrEnd;
I++)
9343 const unsigned NSAMaxSize =
ST->getNSAMaxSize(BaseOpcode->Sampler);
9344 const bool HasPartialNSAEncoding =
ST->hasPartialNSAEncoding();
9345 const bool UseNSA =
ST->hasNSAEncoding() &&
9346 VAddrs.
size() >=
ST->getNSAThreshold(MF) &&
9347 (VAddrs.
size() <= NSAMaxSize || HasPartialNSAEncoding);
9348 const bool UsePartialNSA =
9349 UseNSA && HasPartialNSAEncoding && VAddrs.
size() > NSAMaxSize;
9352 if (UsePartialNSA) {
9354 ArrayRef(VAddrs).drop_front(NSAMaxSize - 1));
9355 }
else if (!UseNSA) {
9362 if (!BaseOpcode->Sampler) {
9365 uint64_t UnormConst =
9366 Op.getConstantOperandVal(ArgOffset + Intr->
UnormIndex);
9368 Unorm = UnormConst ? True : False;
9374 bool IsTexFail =
false;
9375 if (!
parseTexFail(TexFail, DAG, &TFE, &LWE, IsTexFail))
9386 NumVDataDwords += 1;
9387 AdjustRetType =
true;
9392 if (AdjustRetType) {
9395 if (DMaskLanes == 0 && !BaseOpcode->Store) {
9404 MVT::i32, NumVDataDwords)
9407 ResultTypes[0] = NewVT;
9408 if (ResultTypes.size() == 3) {
9412 ResultTypes.erase(&ResultTypes[1]);
9417 if (BaseOpcode->Atomic)
9424 if (BaseOpcode->Store || BaseOpcode->Atomic)
9425 Ops.push_back(VData);
9426 if (UsePartialNSA) {
9428 Ops.push_back(VAddr);
9432 Ops.push_back(VAddr);
9435 if (RsrcVT != MVT::v4i32 && RsrcVT != MVT::v8i32)
9437 Ops.push_back(Rsrc);
9438 if (BaseOpcode->Sampler) {
9442 Ops.push_back(Samp);
9447 if (!IsGFX12Plus || BaseOpcode->Sampler || BaseOpcode->MSAA)
9448 Ops.push_back(Unorm);
9450 Ops.push_back(IsA16 &&
9451 ST->hasFeature(AMDGPU::FeatureR128A16)
9455 Ops.push_back(IsA16 ? True : False);
9457 if (!Subtarget->hasGFX90AInsts())
9462 "TFE is not supported on this GPU",
DL.getDebugLoc()));
9465 if (!IsGFX12Plus || BaseOpcode->Sampler || BaseOpcode->MSAA)
9468 Ops.push_back(DimInfo->
DA ? True : False);
9469 if (BaseOpcode->HasD16)
9470 Ops.push_back(IsD16 ? True : False);
9472 Ops.push_back(
Op.getOperand(0));
9474 int NumVAddrDwords =
9480 NumVDataDwords, NumVAddrDwords);
9481 }
else if (IsGFX11Plus) {
9483 UseNSA ? AMDGPU::MIMGEncGfx11NSA
9484 : AMDGPU::MIMGEncGfx11Default,
9485 NumVDataDwords, NumVAddrDwords);
9486 }
else if (IsGFX10Plus) {
9488 UseNSA ? AMDGPU::MIMGEncGfx10NSA
9489 : AMDGPU::MIMGEncGfx10Default,
9490 NumVDataDwords, NumVAddrDwords);
9492 if (Subtarget->hasGFX90AInsts()) {
9494 NumVDataDwords, NumVAddrDwords);
9498 "requested image instruction is not supported on this GPU",
9503 for (EVT VT : OrigResultTypes) {
9504 if (VT == MVT::Other)
9505 RetValues[Idx++] =
Op.getOperand(0);
9516 NumVDataDwords, NumVAddrDwords);
9519 NumVDataDwords, NumVAddrDwords);
9526 MachineMemOperand *MemRef = MemOp->getMemOperand();
9530 if (BaseOpcode->AtomicX2) {
9535 if (BaseOpcode->NoReturn)
9538 Subtarget->hasUnpackedD16VMem(), IsD16, DMaskLanes,
9539 NumVDataDwords, IsAtomicPacked16Bit,
DL);
9552 MachinePointerInfo(),
9557 if (!
Offset->isDivergent()) {
9564 if (VT == MVT::i16 && Subtarget->hasScalarSubwordLoads()) {
9573 !Subtarget->hasScalarDwordx3Loads()) {
9600 if (VT == MVT::i16 && Subtarget->hasScalarSubwordLoads()) {
9602 return handleByteShortBufferLoads(DAG, VT,
DL,
Ops, MMO);
9606 unsigned NumLoads = 1;
9612 if (NumElts == 8 || NumElts == 16) {
9613 NumLoads = NumElts / 4;
9617 SDVTList VTList = DAG.
getVTList({LoadVT, MVT::Other});
9622 NumLoads > 1 ?
Align(16 * NumLoads) :
Align(4));
9624 uint64_t InstOffset =
Ops[5]->getAsZExtVal();
9625 for (
unsigned i = 0; i < NumLoads; ++i) {
9631 if (NumElts == 8 || NumElts == 16)
9639 if (!Subtarget->hasArchitectedSGPRs())
9651 unsigned Width)
const {
9653 using namespace AMDGPU::Hwreg;
9655 AMDGPU::S_GETREG_B32_const, SL, MVT::i32,
9694 auto *MFI = MF.
getInfo<SIMachineFunctionInfo>();
9696 EVT VT =
Op.getValueType();
9698 unsigned IntrinsicID =
Op.getConstantOperandVal(0);
9702 switch (IntrinsicID) {
9703 case Intrinsic::amdgcn_implicit_buffer_ptr: {
9706 return getPreloadedValue(DAG, *MFI, VT,
9709 case Intrinsic::amdgcn_dispatch_ptr:
9710 case Intrinsic::amdgcn_queue_ptr: {
9711 if (!Subtarget->isAmdHsaOrMesa(MF.
getFunction())) {
9713 MF.
getFunction(),
"unsupported hsa intrinsic without hsa target",
9718 auto RegID = IntrinsicID == Intrinsic::amdgcn_dispatch_ptr
9721 return getPreloadedValue(DAG, *MFI, VT, RegID);
9723 case Intrinsic::amdgcn_implicitarg_ptr: {
9725 return getImplicitArgPtr(DAG,
DL);
9726 return getPreloadedValue(DAG, *MFI, VT,
9729 case Intrinsic::amdgcn_kernarg_segment_ptr: {
9735 return getPreloadedValue(DAG, *MFI, VT,
9738 case Intrinsic::amdgcn_dispatch_id: {
9741 case Intrinsic::amdgcn_rcp:
9743 case Intrinsic::amdgcn_rsq:
9745 case Intrinsic::amdgcn_rsq_legacy:
9749 case Intrinsic::amdgcn_rcp_legacy:
9753 case Intrinsic::amdgcn_rsq_clamp: {
9764 return DAG.
getNode(ISD::FMAXNUM,
DL, VT, Tmp,
9767 case Intrinsic::r600_read_ngroups_x:
9768 if (Subtarget->isAmdHsaOS())
9771 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
9774 case Intrinsic::r600_read_ngroups_y:
9775 if (Subtarget->isAmdHsaOS())
9778 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
9781 case Intrinsic::r600_read_ngroups_z:
9782 if (Subtarget->isAmdHsaOS())
9785 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
9788 case Intrinsic::r600_read_local_size_x:
9789 if (Subtarget->isAmdHsaOS())
9792 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
9794 case Intrinsic::r600_read_local_size_y:
9795 if (Subtarget->isAmdHsaOS())
9798 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
9800 case Intrinsic::r600_read_local_size_z:
9801 if (Subtarget->isAmdHsaOS())
9804 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
9806 case Intrinsic::amdgcn_workgroup_id_x:
9807 return lowerWorkGroupId(DAG, *MFI, VT,
9811 case Intrinsic::amdgcn_workgroup_id_y:
9812 return lowerWorkGroupId(DAG, *MFI, VT,
9816 case Intrinsic::amdgcn_workgroup_id_z:
9817 return lowerWorkGroupId(DAG, *MFI, VT,
9821 case Intrinsic::amdgcn_cluster_id_x:
9822 return Subtarget->hasClusters()
9823 ? getPreloadedValue(DAG, *MFI, VT,
9825 : DAG.getPOISON(VT);
9826 case Intrinsic::amdgcn_cluster_id_y:
9827 return Subtarget->hasClusters()
9828 ? getPreloadedValue(DAG, *MFI, VT,
9831 case Intrinsic::amdgcn_cluster_id_z:
9832 return Subtarget->hasClusters()
9833 ? getPreloadedValue(DAG, *MFI, VT,
9836 case Intrinsic::amdgcn_cluster_workgroup_id_x:
9837 return Subtarget->hasClusters()
9838 ? getPreloadedValue(
9842 case Intrinsic::amdgcn_cluster_workgroup_id_y:
9843 return Subtarget->hasClusters()
9844 ? getPreloadedValue(
9848 case Intrinsic::amdgcn_cluster_workgroup_id_z:
9849 return Subtarget->hasClusters()
9850 ? getPreloadedValue(
9854 case Intrinsic::amdgcn_cluster_workgroup_flat_id:
9855 return Subtarget->hasClusters()
9858 case Intrinsic::amdgcn_cluster_workgroup_max_id_x:
9859 return Subtarget->hasClusters()
9860 ? getPreloadedValue(
9864 case Intrinsic::amdgcn_cluster_workgroup_max_id_y:
9865 return Subtarget->hasClusters()
9866 ? getPreloadedValue(
9870 case Intrinsic::amdgcn_cluster_workgroup_max_id_z:
9871 return Subtarget->hasClusters()
9872 ? getPreloadedValue(
9876 case Intrinsic::amdgcn_cluster_workgroup_max_flat_id:
9877 return Subtarget->hasClusters()
9878 ? getPreloadedValue(
9882 case Intrinsic::amdgcn_wave_id:
9883 return lowerWaveID(DAG,
Op);
9884 case Intrinsic::amdgcn_lds_kernel_id: {
9886 return getLDSKernelId(DAG,
DL);
9887 return getPreloadedValue(DAG, *MFI, VT,
9890 case Intrinsic::amdgcn_workitem_id_x:
9891 return lowerWorkitemID(DAG,
Op, 0, MFI->getArgInfo().WorkItemIDX);
9892 case Intrinsic::amdgcn_workitem_id_y:
9893 return lowerWorkitemID(DAG,
Op, 1, MFI->getArgInfo().WorkItemIDY);
9894 case Intrinsic::amdgcn_workitem_id_z:
9895 return lowerWorkitemID(DAG,
Op, 2, MFI->getArgInfo().WorkItemIDZ);
9896 case Intrinsic::amdgcn_wavefrontsize:
9898 SDLoc(
Op), MVT::i32);
9899 case Intrinsic::amdgcn_s_buffer_load: {
9900 unsigned CPol =
Op.getConstantOperandVal(3);
9907 return lowerSBuffer(VT,
DL,
Op.getOperand(1),
Op.getOperand(2),
9908 Op.getOperand(3), DAG);
9910 case Intrinsic::amdgcn_fdiv_fast:
9911 return lowerFDIV_FAST(
Op, DAG);
9912 case Intrinsic::amdgcn_sin:
9915 case Intrinsic::amdgcn_cos:
9918 case Intrinsic::amdgcn_mul_u24:
9921 case Intrinsic::amdgcn_mul_i24:
9925 case Intrinsic::amdgcn_log_clamp: {
9931 case Intrinsic::amdgcn_fract:
9934 case Intrinsic::amdgcn_class:
9937 case Intrinsic::amdgcn_div_fmas:
9939 Op.getOperand(2),
Op.getOperand(3),
Op.getOperand(4));
9941 case Intrinsic::amdgcn_div_fixup:
9943 Op.getOperand(2),
Op.getOperand(3));
9945 case Intrinsic::amdgcn_div_scale: {
9958 SDValue Src0 =
Param->isAllOnes() ? Numerator : Denominator;
9961 Denominator, Numerator);
9963 case Intrinsic::amdgcn_icmp: {
9965 if (
Op.getOperand(1).getValueType() == MVT::i1 &&
9966 Op.getConstantOperandVal(2) == 0 &&
9971 case Intrinsic::amdgcn_fcmp: {
9974 case Intrinsic::amdgcn_ballot:
9976 case Intrinsic::amdgcn_fmed3:
9978 Op.getOperand(2),
Op.getOperand(3));
9979 case Intrinsic::amdgcn_fdot2:
9981 Op.getOperand(2),
Op.getOperand(3),
Op.getOperand(4));
9982 case Intrinsic::amdgcn_fmul_legacy:
9985 case Intrinsic::amdgcn_sffbh:
9987 case Intrinsic::amdgcn_sbfe:
9989 Op.getOperand(2),
Op.getOperand(3));
9990 case Intrinsic::amdgcn_ubfe:
9992 Op.getOperand(2),
Op.getOperand(3));
9993 case Intrinsic::amdgcn_cvt_pkrtz:
9994 case Intrinsic::amdgcn_cvt_pknorm_i16:
9995 case Intrinsic::amdgcn_cvt_pknorm_u16:
9996 case Intrinsic::amdgcn_cvt_pk_i16:
9997 case Intrinsic::amdgcn_cvt_pk_u16: {
9999 EVT VT =
Op.getValueType();
10002 if (IntrinsicID == Intrinsic::amdgcn_cvt_pkrtz)
10004 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pknorm_i16)
10006 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pknorm_u16)
10008 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pk_i16)
10014 return DAG.
getNode(Opcode,
DL, VT,
Op.getOperand(1),
Op.getOperand(2));
10017 DAG.
getNode(Opcode,
DL, MVT::i32,
Op.getOperand(1),
Op.getOperand(2));
10018 return DAG.
getNode(ISD::BITCAST,
DL, VT, Node);
10020 case Intrinsic::amdgcn_fmad_ftz:
10022 Op.getOperand(2),
Op.getOperand(3));
10024 case Intrinsic::amdgcn_if_break:
10026 Op->getOperand(1),
Op->getOperand(2)),
10029 case Intrinsic::amdgcn_groupstaticsize: {
10035 const GlobalValue *GV =
10041 case Intrinsic::amdgcn_is_shared:
10042 case Intrinsic::amdgcn_is_private: {
10045 DAG.
getNode(ISD::BITCAST,
DL, MVT::v2i32,
Op.getOperand(1));
10049 unsigned AS = (IntrinsicID == Intrinsic::amdgcn_is_shared)
10053 Subtarget->hasGloballyAddressableScratch()) {
10056 AMDGPU::S_MOV_B32,
DL, MVT::i32,
10057 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE_HI, MVT::i32)),
10066 SDValue Aperture = getSegmentAperture(AS, SL, DAG);
10069 case Intrinsic::amdgcn_perm:
10071 Op.getOperand(2),
Op.getOperand(3));
10072 case Intrinsic::amdgcn_reloc_constant: {
10082 case Intrinsic::amdgcn_swmmac_f16_16x16x32_f16:
10083 case Intrinsic::amdgcn_swmmac_bf16_16x16x32_bf16:
10084 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf16:
10085 case Intrinsic::amdgcn_swmmac_f32_16x16x32_f16:
10086 case Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_fp8:
10087 case Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_bf8:
10088 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_fp8:
10089 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_bf8: {
10090 if (
Op.getOperand(4).getValueType() == MVT::i32)
10096 Op.getOperand(0),
Op.getOperand(1),
Op.getOperand(2),
10097 Op.getOperand(3), IndexKeyi32);
10099 case Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_fp8:
10100 case Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_bf8:
10101 case Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_fp8:
10102 case Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_bf8:
10103 case Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_fp8:
10104 case Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_bf8:
10105 case Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_fp8:
10106 case Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_bf8: {
10107 if (
Op.getOperand(4).getValueType() == MVT::i64)
10113 {Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
10114 Op.getOperand(3), IndexKeyi64, Op.getOperand(5),
10115 Op.getOperand(6)});
10117 case Intrinsic::amdgcn_swmmac_f16_16x16x64_f16:
10118 case Intrinsic::amdgcn_swmmac_bf16_16x16x64_bf16:
10119 case Intrinsic::amdgcn_swmmac_f32_16x16x64_bf16:
10120 case Intrinsic::amdgcn_swmmac_bf16f32_16x16x64_bf16:
10121 case Intrinsic::amdgcn_swmmac_f32_16x16x64_f16:
10122 case Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8: {
10123 EVT IndexKeyTy = IntrinsicID == Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8
10126 if (
Op.getOperand(6).getValueType() == IndexKeyTy)
10132 {Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
10133 Op.getOperand(3), Op.getOperand(4), Op.getOperand(5),
10134 IndexKey, Op.getOperand(7),
10135 Op.getOperand(8)});
10137 case Intrinsic::amdgcn_swmmac_i32_16x16x32_iu4:
10138 case Intrinsic::amdgcn_swmmac_i32_16x16x32_iu8:
10139 case Intrinsic::amdgcn_swmmac_i32_16x16x64_iu4: {
10140 if (
Op.getOperand(6).getValueType() == MVT::i32)
10146 {Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
10147 Op.getOperand(3), Op.getOperand(4), Op.getOperand(5),
10148 IndexKeyi32, Op.getOperand(7)});
10150 case Intrinsic::amdgcn_addrspacecast_nonnull:
10151 return lowerADDRSPACECAST(
Op, DAG);
10152 case Intrinsic::amdgcn_readlane:
10153 case Intrinsic::amdgcn_readfirstlane:
10154 case Intrinsic::amdgcn_writelane:
10155 case Intrinsic::amdgcn_permlane16:
10156 case Intrinsic::amdgcn_permlanex16:
10157 case Intrinsic::amdgcn_permlane64:
10158 case Intrinsic::amdgcn_set_inactive:
10159 case Intrinsic::amdgcn_set_inactive_chain_arg:
10160 case Intrinsic::amdgcn_mov_dpp8:
10161 case Intrinsic::amdgcn_update_dpp:
10163 case Intrinsic::amdgcn_dead: {
10165 for (
const EVT ValTy :
Op.getNode()->values())
10170 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
10172 return lowerImage(
Op, ImageDimIntr, DAG,
false);
10183 return DAG.
getRegister(AMDGPU::SGPR_NULL, MVT::i32);
10189 unsigned NewOpcode)
const {
10193 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(3), DAG);
10194 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(4), DAG);
10212 M->getMemOperand());
10217 unsigned NewOpcode)
const {
10221 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(3), DAG);
10222 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(5), DAG);
10240 M->getMemOperand());
10245 unsigned IntrID =
Op.getConstantOperandVal(1);
10249 case Intrinsic::amdgcn_ds_ordered_add:
10250 case Intrinsic::amdgcn_ds_ordered_swap: {
10255 unsigned IndexOperand =
M->getConstantOperandVal(7);
10256 unsigned WaveRelease =
M->getConstantOperandVal(8);
10257 unsigned WaveDone =
M->getConstantOperandVal(9);
10259 unsigned OrderedCountIndex = IndexOperand & 0x3f;
10260 IndexOperand &= ~0x3f;
10261 unsigned CountDw = 0;
10264 CountDw = (IndexOperand >> 24) & 0xf;
10265 IndexOperand &= ~(0xf << 24);
10267 if (CountDw < 1 || CountDw > 4) {
10270 Fn,
"ds_ordered_count: dword count must be between 1 and 4",
10271 DL.getDebugLoc()));
10276 if (IndexOperand) {
10279 Fn,
"ds_ordered_count: bad index operand",
DL.getDebugLoc()));
10282 if (WaveDone && !WaveRelease) {
10286 Fn,
"ds_ordered_count: wave_done requires wave_release",
10287 DL.getDebugLoc()));
10290 unsigned Instruction = IntrID == Intrinsic::amdgcn_ds_ordered_add ? 0 : 1;
10291 unsigned ShaderType =
10293 unsigned Offset0 = OrderedCountIndex << 2;
10294 unsigned Offset1 = WaveRelease | (WaveDone << 1) | (Instruction << 4);
10297 Offset1 |= (CountDw - 1) << 6;
10300 Offset1 |= ShaderType << 2;
10302 unsigned Offset = Offset0 | (Offset1 << 8);
10309 M->getVTList(),
Ops,
M->getMemoryVT(),
10310 M->getMemOperand());
10312 case Intrinsic::amdgcn_raw_buffer_load:
10313 case Intrinsic::amdgcn_raw_ptr_buffer_load:
10314 case Intrinsic::amdgcn_raw_atomic_buffer_load:
10315 case Intrinsic::amdgcn_raw_ptr_atomic_buffer_load:
10316 case Intrinsic::amdgcn_raw_buffer_load_format:
10317 case Intrinsic::amdgcn_raw_ptr_buffer_load_format: {
10318 const bool IsFormat =
10319 IntrID == Intrinsic::amdgcn_raw_buffer_load_format ||
10320 IntrID == Intrinsic::amdgcn_raw_ptr_buffer_load_format;
10322 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(2), DAG);
10323 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(3), DAG);
10337 return lowerIntrinsicLoad(M, IsFormat, DAG,
Ops);
10339 case Intrinsic::amdgcn_struct_buffer_load:
10340 case Intrinsic::amdgcn_struct_ptr_buffer_load:
10341 case Intrinsic::amdgcn_struct_buffer_load_format:
10342 case Intrinsic::amdgcn_struct_ptr_buffer_load_format:
10343 case Intrinsic::amdgcn_struct_atomic_buffer_load:
10344 case Intrinsic::amdgcn_struct_ptr_atomic_buffer_load: {
10345 const bool IsFormat =
10346 IntrID == Intrinsic::amdgcn_struct_buffer_load_format ||
10347 IntrID == Intrinsic::amdgcn_struct_ptr_buffer_load_format;
10349 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(2), DAG);
10350 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(4), DAG);
10365 case Intrinsic::amdgcn_raw_tbuffer_load:
10366 case Intrinsic::amdgcn_raw_ptr_tbuffer_load: {
10368 EVT LoadVT =
Op.getValueType();
10369 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(2), DAG);
10370 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(3), DAG);
10389 Op->getVTList(),
Ops, LoadVT,
M->getMemOperand(),
10392 case Intrinsic::amdgcn_struct_tbuffer_load:
10393 case Intrinsic::amdgcn_struct_ptr_tbuffer_load: {
10395 EVT LoadVT =
Op.getValueType();
10396 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(2), DAG);
10397 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(4), DAG);
10416 Op->getVTList(),
Ops, LoadVT,
M->getMemOperand(),
10419 case Intrinsic::amdgcn_raw_buffer_atomic_fadd:
10420 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fadd:
10422 case Intrinsic::amdgcn_struct_buffer_atomic_fadd:
10423 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fadd:
10424 return lowerStructBufferAtomicIntrin(
Op, DAG,
10426 case Intrinsic::amdgcn_raw_buffer_atomic_fmin:
10427 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fmin:
10429 case Intrinsic::amdgcn_struct_buffer_atomic_fmin:
10430 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fmin:
10431 return lowerStructBufferAtomicIntrin(
Op, DAG,
10433 case Intrinsic::amdgcn_raw_buffer_atomic_fmax:
10434 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fmax:
10436 case Intrinsic::amdgcn_struct_buffer_atomic_fmax:
10437 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fmax:
10438 return lowerStructBufferAtomicIntrin(
Op, DAG,
10440 case Intrinsic::amdgcn_raw_buffer_atomic_swap:
10441 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_swap:
10443 case Intrinsic::amdgcn_raw_buffer_atomic_add:
10444 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_add:
10446 case Intrinsic::amdgcn_raw_buffer_atomic_sub:
10447 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_sub:
10449 case Intrinsic::amdgcn_raw_buffer_atomic_smin:
10450 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smin:
10452 case Intrinsic::amdgcn_raw_buffer_atomic_umin:
10453 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umin:
10455 case Intrinsic::amdgcn_raw_buffer_atomic_smax:
10456 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smax:
10458 case Intrinsic::amdgcn_raw_buffer_atomic_umax:
10459 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umax:
10461 case Intrinsic::amdgcn_raw_buffer_atomic_and:
10462 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_and:
10464 case Intrinsic::amdgcn_raw_buffer_atomic_or:
10465 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_or:
10467 case Intrinsic::amdgcn_raw_buffer_atomic_xor:
10468 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_xor:
10470 case Intrinsic::amdgcn_raw_buffer_atomic_inc:
10471 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_inc:
10473 case Intrinsic::amdgcn_raw_buffer_atomic_dec:
10474 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_dec:
10476 case Intrinsic::amdgcn_raw_buffer_atomic_cond_sub_u32:
10477 return lowerRawBufferAtomicIntrin(
Op, DAG,
10479 case Intrinsic::amdgcn_struct_buffer_atomic_swap:
10480 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_swap:
10481 return lowerStructBufferAtomicIntrin(
Op, DAG,
10483 case Intrinsic::amdgcn_struct_buffer_atomic_add:
10484 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_add:
10486 case Intrinsic::amdgcn_struct_buffer_atomic_sub:
10487 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_sub:
10489 case Intrinsic::amdgcn_struct_buffer_atomic_smin:
10490 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smin:
10491 return lowerStructBufferAtomicIntrin(
Op, DAG,
10493 case Intrinsic::amdgcn_struct_buffer_atomic_umin:
10494 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umin:
10495 return lowerStructBufferAtomicIntrin(
Op, DAG,
10497 case Intrinsic::amdgcn_struct_buffer_atomic_smax:
10498 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smax:
10499 return lowerStructBufferAtomicIntrin(
Op, DAG,
10501 case Intrinsic::amdgcn_struct_buffer_atomic_umax:
10502 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umax:
10503 return lowerStructBufferAtomicIntrin(
Op, DAG,
10505 case Intrinsic::amdgcn_struct_buffer_atomic_and:
10506 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_and:
10508 case Intrinsic::amdgcn_struct_buffer_atomic_or:
10509 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_or:
10511 case Intrinsic::amdgcn_struct_buffer_atomic_xor:
10512 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_xor:
10514 case Intrinsic::amdgcn_struct_buffer_atomic_inc:
10515 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_inc:
10517 case Intrinsic::amdgcn_struct_buffer_atomic_dec:
10518 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_dec:
10520 case Intrinsic::amdgcn_struct_buffer_atomic_cond_sub_u32:
10521 return lowerStructBufferAtomicIntrin(
Op, DAG,
10524 case Intrinsic::amdgcn_raw_buffer_atomic_cmpswap:
10525 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_cmpswap: {
10526 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(4), DAG);
10527 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(5), DAG);
10541 EVT VT =
Op.getValueType();
10545 Op->getVTList(),
Ops, VT,
10546 M->getMemOperand());
10548 case Intrinsic::amdgcn_struct_buffer_atomic_cmpswap:
10549 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_cmpswap: {
10550 SDValue Rsrc = bufferRsrcPtrToVector(
Op->getOperand(4), DAG);
10551 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(6), DAG);
10565 EVT VT =
Op.getValueType();
10569 Op->getVTList(),
Ops, VT,
10570 M->getMemOperand());
10572 case Intrinsic::amdgcn_image_bvh_dual_intersect_ray:
10573 case Intrinsic::amdgcn_image_bvh8_intersect_ray: {
10575 SDValue NodePtr =
M->getOperand(2);
10576 SDValue RayExtent =
M->getOperand(3);
10577 SDValue InstanceMask =
M->getOperand(4);
10578 SDValue RayOrigin =
M->getOperand(5);
10579 SDValue RayDir =
M->getOperand(6);
10581 SDValue TDescr =
M->getOperand(8);
10586 if (!Subtarget->hasBVHDualAndBVH8Insts()) {
10591 bool IsBVH8 = IntrID == Intrinsic::amdgcn_image_bvh8_intersect_ray;
10592 const unsigned NumVDataDwords = 10;
10593 const unsigned NumVAddrDwords = IsBVH8 ? 11 : 12;
10595 IsBVH8 ? AMDGPU::IMAGE_BVH8_INTERSECT_RAY
10596 : AMDGPU::IMAGE_BVH_DUAL_INTERSECT_RAY,
10597 AMDGPU::MIMGEncGfx12, NumVDataDwords, NumVAddrDwords);
10601 Ops.push_back(NodePtr);
10604 {DAG.getBitcast(MVT::i32, RayExtent),
10605 DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, InstanceMask)}));
10606 Ops.push_back(RayOrigin);
10607 Ops.push_back(RayDir);
10608 Ops.push_back(Offsets);
10609 Ops.push_back(TDescr);
10610 Ops.push_back(
M->getChain());
10613 MachineMemOperand *MemRef =
M->getMemOperand();
10617 case Intrinsic::amdgcn_image_bvh_intersect_ray: {
10619 SDValue NodePtr =
M->getOperand(2);
10620 SDValue RayExtent =
M->getOperand(3);
10621 SDValue RayOrigin =
M->getOperand(4);
10622 SDValue RayDir =
M->getOperand(5);
10623 SDValue RayInvDir =
M->getOperand(6);
10624 SDValue TDescr =
M->getOperand(7);
10631 if (!Subtarget->hasGFX10_AEncoding()) {
10641 const unsigned NumVDataDwords = 4;
10642 const unsigned NumVAddrDwords = IsA16 ? (Is64 ? 9 : 8) : (Is64 ? 12 : 11);
10643 const unsigned NumVAddrs = IsGFX11Plus ? (IsA16 ? 4 : 5) : NumVAddrDwords;
10644 const bool UseNSA = (Subtarget->hasNSAEncoding() &&
10647 const unsigned BaseOpcodes[2][2] = {
10648 {AMDGPU::IMAGE_BVH_INTERSECT_RAY, AMDGPU::IMAGE_BVH_INTERSECT_RAY_a16},
10649 {AMDGPU::IMAGE_BVH64_INTERSECT_RAY,
10650 AMDGPU::IMAGE_BVH64_INTERSECT_RAY_a16}};
10654 IsGFX12Plus ? AMDGPU::MIMGEncGfx12
10655 : IsGFX11 ? AMDGPU::MIMGEncGfx11NSA
10656 : AMDGPU::MIMGEncGfx10NSA,
10657 NumVDataDwords, NumVAddrDwords);
10661 IsGFX11 ? AMDGPU::MIMGEncGfx11Default
10662 : AMDGPU::MIMGEncGfx10Default,
10663 NumVDataDwords, NumVAddrDwords);
10669 auto packLanes = [&DAG, &
Ops, &
DL](
SDValue Op,
bool IsAligned) {
10672 if (Lanes[0].getValueSizeInBits() == 32) {
10673 for (
unsigned I = 0;
I < 3; ++
I)
10680 Ops.push_back(Lanes[2]);
10692 if (UseNSA && IsGFX11Plus) {
10693 Ops.push_back(NodePtr);
10695 Ops.push_back(RayOrigin);
10700 for (
unsigned I = 0;
I < 3; ++
I) {
10703 {DirLanes[I], InvDirLanes[I]})));
10707 Ops.push_back(RayDir);
10708 Ops.push_back(RayInvDir);
10715 Ops.push_back(NodePtr);
10718 packLanes(RayOrigin,
true);
10719 packLanes(RayDir,
true);
10720 packLanes(RayInvDir,
false);
10725 if (NumVAddrDwords > 12) {
10727 Ops.append(16 -
Ops.size(), Undef);
10733 Ops.push_back(MergedOps);
10736 Ops.push_back(TDescr);
10738 Ops.push_back(
M->getChain());
10741 MachineMemOperand *MemRef =
M->getMemOperand();
10745 case Intrinsic::amdgcn_global_atomic_fmin_num:
10746 case Intrinsic::amdgcn_global_atomic_fmax_num:
10747 case Intrinsic::amdgcn_flat_atomic_fmin_num:
10748 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
10755 unsigned Opcode = 0;
10757 case Intrinsic::amdgcn_global_atomic_fmin_num:
10758 case Intrinsic::amdgcn_flat_atomic_fmin_num: {
10759 Opcode = ISD::ATOMIC_LOAD_FMIN;
10762 case Intrinsic::amdgcn_global_atomic_fmax_num:
10763 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
10764 Opcode = ISD::ATOMIC_LOAD_FMAX;
10770 return DAG.
getAtomic(Opcode, SDLoc(
Op),
M->getMemoryVT(),
M->getVTList(),
10771 Ops,
M->getMemOperand());
10773 case Intrinsic::amdgcn_s_get_barrier_state:
10774 case Intrinsic::amdgcn_s_get_named_barrier_state: {
10781 if (IntrID == Intrinsic::amdgcn_s_get_named_barrier_state)
10782 BarID = (BarID >> 4) & 0x3F;
10783 Opc = AMDGPU::S_GET_BARRIER_STATE_IMM;
10786 Ops.push_back(Chain);
10788 Opc = AMDGPU::S_GET_BARRIER_STATE_M0;
10789 if (IntrID == Intrinsic::amdgcn_s_get_named_barrier_state) {
10797 Ops.push_back(
copyToM0(DAG, Chain,
DL, M0Val).getValue(0));
10805 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
10806 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
10807 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B: {
10811 EVT VT =
Op->getValueType(0);
10817 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
10819 return lowerImage(
Op, ImageDimIntr, DAG,
true);
10827SDValue SITargetLowering::getMemIntrinsicNode(
unsigned Opcode,
const SDLoc &
DL,
10834 EVT VT = VTList.
VTs[0];
10837 bool IsTFE = VTList.
NumVTs == 3;
10840 unsigned NumOpDWords = NumValueDWords + 1;
10842 SDVTList OpDWordsVTList = DAG.
getVTList(OpDWordsVT, VTList.
VTs[2]);
10843 MachineMemOperand *OpDWordsMMO =
10845 SDValue Op = getMemIntrinsicNode(Opcode,
DL, OpDWordsVTList,
Ops,
10846 OpDWordsVT, OpDWordsMMO, DAG);
10851 NumValueDWords == 1
10860 if (!Subtarget->hasDwordx3LoadStores() &&
10861 (VT == MVT::v3i32 || VT == MVT::v3f32)) {
10865 SDVTList WidenedVTList = DAG.
getVTList(WidenedVT, VTList.
VTs[1]);
10867 WidenedMemVT, WidenedMMO);
10877 bool ImageStore)
const {
10887 if (Subtarget->hasUnpackedD16VMem()) {
10901 if (ImageStore && Subtarget->hasImageStoreD16Bug()) {
10912 for (
unsigned I = 0;
I < Elts.
size() / 2;
I += 1) {
10918 if ((NumElements % 2) == 1) {
10920 unsigned I = Elts.
size() / 2;
10936 if (NumElements == 3) {
10946 return DAG.
getNode(ISD::BITCAST,
DL, WidenedStoreVT, ZExt);
10957 unsigned IntrinsicID =
Op.getConstantOperandVal(1);
10960 switch (IntrinsicID) {
10961 case Intrinsic::amdgcn_exp_compr: {
10962 if (!Subtarget->hasCompressedExport()) {
10965 "intrinsic not supported on subtarget",
DL.getDebugLoc()));
10977 DAG.
getNode(ISD::BITCAST,
DL, MVT::f32, Src0),
10978 DAG.
getNode(ISD::BITCAST,
DL, MVT::f32, Src1),
10987 unsigned Opc =
Done->isZero() ? AMDGPU::EXP : AMDGPU::EXP_DONE;
10991 case Intrinsic::amdgcn_struct_tbuffer_store:
10992 case Intrinsic::amdgcn_struct_ptr_tbuffer_store: {
10994 bool IsD16 = (VData.
getValueType().getScalarType() == MVT::f16);
10996 VData = handleD16VData(VData, DAG);
10997 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(3), DAG);
10998 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(5), DAG);
11016 M->getMemoryVT(),
M->getMemOperand());
11019 case Intrinsic::amdgcn_raw_tbuffer_store:
11020 case Intrinsic::amdgcn_raw_ptr_tbuffer_store: {
11022 bool IsD16 = (VData.
getValueType().getScalarType() == MVT::f16);
11024 VData = handleD16VData(VData, DAG);
11025 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(3), DAG);
11026 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(4), DAG);
11044 M->getMemoryVT(),
M->getMemOperand());
11047 case Intrinsic::amdgcn_raw_buffer_store:
11048 case Intrinsic::amdgcn_raw_ptr_buffer_store:
11049 case Intrinsic::amdgcn_raw_buffer_store_format:
11050 case Intrinsic::amdgcn_raw_ptr_buffer_store_format: {
11051 const bool IsFormat =
11052 IntrinsicID == Intrinsic::amdgcn_raw_buffer_store_format ||
11053 IntrinsicID == Intrinsic::amdgcn_raw_ptr_buffer_store_format;
11060 VData = handleD16VData(VData, DAG);
11070 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(3), DAG);
11071 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(4), DAG);
11091 return handleByteShortBufferStores(DAG, VDataVT,
DL,
Ops, M);
11094 M->getMemoryVT(),
M->getMemOperand());
11097 case Intrinsic::amdgcn_struct_buffer_store:
11098 case Intrinsic::amdgcn_struct_ptr_buffer_store:
11099 case Intrinsic::amdgcn_struct_buffer_store_format:
11100 case Intrinsic::amdgcn_struct_ptr_buffer_store_format: {
11101 const bool IsFormat =
11102 IntrinsicID == Intrinsic::amdgcn_struct_buffer_store_format ||
11103 IntrinsicID == Intrinsic::amdgcn_struct_ptr_buffer_store_format;
11111 VData = handleD16VData(VData, DAG);
11121 auto Rsrc = bufferRsrcPtrToVector(
Op.getOperand(3), DAG);
11122 auto [VOffset,
Offset] = splitBufferOffsets(
Op.getOperand(5), DAG);
11141 EVT VDataType = VData.getValueType().getScalarType();
11143 return handleByteShortBufferStores(DAG, VDataType,
DL,
Ops, M);
11146 M->getMemoryVT(),
M->getMemOperand());
11148 case Intrinsic::amdgcn_raw_buffer_load_lds:
11149 case Intrinsic::amdgcn_raw_ptr_buffer_load_lds:
11150 case Intrinsic::amdgcn_struct_buffer_load_lds:
11151 case Intrinsic::amdgcn_struct_ptr_buffer_load_lds: {
11152 if (!Subtarget->hasVMemToLDSLoad())
11156 IntrinsicID == Intrinsic::amdgcn_struct_buffer_load_lds ||
11157 IntrinsicID == Intrinsic::amdgcn_struct_ptr_buffer_load_lds;
11158 unsigned OpOffset = HasVIndex ? 1 : 0;
11159 SDValue VOffset =
Op.getOperand(5 + OpOffset);
11161 unsigned Size =
Op->getConstantOperandVal(4);
11167 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_UBYTE_LDS_BOTHEN
11168 : AMDGPU::BUFFER_LOAD_UBYTE_LDS_IDXEN
11169 : HasVOffset ? AMDGPU::BUFFER_LOAD_UBYTE_LDS_OFFEN
11170 : AMDGPU::BUFFER_LOAD_UBYTE_LDS_OFFSET;
11173 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_USHORT_LDS_BOTHEN
11174 : AMDGPU::BUFFER_LOAD_USHORT_LDS_IDXEN
11175 : HasVOffset ? AMDGPU::BUFFER_LOAD_USHORT_LDS_OFFEN
11176 : AMDGPU::BUFFER_LOAD_USHORT_LDS_OFFSET;
11179 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORD_LDS_BOTHEN
11180 : AMDGPU::BUFFER_LOAD_DWORD_LDS_IDXEN
11181 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORD_LDS_OFFEN
11182 : AMDGPU::BUFFER_LOAD_DWORD_LDS_OFFSET;
11185 if (!Subtarget->hasLDSLoadB96_B128())
11187 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX3_LDS_BOTHEN
11188 : AMDGPU::BUFFER_LOAD_DWORDX3_LDS_IDXEN
11189 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX3_LDS_OFFEN
11190 : AMDGPU::BUFFER_LOAD_DWORDX3_LDS_OFFSET;
11193 if (!Subtarget->hasLDSLoadB96_B128())
11195 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX4_LDS_BOTHEN
11196 : AMDGPU::BUFFER_LOAD_DWORDX4_LDS_IDXEN
11197 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX4_LDS_OFFEN
11198 : AMDGPU::BUFFER_LOAD_DWORDX4_LDS_OFFSET;
11206 if (HasVIndex && HasVOffset)
11210 else if (HasVIndex)
11211 Ops.push_back(
Op.getOperand(5));
11212 else if (HasVOffset)
11213 Ops.push_back(VOffset);
11215 SDValue Rsrc = bufferRsrcPtrToVector(
Op.getOperand(2), DAG);
11216 Ops.push_back(Rsrc);
11217 Ops.push_back(
Op.getOperand(6 + OpOffset));
11218 Ops.push_back(
Op.getOperand(7 + OpOffset));
11220 unsigned Aux =
Op.getConstantOperandVal(8 + OpOffset);
11233 MachineMemOperand *LoadMMO =
M->getMemOperand();
11238 MachinePointerInfo StorePtrI = LoadPtrI;
11262 case Intrinsic::amdgcn_load_to_lds:
11263 case Intrinsic::amdgcn_global_load_lds: {
11264 if (!Subtarget->hasVMemToLDSLoad())
11268 unsigned Size =
Op->getConstantOperandVal(4);
11273 Opc = AMDGPU::GLOBAL_LOAD_LDS_UBYTE;
11276 Opc = AMDGPU::GLOBAL_LOAD_LDS_USHORT;
11279 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORD;
11282 if (!Subtarget->hasLDSLoadB96_B128())
11284 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORDX3;
11287 if (!Subtarget->hasLDSLoadB96_B128())
11289 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORDX4;
11305 if (
LHS->isDivergent())
11309 RHS.getOperand(0).getValueType() == MVT::i32) {
11312 VOffset =
RHS.getOperand(0);
11316 Ops.push_back(Addr);
11324 Ops.push_back(VOffset);
11327 Ops.push_back(
Op.getOperand(5));
11328 Ops.push_back(
Op.getOperand(6));
11333 MachineMemOperand *LoadMMO =
M->getMemOperand();
11335 LoadPtrI.
Offset =
Op->getConstantOperandVal(5);
11336 MachinePointerInfo StorePtrI = LoadPtrI;
11355 case Intrinsic::amdgcn_end_cf:
11357 Op->getOperand(2), Chain),
11359 case Intrinsic::amdgcn_s_barrier_init:
11360 case Intrinsic::amdgcn_s_barrier_signal_var: {
11367 unsigned Opc = IntrinsicID == Intrinsic::amdgcn_s_barrier_init
11368 ? AMDGPU::S_BARRIER_INIT_M0
11369 : AMDGPU::S_BARRIER_SIGNAL_M0;
11384 constexpr unsigned ShAmt = 16;
11391 Ops.push_back(
copyToM0(DAG, Chain,
DL, M0Val).getValue(0));
11396 case Intrinsic::amdgcn_s_barrier_join: {
11405 Opc = AMDGPU::S_BARRIER_JOIN_IMM;
11408 unsigned BarID = (BarVal >> 4) & 0x3F;
11411 Ops.push_back(Chain);
11413 Opc = AMDGPU::S_BARRIER_JOIN_M0;
11423 Ops.push_back(
copyToM0(DAG, Chain,
DL, M0Val).getValue(0));
11429 case Intrinsic::amdgcn_s_prefetch_data: {
11432 return Op.getOperand(0);
11435 case Intrinsic::amdgcn_s_buffer_prefetch_data: {
11437 Chain, bufferRsrcPtrToVector(
Op.getOperand(2), DAG),
11444 Op->getVTList(),
Ops,
M->getMemoryVT(),
11445 M->getMemOperand());
11447 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
11448 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
11449 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
11458 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
11460 return lowerImage(
Op, ImageDimIntr, DAG,
true);
11485std::pair<SDValue, SDValue>
11515 unsigned Overflow = ImmOffset & ~MaxImm;
11516 ImmOffset -= Overflow;
11517 if ((int32_t)Overflow < 0) {
11518 Overflow += ImmOffset;
11523 auto OverflowVal = DAG.
getConstant(Overflow,
DL, MVT::i32);
11542void SITargetLowering::setBufferOffsets(
SDValue CombinedOffset,
11544 Align Alignment)
const {
11546 SDLoc
DL(CombinedOffset);
11548 uint32_t
Imm =
C->getZExtValue();
11549 uint32_t SOffset, ImmOffset;
11550 if (
TII->splitMUBUFOffset(Imm, SOffset, ImmOffset, Alignment)) {
11560 uint32_t SOffset, ImmOffset;
11563 TII->splitMUBUFOffset(
Offset, SOffset, ImmOffset, Alignment)) {
11571 SDValue SOffsetZero = Subtarget->hasRestrictedSOffset()
11580SDValue SITargetLowering::bufferRsrcPtrToVector(
SDValue MaybePointer,
11583 return MaybePointer;
11597 SDValue NumRecords =
Op->getOperand(3);
11600 auto [LowHalf, HighHalf] = DAG.
SplitScalar(Pointer, Loc, MVT::i32, MVT::i32);
11603 std::optional<uint32_t> ConstStride = std::nullopt;
11605 ConstStride = ConstNode->getZExtValue();
11608 if (!ConstStride || *ConstStride != 0) {
11611 ShiftedStride = DAG.
getConstant(*ConstStride << 16, Loc, MVT::i32);
11622 NewHighHalf, NumRecords, Flags);
11623 SDValue RsrcPtr = DAG.
getNode(ISD::BITCAST, Loc, MVT::i128, Rsrc);
11632 bool IsTFE)
const {
11641 SDVTList VTs = DAG.
getVTList(MVT::v2i32, MVT::Other);
11656 SDVTList ResList = DAG.
getVTList(MVT::i32, MVT::Other);
11660 LoadVal = DAG.
getNode(ISD::BITCAST,
DL, LoadVT, LoadVal);
11670 if (VDataType == MVT::f16 || VDataType == MVT::bf16)
11674 Ops[1] = BufferStoreExt;
11679 M->getMemOperand());
11704 DAGCombinerInfo &DCI)
const {
11705 SelectionDAG &DAG = DCI.DAG;
11720 if ((MemVT.
isSimple() && !DCI.isAfterLegalizeDAG()) ||
11727 "unexpected vector extload");
11740 "unexpected fp extload");
11758 DCI.AddToWorklist(Cvt.
getNode());
11763 DCI.AddToWorklist(Cvt.
getNode());
11766 Cvt = DAG.
getNode(ISD::BITCAST, SL, VT, Cvt);
11774 if (
Info.isEntryFunction())
11775 return Info.getUserSGPRInfo().hasFlatScratchInit();
11783 EVT MemVT =
Load->getMemoryVT();
11784 MachineMemOperand *MMO =
Load->getMemOperand();
11796 EVT RealMemVT = (MemVT == MVT::i1) ? MVT::i8 : MVT::i16;
11824 assert(
Op.getValueType().getVectorElementType() == MVT::i32 &&
11825 "Custom lowering for non-i32 vectors hasn't been implemented.");
11828 unsigned AS =
Load->getAddressSpace();
11835 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
11839 !Subtarget->hasMultiDwordFlatScratchAddressing())
11849 Subtarget->getScalarizeGlobalBehavior() &&
Load->isSimple() &&
11852 Alignment >=
Align(4) && NumElements < 32) {
11854 (Subtarget->hasScalarDwordx3Loads() && NumElements == 3))
11866 if (NumElements > 4)
11869 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
11879 switch (Subtarget->getMaxPrivateElementSize()) {
11885 if (NumElements > 2)
11890 if (NumElements > 4)
11893 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
11902 auto Flags =
Load->getMemOperand()->getFlags();
11904 Load->getAlign(), Flags, &
Fast) &&
11913 MemVT, *
Load->getMemOperand())) {
11922 EVT VT =
Op.getValueType();
11949 return DAG.
getNode(ISD::BITCAST,
DL, VT, Res);
11959 EVT VT =
Op.getValueType();
11960 const SDNodeFlags
Flags =
Op->getFlags();
11962 bool AllowInaccurateRcp =
Flags.hasApproximateFuncs();
11968 if (!AllowInaccurateRcp && VT != MVT::f16 && VT != MVT::bf16)
11971 if (CLHS->isExactlyValue(1.0)) {
11988 if (CLHS->isExactlyValue(-1.0)) {
11997 if (!AllowInaccurateRcp &&
11998 ((VT != MVT::f16 && VT != MVT::bf16) || !
Flags.hasAllowReciprocal()))
12012 EVT VT =
Op.getValueType();
12013 const SDNodeFlags
Flags =
Op->getFlags();
12015 bool AllowInaccurateDiv =
Flags.hasApproximateFuncs();
12016 if (!AllowInaccurateDiv)
12037 return DAG.
getNode(Opcode, SL, VT,
A,
B, Flags);
12051 return DAG.
getNode(Opcode, SL, VTList,
12060 return DAG.
getNode(Opcode, SL, VT, {
A,
B,
C}, Flags);
12074 return DAG.
getNode(Opcode, SL, VTList,
12080 if (
SDValue FastLowered = lowerFastUnsafeFDIV(
Op, DAG))
12081 return FastLowered;
12084 EVT VT =
Op.getValueType();
12091 if (VT == MVT::bf16) {
12114 unsigned FMADOpCode =
12116 SDValue NegRHSExt = DAG.
getNode(ISD::FNEG, SL, MVT::f32, RHSExt);
12121 SDValue Err = DAG.
getNode(FMADOpCode, SL, MVT::f32, NegRHSExt, Quot, LHSExt,
12123 Quot = DAG.
getNode(FMADOpCode, SL, MVT::f32, Err, Rcp, Quot,
Op->getFlags());
12124 Err = DAG.
getNode(FMADOpCode, SL, MVT::f32, NegRHSExt, Quot, LHSExt,
12130 Tmp = DAG.
getNode(ISD::BITCAST, SL, MVT::f32, TmpCast);
12140 SDNodeFlags
Flags =
Op->getFlags();
12147 const APFloat K0Val(0x1p+96f);
12150 const APFloat K1Val(0x1p-32f);
12177 assert(ST->hasDenormModeInst() &&
"Requires S_DENORM_MODE");
12178 uint32_t DPDenormModeDefault =
Info->getMode().fpDenormModeDPValue();
12179 uint32_t Mode = SPDenormMode | (DPDenormModeDefault << 2);
12184 if (
SDValue FastLowered = lowerFastUnsafeFDIV(
Op, DAG))
12185 return FastLowered;
12191 SDNodeFlags
Flags =
Op->getFlags();
12192 Flags.setNoFPExcept(
true);
12200 SDVTList ScaleVT = DAG.
getVTList(MVT::f32, MVT::i1);
12211 DAG.
getNode(ISD::FNEG, SL, MVT::f32, DenominatorScaled, Flags);
12213 using namespace AMDGPU::Hwreg;
12214 const unsigned Denorm32Reg = HwregEncoding::encode(ID_MODE, 4, 2);
12218 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
12219 const DenormalMode DenormMode =
Info->getMode().FP32Denormals;
12222 const bool HasDynamicDenormals =
12228 if (!PreservesDenormals) {
12233 SDVTList BindParamVTs = DAG.
getVTList(MVT::Other, MVT::Glue);
12236 if (HasDynamicDenormals) {
12240 SavedDenormMode =
SDValue(GetReg, 0);
12246 SDNode *EnableDenorm;
12247 if (Subtarget->hasDenormModeInst()) {
12248 const SDValue EnableDenormValue =
12255 const SDValue EnableDenormValue =
12257 EnableDenorm = DAG.
getMachineNode(AMDGPU::S_SETREG_B32, SL, BindParamVTs,
12258 {EnableDenormValue,
BitField, Glue});
12268 ApproxRcp, One, NegDivScale0, Flags);
12271 ApproxRcp, Fma0, Flags);
12277 NumeratorScaled,
Mul, Flags);
12283 NumeratorScaled, Fma3, Flags);
12285 if (!PreservesDenormals) {
12286 SDNode *DisableDenorm;
12287 if (!HasDynamicDenormals && Subtarget->hasDenormModeInst()) {
12291 SDVTList BindParamVTs = DAG.
getVTList(MVT::Other, MVT::Glue);
12297 assert(HasDynamicDenormals == (
bool)SavedDenormMode);
12298 const SDValue DisableDenormValue =
12299 HasDynamicDenormals
12304 AMDGPU::S_SETREG_B32, SL, MVT::Other,
12315 {Fma4, Fma1, Fma3, Scale},
Flags);
12321 if (
SDValue FastLowered = lowerFastUnsafeFDIV64(
Op, DAG))
12322 return FastLowered;
12330 SDVTList ScaleVT = DAG.
getVTList(MVT::f64, MVT::i1);
12334 SDValue NegDivScale0 = DAG.
getNode(ISD::FNEG, SL, MVT::f64, DivScale0);
12354 if (!Subtarget->hasUsableDivScaleConditionOutput()) {
12363 SDValue Scale0BC = DAG.
getNode(ISD::BITCAST, SL, MVT::v2i32, DivScale0);
12364 SDValue Scale1BC = DAG.
getNode(ISD::BITCAST, SL, MVT::v2i32, DivScale1);
12390 EVT VT =
Op.getValueType();
12392 if (VT == MVT::f32)
12393 return LowerFDIV32(
Op, DAG);
12395 if (VT == MVT::f64)
12396 return LowerFDIV64(
Op, DAG);
12398 if (VT == MVT::f16 || VT == MVT::bf16)
12399 return LowerFDIV16(
Op, DAG);
12408 EVT ResultExpVT =
Op->getValueType(1);
12409 EVT InstrExpVT = VT == MVT::f16 ? MVT::i16 : MVT::i32;
12419 if (Subtarget->hasFractBug()) {
12437 EVT VT =
Store->getMemoryVT();
12439 if (VT == MVT::i1) {
12443 Store->getBasePtr(), MVT::i1,
Store->getMemOperand());
12447 Store->getValue().getValueType().getScalarType() == MVT::i32);
12449 unsigned AS =
Store->getAddressSpace();
12457 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
12461 !Subtarget->hasMultiDwordFlatScratchAddressing())
12468 if (NumElements > 4)
12471 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
12475 VT, *
Store->getMemOperand()))
12481 switch (Subtarget->getMaxPrivateElementSize()) {
12485 if (NumElements > 2)
12489 if (NumElements > 4 ||
12490 (NumElements == 3 && !Subtarget->enableFlatScratch()))
12498 auto Flags =
Store->getMemOperand()->getFlags();
12517 assert(!Subtarget->has16BitInsts());
12518 SDNodeFlags
Flags =
Op->getFlags();
12520 DAG.
getNode(ISD::FP_EXTEND, SL, MVT::f32,
Op.getOperand(0), Flags);
12532 SDNodeFlags
Flags =
Op->getFlags();
12533 MVT VT =
Op.getValueType().getSimpleVT();
12563 SDValue SqrtSNextDown = DAG.
getNode(ISD::BITCAST,
DL, VT, SqrtSNextDownInt);
12566 DAG.
getNode(ISD::FNEG,
DL, VT, SqrtSNextDown, Flags);
12575 SDValue NegSqrtSNextUp = DAG.
getNode(ISD::FNEG,
DL, VT, SqrtSNextUp, Flags);
12641 SDNodeFlags
Flags =
Op->getFlags();
12687 SqrtRet = DAG.
getNode(ISD::FLDEXP,
DL, MVT::f64, SqrtRet, ScaleDown, Flags);
12704 EVT VT =
Op.getValueType();
12714 if (Subtarget->hasTrigReducedRange()) {
12721 switch (
Op.getOpcode()) {
12748 EVT VT =
Op.getValueType();
12756 Op->getVTList(),
Ops, VT,
12765SITargetLowering::performUCharToFloatCombine(
SDNode *
N,
12766 DAGCombinerInfo &DCI)
const {
12767 EVT VT =
N->getValueType(0);
12769 if (ScalarVT != MVT::f32 && ScalarVT != MVT::f16)
12772 SelectionDAG &DAG = DCI.DAG;
12776 EVT SrcVT = Src.getValueType();
12782 if (DCI.isAfterLegalizeDAG() && SrcVT == MVT::i32) {
12785 DCI.AddToWorklist(Cvt.
getNode());
12788 if (ScalarVT != MVT::f32) {
12800 DAGCombinerInfo &DCI)
const {
12807 if (SignOp.
getOpcode() == ISD::FP_EXTEND ||
12811 SelectionDAG &DAG = DCI.DAG;
12830 for (
unsigned I = 0;
I != NumElts; ++
I) {
12854 if (NewElts.
size() == 1)
12876 for (
unsigned I = 0;
I != NumElts; ++
I) {
12911SDValue SITargetLowering::performSHLPtrCombine(
SDNode *
N,
unsigned AddrSpace,
12913 DAGCombinerInfo &DCI)
const {
12931 SelectionDAG &DAG = DCI.DAG;
12944 AM.BaseOffs =
Offset.getSExtValue();
12949 EVT VT =
N->getValueType(0);
12955 Flags.setNoUnsignedWrap(
12956 N->getFlags().hasNoUnsignedWrap() &&
12966 switch (
N->getOpcode()) {
12977 DAGCombinerInfo &DCI)
const {
12978 SelectionDAG &DAG = DCI.DAG;
12985 SDValue NewPtr = performSHLPtrCombine(
Ptr.getNode(),
N->getAddressSpace(),
12986 N->getMemoryVT(), DCI);
12990 NewOps[PtrIdx] = NewPtr;
12999 return (
Opc ==
ISD::AND && (Val == 0 || Val == 0xffffffff)) ||
13000 (
Opc ==
ISD::OR && (Val == 0xffffffff || Val == 0)) ||
13009SDValue SITargetLowering::splitBinaryBitConstantOp(
13013 uint32_t ValLo =
Lo_32(Val);
13014 uint32_t ValHi =
Hi_32(Val);
13021 if (Subtarget->has64BitLiterals() && CRHS->
hasOneUse() &&
13035 if (V.getValueType() != MVT::i1)
13037 switch (V.getOpcode()) {
13054 return V.getResNo() == 1;
13056 unsigned IntrinsicID = V.getConstantOperandVal(0);
13057 switch (IntrinsicID) {
13058 case Intrinsic::amdgcn_is_shared:
13059 case Intrinsic::amdgcn_is_private:
13076 if (!(
C & 0x000000ff))
13077 ZeroByteMask |= 0x000000ff;
13078 if (!(
C & 0x0000ff00))
13079 ZeroByteMask |= 0x0000ff00;
13080 if (!(
C & 0x00ff0000))
13081 ZeroByteMask |= 0x00ff0000;
13082 if (!(
C & 0xff000000))
13083 ZeroByteMask |= 0xff000000;
13084 uint32_t NonZeroByteMask = ~ZeroByteMask;
13085 if ((NonZeroByteMask &
C) != NonZeroByteMask)
13098 assert(V.getValueSizeInBits() == 32);
13100 if (V.getNumOperands() != 2)
13109 switch (V.getOpcode()) {
13114 return (0x03020100 & ConstMask) | (0x0c0c0c0c & ~ConstMask);
13119 return (0x03020100 & ~ConstMask) | ConstMask;
13126 return uint32_t((0x030201000c0c0c0cull <<
C) >> 32);
13132 return uint32_t(0x0c0c0c0c03020100ull >>
C);
13139 DAGCombinerInfo &DCI)
const {
13140 if (DCI.isBeforeLegalize())
13143 SelectionDAG &DAG = DCI.DAG;
13144 EVT VT =
N->getValueType(0);
13149 if (VT == MVT::i64 && CRHS) {
13151 splitBinaryBitConstantOp(DCI, SDLoc(
N),
ISD::AND,
LHS, CRHS))
13155 if (CRHS && VT == MVT::i32) {
13165 unsigned Shift = CShift->getZExtValue();
13167 unsigned Offset = NB + Shift;
13168 if ((
Offset & (Bits - 1)) == 0) {
13192 Sel = (
LHS.getConstantOperandVal(2) & Sel) | (~Sel & 0x0c0c0c0c);
13207 if (
Y.getOpcode() != ISD::FABS ||
Y.getOperand(0) !=
X ||
13212 if (
X !=
LHS.getOperand(1))
13216 const ConstantFPSDNode *C1 =
13250 (
RHS.getOperand(0) ==
LHS.getOperand(0) &&
13251 LHS.getOperand(0) ==
LHS.getOperand(1))) {
13253 unsigned NewMask = LCC ==
ISD::SETO ?
Mask->getZExtValue() & ~OrdMask
13254 :
Mask->getZExtValue() & OrdMask;
13275 N->isDivergent() &&
TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
13278 if (LHSMask != ~0u && RHSMask != ~0u) {
13281 if (LHSMask > RHSMask) {
13288 uint32_t LHSUsedLanes = ~(LHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
13289 uint32_t RHSUsedLanes = ~(RHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
13292 if (!(LHSUsedLanes & RHSUsedLanes) &&
13295 !(LHSUsedLanes == 0x0c0c0000 && RHSUsedLanes == 0x00000c0c)) {
13301 uint32_t
Mask = LHSMask & RHSMask;
13302 for (
unsigned I = 0;
I < 32;
I += 8) {
13303 uint32_t ByteSel = 0xff <<
I;
13304 if ((LHSMask & ByteSel) == 0x0c || (RHSMask & ByteSel) == 0x0c)
13305 Mask &= (0x0c <<
I) & 0xffffffff;
13310 uint32_t Sel =
Mask | (LHSUsedLanes & 0x04040404);
13363static const std::optional<ByteProvider<SDValue>>
13365 unsigned Depth = 0) {
13368 return std::nullopt;
13370 if (
Op.getValueSizeInBits() < 8)
13371 return std::nullopt;
13373 if (
Op.getValueType().isVector())
13376 switch (
Op->getOpcode()) {
13388 NarrowVT = VTSign->getVT();
13391 return std::nullopt;
13394 if (SrcIndex >= NarrowByteWidth)
13395 return std::nullopt;
13403 return std::nullopt;
13405 uint64_t BitShift = ShiftOp->getZExtValue();
13407 if (BitShift % 8 != 0)
13408 return std::nullopt;
13410 SrcIndex += BitShift / 8;
13428static const std::optional<ByteProvider<SDValue>>
13430 unsigned StartingIndex = 0) {
13434 return std::nullopt;
13436 unsigned BitWidth =
Op.getScalarValueSizeInBits();
13438 return std::nullopt;
13440 return std::nullopt;
13442 bool IsVec =
Op.getValueType().isVector();
13443 switch (
Op.getOpcode()) {
13446 return std::nullopt;
13451 return std::nullopt;
13455 return std::nullopt;
13458 if (!
LHS->isConstantZero() && !
RHS->isConstantZero())
13459 return std::nullopt;
13460 if (!
LHS ||
LHS->isConstantZero())
13462 if (!
RHS ||
RHS->isConstantZero())
13464 return std::nullopt;
13469 return std::nullopt;
13473 return std::nullopt;
13475 uint32_t BitMask = BitMaskOp->getZExtValue();
13477 uint32_t IndexMask = 0xFF << (Index * 8);
13479 if ((IndexMask & BitMask) != IndexMask) {
13482 if (IndexMask & BitMask)
13483 return std::nullopt;
13492 return std::nullopt;
13496 if (!ShiftOp ||
Op.getValueType().isVector())
13497 return std::nullopt;
13499 uint64_t BitsProvided =
Op.getValueSizeInBits();
13500 if (BitsProvided % 8 != 0)
13501 return std::nullopt;
13503 uint64_t BitShift = ShiftOp->getAPIntValue().urem(BitsProvided);
13505 return std::nullopt;
13507 uint64_t ConcatSizeInBytes = BitsProvided / 4;
13508 uint64_t ByteShift = BitShift / 8;
13510 uint64_t NewIndex = (Index + ByteShift) % ConcatSizeInBytes;
13511 uint64_t BytesProvided = BitsProvided / 8;
13512 SDValue NextOp =
Op.getOperand(NewIndex >= BytesProvided ? 0 : 1);
13513 NewIndex %= BytesProvided;
13520 return std::nullopt;
13524 return std::nullopt;
13526 uint64_t BitShift = ShiftOp->getZExtValue();
13528 return std::nullopt;
13530 auto BitsProvided =
Op.getScalarValueSizeInBits();
13531 if (BitsProvided % 8 != 0)
13532 return std::nullopt;
13534 uint64_t BytesProvided = BitsProvided / 8;
13535 uint64_t ByteShift = BitShift / 8;
13540 return BytesProvided - ByteShift > Index
13548 return std::nullopt;
13552 return std::nullopt;
13554 uint64_t BitShift = ShiftOp->getZExtValue();
13555 if (BitShift % 8 != 0)
13556 return std::nullopt;
13557 uint64_t ByteShift = BitShift / 8;
13563 return Index < ByteShift
13566 Depth + 1, StartingIndex);
13575 return std::nullopt;
13583 NarrowBitWidth = VTSign->getVT().getSizeInBits();
13585 if (NarrowBitWidth % 8 != 0)
13586 return std::nullopt;
13587 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
13589 if (Index >= NarrowByteWidth)
13591 ? std::optional<ByteProvider<SDValue>>(
13599 return std::nullopt;
13603 if (NarrowByteWidth >= Index) {
13608 return std::nullopt;
13615 return std::nullopt;
13621 unsigned NarrowBitWidth = L->getMemoryVT().getSizeInBits();
13622 if (NarrowBitWidth % 8 != 0)
13623 return std::nullopt;
13624 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
13629 if (Index >= NarrowByteWidth) {
13631 ? std::optional<ByteProvider<SDValue>>(
13636 if (NarrowByteWidth > Index) {
13640 return std::nullopt;
13645 return std::nullopt;
13648 Depth + 1, StartingIndex);
13654 return std::nullopt;
13655 auto VecIdx = IdxOp->getZExtValue();
13656 auto ScalarSize =
Op.getScalarValueSizeInBits();
13657 if (ScalarSize < 32)
13658 Index = ScalarSize == 8 ? VecIdx : VecIdx * 2 + Index;
13660 StartingIndex, Index);
13665 return std::nullopt;
13669 return std::nullopt;
13672 (PermMask->getZExtValue() & (0xFF << (Index * 8))) >> (Index * 8);
13673 if (IdxMask > 0x07 && IdxMask != 0x0c)
13674 return std::nullopt;
13676 auto NextOp =
Op.getOperand(IdxMask > 0x03 ? 0 : 1);
13677 auto NextIndex = IdxMask > 0x03 ? IdxMask % 4 : IdxMask;
13679 return IdxMask != 0x0c ?
calculateSrcByte(NextOp, StartingIndex, NextIndex)
13685 return std::nullopt;
13700 return !OpVT.
isVector() && OpVT.getSizeInBits() == 16;
13707 auto MemVT = L->getMemoryVT();
13710 return L->getMemoryVT().getSizeInBits() == 16;
13720 int Low8 = Mask & 0xff;
13721 int Hi8 = (Mask & 0xff00) >> 8;
13723 assert(Low8 < 8 && Hi8 < 8);
13725 bool IsConsecutive = (Hi8 - Low8 == 1);
13730 bool Is16Aligned = !(Low8 % 2);
13732 return IsConsecutive && Is16Aligned;
13740 int Low16 = PermMask & 0xffff;
13741 int Hi16 = (PermMask & 0xffff0000) >> 16;
13751 auto OtherOpIs16Bit = TempOtherOp.getValueSizeInBits() == 16 ||
13753 if (!OtherOpIs16Bit)
13761 unsigned DWordOffset) {
13766 assert(Src.getValueSizeInBits().isKnownMultipleOf(8));
13771 if (Src.getValueType().isVector()) {
13772 auto ScalarTySize = Src.getScalarValueSizeInBits();
13773 auto ScalarTy = Src.getValueType().getScalarType();
13774 if (ScalarTySize == 32) {
13778 if (ScalarTySize > 32) {
13781 DAG.
getConstant(DWordOffset / (ScalarTySize / 32), SL, MVT::i32));
13782 auto ShiftVal = 32 * (DWordOffset % (ScalarTySize / 32));
13789 assert(ScalarTySize < 32);
13790 auto NumElements =
TypeSize / ScalarTySize;
13791 auto Trunc32Elements = (ScalarTySize * NumElements) / 32;
13792 auto NormalizedTrunc = Trunc32Elements * 32 / ScalarTySize;
13793 auto NumElementsIn32 = 32 / ScalarTySize;
13794 auto NumAvailElements = DWordOffset < Trunc32Elements
13796 : NumElements - NormalizedTrunc;
13809 auto ShiftVal = 32 * DWordOffset;
13817 [[maybe_unused]]
EVT VT =
N->getValueType(0);
13822 for (
int i = 0; i < 4; i++) {
13824 std::optional<ByteProvider<SDValue>>
P =
13827 if (!
P ||
P->isConstantZero())
13832 if (PermNodes.
size() != 4)
13835 std::pair<unsigned, unsigned> FirstSrc(0, PermNodes[0].SrcOffset / 4);
13836 std::optional<std::pair<unsigned, unsigned>> SecondSrc;
13838 for (
size_t i = 0; i < PermNodes.
size(); i++) {
13839 auto PermOp = PermNodes[i];
13842 int SrcByteAdjust = 4;
13846 if (!PermOp.hasSameSrc(PermNodes[FirstSrc.first]) ||
13847 ((PermOp.SrcOffset / 4) != FirstSrc.second)) {
13849 if (!PermOp.hasSameSrc(PermNodes[SecondSrc->first]) ||
13850 ((PermOp.SrcOffset / 4) != SecondSrc->second))
13854 SecondSrc = {i, PermNodes[i].SrcOffset / 4};
13855 assert(!(PermNodes[SecondSrc->first].Src->getValueSizeInBits() % 8));
13858 assert((PermOp.SrcOffset % 4) + SrcByteAdjust < 8);
13860 PermMask |= ((PermOp.SrcOffset % 4) + SrcByteAdjust) << (i * 8);
13863 SDValue Op = *PermNodes[FirstSrc.first].Src;
13865 assert(
Op.getValueSizeInBits() == 32);
13869 int Low16 = PermMask & 0xffff;
13870 int Hi16 = (PermMask & 0xffff0000) >> 16;
13872 bool WellFormedLow = (Low16 == 0x0504) || (Low16 == 0x0100);
13873 bool WellFormedHi = (Hi16 == 0x0706) || (Hi16 == 0x0302);
13876 if (WellFormedLow && WellFormedHi)
13880 SDValue OtherOp = SecondSrc ? *PermNodes[SecondSrc->first].Src :
Op;
13889 assert(
Op.getValueType().isByteSized() &&
13907 DAGCombinerInfo &DCI)
const {
13908 SelectionDAG &DAG = DCI.DAG;
13912 EVT VT =
N->getValueType(0);
13913 if (VT == MVT::i1) {
13918 if (Src !=
RHS.getOperand(0))
13923 if (!CLHS || !CRHS)
13927 static const uint32_t MaxMask = 0x3ff;
13947 Sel |=
LHS.getConstantOperandVal(2);
13956 N->isDivergent() &&
TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
13960 auto usesCombinedOperand = [](SDNode *OrUse) {
13962 if (OrUse->getOpcode() != ISD::BITCAST ||
13963 !OrUse->getValueType(0).isVector())
13967 for (
auto *VUser : OrUse->users()) {
13968 if (!VUser->getValueType(0).isVector())
13975 if (VUser->getOpcode() == VectorwiseOp)
13981 if (!
any_of(
N->users(), usesCombinedOperand))
13987 if (LHSMask != ~0u && RHSMask != ~0u) {
13990 if (LHSMask > RHSMask) {
13997 uint32_t LHSUsedLanes = ~(LHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
13998 uint32_t RHSUsedLanes = ~(RHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
14001 if (!(LHSUsedLanes & RHSUsedLanes) &&
14004 !(LHSUsedLanes == 0x0c0c0000 && RHSUsedLanes == 0x00000c0c)) {
14006 LHSMask &= ~RHSUsedLanes;
14007 RHSMask &= ~LHSUsedLanes;
14009 LHSMask |= LHSUsedLanes & 0x04040404;
14011 uint32_t Sel = LHSMask | RHSMask;
14019 if (LHSMask == ~0u || RHSMask == ~0u) {
14060 return IdentitySrc;
14066 if (VT != MVT::i64 || DCI.isBeforeLegalizeOps())
14081 if (SrcVT == MVT::i32) {
14086 DCI.AddToWorklist(LowOr.
getNode());
14087 DCI.AddToWorklist(HiBits.getNode());
14091 return DAG.
getNode(ISD::BITCAST, SL, MVT::i64, Vec);
14098 N->getOperand(0), CRHS))
14106 DAGCombinerInfo &DCI)
const {
14107 if (
SDValue RV = reassociateScalarOps(
N, DCI.DAG))
14114 SelectionDAG &DAG = DCI.DAG;
14116 EVT VT =
N->getValueType(0);
14117 if (CRHS && VT == MVT::i64) {
14119 splitBinaryBitConstantOp(DCI, SDLoc(
N),
ISD::XOR,
LHS, CRHS))
14126 unsigned Opc =
LHS.getOpcode();
14150 DAG.
getNode(ISD::BITCAST,
DL, MVT::f32,
LHS->getOperand(1));
14152 DAG.
getNode(ISD::BITCAST,
DL, MVT::f32,
LHS->getOperand(2));
14156 LHS->getOperand(0), FNegLHS, FNegRHS);
14157 return DAG.
getNode(ISD::BITCAST,
DL, VT, NewSelect);
14165 DAGCombinerInfo &DCI)
const {
14166 if (!Subtarget->has16BitInsts() ||
14170 EVT VT =
N->getValueType(0);
14171 if (VT != MVT::i32)
14175 if (Src.getValueType() != MVT::i16)
14182SITargetLowering::performSignExtendInRegCombine(
SDNode *
N,
14183 DAGCombinerInfo &DCI)
const {
14190 VTSign->getVT() == MVT::i8) ||
14192 VTSign->getVT() == MVT::i16))) {
14193 assert(Subtarget->hasScalarSubwordLoads() &&
14194 "s_buffer_load_{u8, i8} are supported "
14195 "in GFX12 (or newer) architectures.");
14196 EVT VT = Src.getValueType();
14201 SDVTList ResList = DCI.DAG.getVTList(MVT::i32);
14208 SDValue BufferLoad = DCI.DAG.getMemIntrinsicNode(
14209 Opc,
DL, ResList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
14214 VTSign->getVT() == MVT::i8) ||
14216 VTSign->getVT() == MVT::i16)) &&
14225 Src.getOperand(6), Src.getOperand(7)};
14228 DCI.DAG.getVTList(MVT::i32, Src.getOperand(0).getValueType());
14232 SDValue BufferLoadSignExt = DCI.DAG.getMemIntrinsicNode(
14233 Opc, SDLoc(
N), ResList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
14234 return DCI.DAG.getMergeValues(
14235 {BufferLoadSignExt, BufferLoadSignExt.
getValue(1)}, SDLoc(
N));
14241 DAGCombinerInfo &DCI)
const {
14242 SelectionDAG &DAG = DCI.DAG;
14249 if (
N->getOperand(0).isUndef())
14256 DAGCombinerInfo &DCI)
const {
14257 EVT VT =
N->getValueType(0);
14272 if ((VT == MVT::f16 && N0.
getOpcode() == ISD::FSQRT) &&
14282 unsigned MaxDepth)
const {
14283 unsigned Opcode =
Op.getOpcode();
14288 const auto &
F = CFP->getValueAPF();
14289 if (
F.isNaN() &&
F.isSignaling())
14291 if (!
F.isDenormal())
14317 case ISD::FP_EXTEND:
14318 case ISD::FP16_TO_FP:
14319 case ISD::FP_TO_FP16:
14320 case ISD::BF16_TO_FP:
14321 case ISD::FP_TO_BF16:
14354 if (
Op.getValueType() == MVT::i32) {
14360 if (RHS->getZExtValue() == 0xffff0000) {
14370 return Op.getValueType().getScalarType() != MVT::f16;
14374 case ISD::FMINNUM_IEEE:
14375 case ISD::FMAXNUM_IEEE:
14376 case ISD::FMINIMUM:
14377 case ISD::FMAXIMUM:
14378 case ISD::FMINIMUMNUM:
14379 case ISD::FMAXIMUMNUM:
14391 if (Subtarget->supportsMinMaxDenormModes() ||
14401 for (
unsigned I = 0, E =
Op.getNumOperands();
I != E; ++
I) {
14413 for (
unsigned i = 0, e =
Op.getNumOperands(); i != e; ++i) {
14440 if (
Op.getValueType() == MVT::i16) {
14443 TruncSrc.
getOpcode() == ISD::BITCAST &&
14451 unsigned IntrinsicID =
Op.getConstantOperandVal(0);
14453 switch (IntrinsicID) {
14454 case Intrinsic::amdgcn_cvt_pkrtz:
14455 case Intrinsic::amdgcn_cubeid:
14456 case Intrinsic::amdgcn_frexp_mant:
14457 case Intrinsic::amdgcn_fdot2:
14458 case Intrinsic::amdgcn_rcp:
14459 case Intrinsic::amdgcn_rsq:
14460 case Intrinsic::amdgcn_rsq_clamp:
14461 case Intrinsic::amdgcn_rcp_legacy:
14462 case Intrinsic::amdgcn_rsq_legacy:
14463 case Intrinsic::amdgcn_trig_preop:
14464 case Intrinsic::amdgcn_tanh:
14465 case Intrinsic::amdgcn_log:
14466 case Intrinsic::amdgcn_exp2:
14467 case Intrinsic::amdgcn_sqrt:
14485 unsigned MaxDepth)
const {
14488 unsigned Opcode =
MI->getOpcode();
14490 if (Opcode == AMDGPU::G_FCANONICALIZE)
14493 std::optional<FPValueAndVReg> FCR;
14496 if (FCR->Value.isSignaling())
14498 if (!FCR->Value.isDenormal())
14509 case AMDGPU::G_FADD:
14510 case AMDGPU::G_FSUB:
14511 case AMDGPU::G_FMUL:
14512 case AMDGPU::G_FCEIL:
14513 case AMDGPU::G_FFLOOR:
14514 case AMDGPU::G_FRINT:
14515 case AMDGPU::G_FNEARBYINT:
14516 case AMDGPU::G_INTRINSIC_FPTRUNC_ROUND:
14517 case AMDGPU::G_INTRINSIC_TRUNC:
14518 case AMDGPU::G_INTRINSIC_ROUNDEVEN:
14519 case AMDGPU::G_FMA:
14520 case AMDGPU::G_FMAD:
14521 case AMDGPU::G_FSQRT:
14522 case AMDGPU::G_FDIV:
14523 case AMDGPU::G_FREM:
14524 case AMDGPU::G_FPOW:
14525 case AMDGPU::G_FPEXT:
14526 case AMDGPU::G_FLOG:
14527 case AMDGPU::G_FLOG2:
14528 case AMDGPU::G_FLOG10:
14529 case AMDGPU::G_FPTRUNC:
14530 case AMDGPU::G_AMDGPU_RCP_IFLAG:
14531 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE0:
14532 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE1:
14533 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE2:
14534 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE3:
14536 case AMDGPU::G_FNEG:
14537 case AMDGPU::G_FABS:
14538 case AMDGPU::G_FCOPYSIGN:
14540 case AMDGPU::G_FMINNUM:
14541 case AMDGPU::G_FMAXNUM:
14542 case AMDGPU::G_FMINNUM_IEEE:
14543 case AMDGPU::G_FMAXNUM_IEEE:
14544 case AMDGPU::G_FMINIMUM:
14545 case AMDGPU::G_FMAXIMUM:
14546 case AMDGPU::G_FMINIMUMNUM:
14547 case AMDGPU::G_FMAXIMUMNUM: {
14548 if (Subtarget->supportsMinMaxDenormModes() ||
14555 case AMDGPU::G_BUILD_VECTOR:
14560 case AMDGPU::G_INTRINSIC:
14561 case AMDGPU::G_INTRINSIC_CONVERGENT:
14563 case Intrinsic::amdgcn_fmul_legacy:
14564 case Intrinsic::amdgcn_fmad_ftz:
14565 case Intrinsic::amdgcn_sqrt:
14566 case Intrinsic::amdgcn_fmed3:
14567 case Intrinsic::amdgcn_sin:
14568 case Intrinsic::amdgcn_cos:
14569 case Intrinsic::amdgcn_log:
14570 case Intrinsic::amdgcn_exp2:
14571 case Intrinsic::amdgcn_log_clamp:
14572 case Intrinsic::amdgcn_rcp:
14573 case Intrinsic::amdgcn_rcp_legacy:
14574 case Intrinsic::amdgcn_rsq:
14575 case Intrinsic::amdgcn_rsq_clamp:
14576 case Intrinsic::amdgcn_rsq_legacy:
14577 case Intrinsic::amdgcn_div_scale:
14578 case Intrinsic::amdgcn_div_fmas:
14579 case Intrinsic::amdgcn_div_fixup:
14580 case Intrinsic::amdgcn_fract:
14581 case Intrinsic::amdgcn_cvt_pkrtz:
14582 case Intrinsic::amdgcn_cubeid:
14583 case Intrinsic::amdgcn_cubema:
14584 case Intrinsic::amdgcn_cubesc:
14585 case Intrinsic::amdgcn_cubetc:
14586 case Intrinsic::amdgcn_frexp_mant:
14587 case Intrinsic::amdgcn_fdot2:
14588 case Intrinsic::amdgcn_trig_preop:
14589 case Intrinsic::amdgcn_tanh:
14608 if (
C.isDenormal()) {
14622 if (
C.isSignaling()) {
14645SITargetLowering::performFCanonicalizeCombine(
SDNode *
N,
14646 DAGCombinerInfo &DCI)
const {
14647 SelectionDAG &DAG = DCI.DAG;
14649 EVT VT =
N->getValueType(0);
14658 EVT VT =
N->getValueType(0);
14659 return getCanonicalConstantFP(DAG, SDLoc(
N), VT, CFP->getValueAPF());
14675 EVT EltVT =
Lo.getValueType();
14678 for (
unsigned I = 0;
I != 2; ++
I) {
14682 getCanonicalConstantFP(DAG, SL, EltVT, CFP->getValueAPF());
14683 }
else if (
Op.isUndef()) {
14717 case ISD::FMAXNUM_IEEE:
14718 case ISD::FMAXIMUMNUM:
14720 case ISD::FMAXIMUM:
14727 case ISD::FMINNUM_IEEE:
14728 case ISD::FMINIMUMNUM:
14730 case ISD::FMINIMUM:
14756 if (!MinK || !MaxK)
14769 if (VT == MVT::i32 || (VT == MVT::i16 && Subtarget->hasMed3_16()))
14770 return DAG.
getNode(Med3Opc, SL, VT, Src, MaxVal, MinVal);
14829 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
14835 if (
Info->getMode().DX10Clamp) {
14844 if (VT == MVT::f32 || (VT == MVT::f16 && Subtarget->hasMed3_16())) {
14872 case ISD::FMINNUM_IEEE:
14873 case ISD::FMAXNUM_IEEE:
14874 case ISD::FMINIMUMNUM:
14875 case ISD::FMAXIMUMNUM:
14878 return (VT == MVT::f32) || (VT == MVT::f16 && Subtarget.
hasMin3Max3_16()) ||
14880 case ISD::FMINIMUM:
14881 case ISD::FMAXIMUM:
14889 return (VT == MVT::i32) || (VT == MVT::i16 && Subtarget.
hasMin3Max3_16());
14898 DAGCombinerInfo &DCI)
const {
14899 SelectionDAG &DAG = DCI.DAG;
14931 if (
SDValue Med3 = performIntMed3ImmCombine(
14936 if (
SDValue Med3 = performIntMed3ImmCombine(
14942 if (
SDValue Med3 = performIntMed3ImmCombine(
14947 if (
SDValue Med3 = performIntMed3ImmCombine(
14957 if (((
Opc == ISD::FMINNUM && Op0.
getOpcode() == ISD::FMAXNUM) ||
14958 (
Opc == ISD::FMINNUM_IEEE && Op0.
getOpcode() == ISD::FMAXNUM_IEEE) ||
14959 (
Opc == ISD::FMINIMUMNUM && Op0.
getOpcode() == ISD::FMAXIMUMNUM) ||
14962 (VT == MVT::f32 || VT == MVT::f64 ||
14963 (VT == MVT::f16 && Subtarget->has16BitInsts()) ||
14964 (VT == MVT::bf16 && Subtarget->hasBF16PackedInsts()) ||
14965 (VT == MVT::v2bf16 && Subtarget->hasBF16PackedInsts()) ||
14966 (VT == MVT::v2f16 && Subtarget->hasVOP3PInsts())) &&
14968 if (
SDValue Res = performFPMed3ImmCombine(DAG, SDLoc(
N), Op0, Op1))
14975 const SDNodeFlags
Flags =
N->getFlags();
14976 if ((
Opc == ISD::FMINIMUM ||
Opc == ISD::FMAXIMUM) &&
14977 !Subtarget->hasIEEEMinimumMaximumInsts() &&
Flags.hasNoNaNs()) {
14979 Opc == ISD::FMINIMUM ? ISD::FMINNUM_IEEE : ISD::FMAXNUM_IEEE;
14980 return DAG.
getNode(NewOpc, SDLoc(
N), VT, Op0, Op1, Flags);
14990 return (CA->isExactlyValue(0.0) && CB->isExactlyValue(1.0)) ||
14991 (CA->isExactlyValue(1.0) && CB->isExactlyValue(0.0));
15000 DAGCombinerInfo &DCI)
const {
15001 EVT VT =
N->getValueType(0);
15005 SelectionDAG &DAG = DCI.DAG;
15020 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
15024 if (
Info->getMode().DX10Clamp) {
15044 DAGCombinerInfo &DCI)
const {
15048 return DCI.DAG.getUNDEF(
N->getValueType(0));
15056 bool IsDivergentIdx,
15061 unsigned VecSize = EltSize * NumElem;
15064 if (VecSize <= 64 && EltSize < 32)
15073 if (IsDivergentIdx)
15077 unsigned NumInsts = NumElem +
15078 ((EltSize + 31) / 32) * NumElem ;
15082 if (Subtarget->useVGPRIndexMode())
15083 return NumInsts <= 16;
15087 if (Subtarget->hasMovrel())
15088 return NumInsts <= 15;
15094 SDValue Idx =
N->getOperand(
N->getNumOperands() - 1);
15109SITargetLowering::performExtractVectorEltCombine(
SDNode *
N,
15110 DAGCombinerInfo &DCI)
const {
15116 EVT ResVT =
N->getValueType(0);
15140 if (!
C ||
C->getZExtValue() != 0x1f)
15156 if (Vec.
hasOneUse() && DCI.isBeforeLegalize() && VecEltVT == ResVT) {
15175 case ISD::FMAXNUM_IEEE:
15176 case ISD::FMINNUM_IEEE:
15177 case ISD::FMAXIMUM:
15178 case ISD::FMINIMUM: {
15184 DCI.AddToWorklist(Elt0.
getNode());
15185 DCI.AddToWorklist(Elt1.
getNode());
15212 if (Vec.
getOpcode() == ISD::BITCAST && VecVT == MVT::v2i32 && Idx) {
15216 if (KImm && KImm->getValueType(0).getSizeInBits() == 64) {
15217 uint64_t KImmValue = KImm->getZExtValue();
15219 (KImmValue >> (32 * Idx->getZExtValue())) & 0xffffffff, SL, MVT::i32);
15222 if (KFPImm && KFPImm->getValueType(0).getSizeInBits() == 64) {
15223 uint64_t KFPImmValue =
15224 KFPImm->getValueAPF().bitcastToAPInt().getZExtValue();
15225 return DAG.
getConstant((KFPImmValue >> (32 * Idx->getZExtValue())) &
15231 if (!DCI.isBeforeLegalize())
15238 VecSize > 32 && VecSize % 32 == 0 && Idx) {
15241 unsigned BitIndex = Idx->getZExtValue() * VecEltSize;
15242 unsigned EltIdx = BitIndex / 32;
15243 unsigned LeftoverBitIdx = BitIndex % 32;
15247 DCI.AddToWorklist(Cast.
getNode());
15251 DCI.AddToWorklist(Elt.
getNode());
15254 DCI.AddToWorklist(Srl.
getNode());
15258 DCI.AddToWorklist(Trunc.
getNode());
15260 if (VecEltVT == ResVT) {
15261 return DAG.
getNode(ISD::BITCAST, SL, VecEltVT, Trunc);
15272SITargetLowering::performInsertVectorEltCombine(
SDNode *
N,
15273 DAGCombinerInfo &DCI)
const {
15284 SelectionDAG &DAG = DCI.DAG;
15303 if (Src.getOpcode() == ISD::FP_EXTEND &&
15304 Src.getOperand(0).getValueType() == MVT::f16) {
15305 return Src.getOperand(0);
15309 APFloat Val = CFP->getValueAPF();
15310 bool LosesInfo =
true;
15320 DAGCombinerInfo &DCI)
const {
15321 assert(Subtarget->has16BitInsts() && !Subtarget->hasMed3_16() &&
15322 "combine only useful on gfx8");
15324 SDValue TruncSrc =
N->getOperand(0);
15325 EVT VT =
N->getValueType(0);
15326 if (VT != MVT::f16)
15333 SelectionDAG &DAG = DCI.DAG;
15361 return DAG.
getNode(ISD::FMINNUM_IEEE, SL, VT, B1, C1);
15364unsigned SITargetLowering::getFusedOpcode(
const SelectionDAG &DAG,
15366 const SDNode *N1)
const {
15371 if (((VT == MVT::f32 &&
15373 (VT == MVT::f16 && Subtarget->hasMadF16() &&
15393 EVT VT =
N->getValueType(0);
15394 if (VT != MVT::i32 && VT != MVT::i64)
15400 unsigned Opc =
N->getOpcode();
15455 if (!Const ||
Hi_32(Const->getZExtValue()) !=
uint32_t(-1))
15474 DAGCombinerInfo &DCI)
const {
15477 SelectionDAG &DAG = DCI.DAG;
15478 EVT VT =
N->getValueType(0);
15488 if (!
N->isDivergent() && Subtarget->hasSMulHi())
15492 if (NumBits <= 32 || NumBits > 64)
15503 if (!Subtarget->hasFullRate64Ops()) {
15504 unsigned NumUsers = 0;
15505 for (SDNode *User :
LHS->
users()) {
15508 if (!
User->isAnyAdd())
15532 bool MulSignedLo =
false;
15533 if (!MulLHSUnsigned32 || !MulRHSUnsigned32) {
15542 if (VT != MVT::i64) {
15565 getMad64_32(DAG, SL, MVT::i64, MulLHSLo, MulRHSLo, AddRHS, MulSignedLo);
15567 if (!MulSignedLo && (!MulLHSUnsigned32 || !MulRHSUnsigned32)) {
15568 auto [AccumLo, AccumHi] = DAG.
SplitScalar(Accum, SL, MVT::i32, MVT::i32);
15570 if (!MulLHSUnsigned32) {
15577 if (!MulRHSUnsigned32) {
15588 if (VT != MVT::i64)
15594SITargetLowering::foldAddSub64WithZeroLowBitsTo32(
SDNode *
N,
15595 DAGCombinerInfo &DCI)
const {
15605 SelectionDAG &DAG = DCI.DAG;
15620 unsigned Opcode =
N->getOpcode();
15621 if (Opcode == ISD::PTRADD)
15624 DAG.
getNode(Opcode, SL, MVT::i32,
Hi, ConstHi32,
N->getFlags());
15635static std::optional<ByteProvider<SDValue>>
15638 if (!Byte0 || Byte0->isConstantZero()) {
15639 return std::nullopt;
15642 if (Byte1 && !Byte1->isConstantZero()) {
15643 return std::nullopt;
15649 unsigned FirstCs =
First & 0x0c0c0c0c;
15650 unsigned SecondCs = Second & 0x0c0c0c0c;
15651 unsigned FirstNoCs =
First & ~0x0c0c0c0c;
15652 unsigned SecondNoCs = Second & ~0x0c0c0c0c;
15654 assert((FirstCs & 0xFF) | (SecondCs & 0xFF));
15655 assert((FirstCs & 0xFF00) | (SecondCs & 0xFF00));
15656 assert((FirstCs & 0xFF0000) | (SecondCs & 0xFF0000));
15657 assert((FirstCs & 0xFF000000) | (SecondCs & 0xFF000000));
15659 return (FirstNoCs | SecondNoCs) | (FirstCs & SecondCs);
15683 for (
int BPI = 0; BPI < 2; BPI++) {
15686 BPP = {Src1, Src0};
15688 unsigned ZeroMask = 0x0c0c0c0c;
15689 unsigned FMask = 0xFF << (8 * (3 - Step));
15691 unsigned FirstMask =
15692 (BPP.first.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask);
15693 unsigned SecondMask =
15694 (BPP.second.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask);
15698 int FirstGroup = -1;
15699 for (
int I = 0;
I < 2;
I++) {
15701 auto MatchesFirst = [&BPP](
DotSrc &IterElt) {
15702 return IterElt.SrcOp == *BPP.first.Src &&
15703 (IterElt.DWordOffset == (BPP.first.SrcOffset / 4));
15707 if (Match != Srcs.
end()) {
15708 Match->PermMask =
addPermMasks(FirstMask, Match->PermMask);
15713 if (FirstGroup != -1) {
15715 auto MatchesSecond = [&BPP](
DotSrc &IterElt) {
15716 return IterElt.SrcOp == *BPP.second.Src &&
15717 (IterElt.DWordOffset == (BPP.second.SrcOffset / 4));
15720 if (Match != Srcs.
end()) {
15721 Match->PermMask =
addPermMasks(SecondMask, Match->PermMask);
15723 Srcs.
push_back({*BPP.second.Src, SecondMask, BPP.second.SrcOffset / 4});
15731 unsigned ZeroMask = 0x0c0c0c0c;
15732 unsigned FMask = 0xFF << (8 * (3 - Step));
15736 ((Src0.
SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask)),
15740 ((Src1.
SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask)),
15749 if (Srcs.
size() == 1) {
15750 auto *Elt = Srcs.
begin();
15754 if (Elt->PermMask == 0x3020100)
15761 auto *FirstElt = Srcs.
begin();
15762 auto *SecondElt = std::next(FirstElt);
15769 auto FirstMask = FirstElt->PermMask;
15770 auto SecondMask = SecondElt->PermMask;
15772 unsigned FirstCs = FirstMask & 0x0c0c0c0c;
15773 unsigned FirstPlusFour = FirstMask | 0x04040404;
15776 FirstMask = (FirstPlusFour & 0x0F0F0F0F) | FirstCs;
15788 FirstElt = std::next(SecondElt);
15789 if (FirstElt == Srcs.
end())
15792 SecondElt = std::next(FirstElt);
15795 if (SecondElt == Srcs.
end()) {
15801 DAG.
getConstant(FirstElt->PermMask, SL, MVT::i32)));
15807 return Perms.
size() == 2
15813 for (
auto &[EntryVal, EntryMask, EntryOffset] : Srcs) {
15814 EntryMask = EntryMask >> ((4 - ChainLength) * 8);
15815 auto ZeroMask = ChainLength == 2 ? 0x0c0c0000 : 0x0c000000;
15816 EntryMask += ZeroMask;
15821 auto Opcode =
Op.getOpcode();
15827static std::optional<bool>
15838 bool S0IsSigned = Known0.countMinLeadingOnes() > 0;
15841 bool S1IsSigned = Known1.countMinLeadingOnes() > 0;
15843 assert(!(S0IsUnsigned && S0IsSigned));
15844 assert(!(S1IsUnsigned && S1IsSigned));
15852 if ((S0IsUnsigned && S1IsUnsigned) || (S0IsSigned && S1IsSigned))
15858 if ((S0IsUnsigned && S1IsSigned) || (S0IsSigned && S1IsUnsigned))
15859 return std::nullopt;
15871 if ((S0IsSigned && !(S1IsSigned || S1IsUnsigned)) ||
15872 ((S1IsSigned && !(S0IsSigned || S0IsUnsigned))))
15877 if ((!(S1IsSigned || S1IsUnsigned) && !(S0IsSigned || S0IsUnsigned)))
15883 if ((S0IsUnsigned && !(S1IsSigned || S1IsUnsigned)) ||
15884 ((S1IsUnsigned && !(S0IsSigned || S0IsUnsigned))))
15885 return std::nullopt;
15891 DAGCombinerInfo &DCI)
const {
15892 SelectionDAG &DAG = DCI.DAG;
15893 EVT VT =
N->getValueType(0);
15899 if (Subtarget->hasMad64_32()) {
15900 if (
SDValue Folded = tryFoldToMad64_32(
N, DCI))
15905 if (
SDValue V = reassociateScalarOps(
N, DAG)) {
15909 if (VT == MVT::i64) {
15910 if (
SDValue Folded = foldAddSub64WithZeroLowBitsTo32(
N, DCI))
15915 (Subtarget->hasDot1Insts() || Subtarget->hasDot8Insts())) {
15917 std::optional<bool> IsSigned;
15923 int ChainLength = 0;
15924 for (
int I = 0;
I < 4;
I++) {
15928 auto Src0 =
handleMulOperand(TempNode->getOperand(MulIdx)->getOperand(0));
15931 auto Src1 =
handleMulOperand(TempNode->getOperand(MulIdx)->getOperand(1));
15936 TempNode->getOperand(MulIdx), *Src0, *Src1,
15937 TempNode->getOperand(MulIdx)->getOperand(0),
15938 TempNode->getOperand(MulIdx)->getOperand(1), DAG);
15942 IsSigned = *IterIsSigned;
15943 if (*IterIsSigned != *IsSigned)
15946 auto AddIdx = 1 - MulIdx;
15949 if (
I == 2 &&
isMul(TempNode->getOperand(AddIdx))) {
15950 Src2s.
push_back(TempNode->getOperand(AddIdx));
15960 TempNode->getOperand(AddIdx), *Src0, *Src1,
15961 TempNode->getOperand(AddIdx)->getOperand(0),
15962 TempNode->getOperand(AddIdx)->getOperand(1), DAG);
15966 if (*IterIsSigned != *IsSigned)
15970 ChainLength =
I + 2;
15974 TempNode = TempNode->getOperand(AddIdx);
15976 ChainLength =
I + 1;
15977 if (TempNode->getNumOperands() < 2)
15979 LHS = TempNode->getOperand(0);
15980 RHS = TempNode->getOperand(1);
15983 if (ChainLength < 2)
15989 if (ChainLength < 4) {
15999 bool UseOriginalSrc =
false;
16000 if (ChainLength == 4 && Src0s.
size() == 1 && Src1s.
size() == 1 &&
16001 Src0s.
begin()->PermMask == Src1s.
begin()->PermMask &&
16002 Src0s.
begin()->SrcOp.getValueSizeInBits() >= 32 &&
16003 Src1s.
begin()->SrcOp.getValueSizeInBits() >= 32) {
16004 SmallVector<unsigned, 4> SrcBytes;
16005 auto Src0Mask = Src0s.
begin()->PermMask;
16006 SrcBytes.
push_back(Src0Mask & 0xFF000000);
16007 bool UniqueEntries =
true;
16008 for (
auto I = 1;
I < 4;
I++) {
16009 auto NextByte = Src0Mask & (0xFF << ((3 -
I) * 8));
16012 UniqueEntries =
false;
16018 if (UniqueEntries) {
16019 UseOriginalSrc =
true;
16021 auto *FirstElt = Src0s.
begin();
16025 auto *SecondElt = Src1s.
begin();
16027 SecondElt->DWordOffset);
16036 if (!UseOriginalSrc) {
16043 DAG.
getExtOrTrunc(*IsSigned, Src2s[ChainLength - 1], SL, MVT::i32);
16046 : Intrinsic::amdgcn_udot4,
16056 if (VT != MVT::i32 || !DCI.isAfterLegalizeDAG())
16061 unsigned Opc =
LHS.getOpcode();
16073 auto Cond =
RHS.getOperand(0);
16078 SDVTList VTList = DAG.
getVTList(MVT::i32, MVT::i1);
16095 DAGCombinerInfo &DCI)
const {
16096 SelectionDAG &DAG = DCI.DAG;
16098 EVT VT =
N->getValueType(0);
16111 SDNodeFlags ShlFlags = N1->
getFlags();
16115 SDNodeFlags NewShlFlags =
16120 DCI.AddToWorklist(Inner.
getNode());
16127 if (Subtarget->hasMad64_32()) {
16128 if (
SDValue Folded = tryFoldToMad64_32(
N, DCI))
16137 if (VT == MVT::i64) {
16138 if (
SDValue Folded = foldAddSub64WithZeroLowBitsTo32(
N, DCI))
16146 if (
const GlobalAddressSDNode *GA =
16151 SDNodeFlags
Flags =
16154 DCI.AddToWorklist(Inner.
getNode());
16182 SDNodeFlags ReassocFlags =
16185 if (ZIsConstant != YIsConstant) {
16189 DCI.AddToWorklist(Inner.
getNode());
16197 assert(!YIsConstant && !ZIsConstant);
16199 if (!
X->isDivergent() &&
Y->isDivergent() !=
Z->isDivergent()) {
16208 if (
Y->isDivergent())
16211 DCI.AddToWorklist(UniformInner.
getNode());
16219 DAGCombinerInfo &DCI)
const {
16220 SelectionDAG &DAG = DCI.DAG;
16221 EVT VT =
N->getValueType(0);
16223 if (VT == MVT::i64) {
16224 if (
SDValue Folded = foldAddSub64WithZeroLowBitsTo32(
N, DCI))
16228 if (VT != MVT::i32)
16237 unsigned Opc =
RHS.getOpcode();
16244 auto Cond =
RHS.getOperand(0);
16249 SDVTList VTList = DAG.
getVTList(MVT::i32, MVT::i1);
16267SITargetLowering::performAddCarrySubCarryCombine(
SDNode *
N,
16268 DAGCombinerInfo &DCI)
const {
16270 if (
N->getValueType(0) != MVT::i32)
16276 SelectionDAG &DAG = DCI.DAG;
16281 unsigned LHSOpc =
LHS.getOpcode();
16282 unsigned Opc =
N->getOpcode();
16286 return DAG.
getNode(
Opc, SDLoc(
N),
N->getVTList(), Args);
16292 DAGCombinerInfo &DCI)
const {
16296 SelectionDAG &DAG = DCI.DAG;
16297 EVT VT =
N->getValueType(0);
16309 if (
A ==
LHS.getOperand(1)) {
16310 unsigned FusedOp = getFusedOpcode(DAG,
N,
LHS.getNode());
16311 if (FusedOp != 0) {
16313 return DAG.
getNode(FusedOp, SL, VT,
A, Two,
RHS);
16321 if (
A ==
RHS.getOperand(1)) {
16322 unsigned FusedOp = getFusedOpcode(DAG,
N,
RHS.getNode());
16323 if (FusedOp != 0) {
16325 return DAG.
getNode(FusedOp, SL, VT,
A, Two,
LHS);
16334 DAGCombinerInfo &DCI)
const {
16338 SelectionDAG &DAG = DCI.DAG;
16340 EVT VT =
N->getValueType(0);
16353 if (
A ==
LHS.getOperand(1)) {
16354 unsigned FusedOp = getFusedOpcode(DAG,
N,
LHS.getNode());
16355 if (FusedOp != 0) {
16359 return DAG.
getNode(FusedOp, SL, VT,
A, Two, NegRHS);
16368 if (
A ==
RHS.getOperand(1)) {
16369 unsigned FusedOp = getFusedOpcode(DAG,
N,
RHS.getNode());
16370 if (FusedOp != 0) {
16372 return DAG.
getNode(FusedOp, SL, VT,
A, NegTwo,
LHS);
16381 DAGCombinerInfo &DCI)
const {
16382 SelectionDAG &DAG = DCI.DAG;
16384 EVT VT =
N->getValueType(0);
16385 if ((VT != MVT::f16 && VT != MVT::bf16) || !Subtarget->has16BitInsts())
16391 SDNodeFlags
Flags =
N->getFlags();
16392 SDNodeFlags RHSFlags =
RHS->getFlags();
16398 bool IsNegative =
false;
16399 if (CLHS->isExactlyValue(1.0) ||
16400 (IsNegative = CLHS->isExactlyValue(-1.0))) {
16403 if (
RHS.getOpcode() == ISD::FSQRT) {
16407 return IsNegative ? DAG.
getNode(ISD::FNEG, SL, VT, Rsq, Flags) : Rsq;
16416 DAGCombinerInfo &DCI)
const {
16417 SelectionDAG &DAG = DCI.DAG;
16418 EVT VT =
N->getValueType(0);
16422 if (!
N->isDivergent() &&
getSubtarget()->hasSALUFloatInsts() &&
16423 (ScalarVT == MVT::f32 || ScalarVT == MVT::f16)) {
16438 if ((ScalarVT == MVT::f64 || ScalarVT == MVT::f32 || ScalarVT == MVT::f16) &&
16443 const ConstantFPSDNode *FalseNode =
16453 if (ScalarVT == MVT::f32 &&
16459 if (TrueNodeExpVal == INT_MIN)
16462 if (FalseNodeExpVal == INT_MIN)
16475 return DAG.
getNode(ISD::FLDEXP, SL, VT,
LHS, SelectNode,
N->getFlags());
16482 DAGCombinerInfo &DCI)
const {
16483 SelectionDAG &DAG = DCI.DAG;
16484 EVT VT =
N->getValueType(0);
16487 if (!Subtarget->hasDot10Insts() || VT != MVT::f32)
16505 (
N->getFlags().hasAllowContract() &&
16506 FMA->getFlags().hasAllowContract())) {
16521 if (FMAOp1.
getOpcode() != ISD::FP_EXTEND ||
16540 if (Vec1 == Vec2 || Vec3 == Vec4)
16546 if ((Vec1 == Vec3 && Vec2 == Vec4) || (Vec1 == Vec4 && Vec2 == Vec3)) {
16555 DAGCombinerInfo &DCI)
const {
16556 SelectionDAG &DAG = DCI.DAG;
16561 EVT VT =
LHS.getValueType();
16590 return LHS.getOperand(0);
16598 LHS.getConstantOperandVal(1) !=
LHS.getConstantOperandVal(2) &&
16605 const APInt &CT =
LHS.getConstantOperandAPInt(1);
16606 const APInt &CF =
LHS.getConstantOperandAPInt(2);
16614 return LHS.getOperand(0);
16618 if (VT != MVT::f32 && VT != MVT::f64 &&
16619 (!Subtarget->has16BitInsts() || VT != MVT::f16))
16627 LHS.getOpcode() == ISD::FABS) {
16634 const unsigned IsInfMask =
16636 const unsigned IsFiniteMask =
16650SITargetLowering::performCvtF32UByteNCombine(
SDNode *
N,
16651 DAGCombinerInfo &DCI)
const {
16652 SelectionDAG &DAG = DCI.DAG;
16673 unsigned ShiftOffset = 8 *
Offset;
16675 ShiftOffset -=
C->getZExtValue();
16677 ShiftOffset +=
C->getZExtValue();
16679 if (ShiftOffset < 32 && (ShiftOffset % 8) == 0) {
16681 MVT::f32, Shifted);
16692 DCI.AddToWorklist(
N);
16699 return DAG.
getNode(
N->getOpcode(), SL, MVT::f32, DemandedSrc);
16705 DAGCombinerInfo &DCI)
const {
16710 const MachineFunction &MF = DCI.DAG.getMachineFunction();
16714 (
F.isNaN() && MF.
getInfo<SIMachineFunctionInfo>()->getMode().DX10Clamp)) {
16715 return DCI.DAG.getConstantFP(Zero, SDLoc(
N),
N->getValueType(0));
16718 APFloat One(
F.getSemantics(),
"1.0");
16720 return DCI.DAG.getConstantFP(One, SDLoc(
N),
N->getValueType(0));
16726 DAGCombinerInfo &DCI)
const {
16747 bool isFloatingPoint =
LHS.getValueType().isFloatingPoint();
16748 bool isInteger =
LHS.getValueType().isInteger();
16751 if (!isFloatingPoint && !isInteger)
16756 if (!isEquality && !isNonEquality)
16773 if (isFloatingPoint) {
16775 if (!Val.
isNormal() || Subtarget->getInstrInfo()->isInlineConstant(Val))
16786 if (!(isEquality && TrueVal == ConstVal) &&
16787 !(isNonEquality && FalseVal == ConstVal))
16794 SelectLHS, SelectRHS);
16799 switch (
N->getOpcode()) {
16815 if (
auto Res = promoteUniformOpToI32(
SDValue(
N, 0), DCI))
16825 switch (
N->getOpcode()) {
16827 return performAddCombine(
N, DCI);
16829 return performPtrAddCombine(
N, DCI);
16831 return performSubCombine(
N, DCI);
16834 return performAddCarrySubCarryCombine(
N, DCI);
16836 return performFAddCombine(
N, DCI);
16838 return performFSubCombine(
N, DCI);
16840 return performFDivCombine(
N, DCI);
16842 return performFMulCombine(
N, DCI);
16844 return performSetCCCombine(
N, DCI);
16846 if (
auto Res = performSelectCombine(
N, DCI))
16851 case ISD::FMAXNUM_IEEE:
16852 case ISD::FMINNUM_IEEE:
16853 case ISD::FMAXIMUM:
16854 case ISD::FMINIMUM:
16855 case ISD::FMAXIMUMNUM:
16856 case ISD::FMINIMUMNUM:
16863 return performMinMaxCombine(
N, DCI);
16865 return performFMACombine(
N, DCI);
16867 return performAndCombine(
N, DCI);
16869 return performOrCombine(
N, DCI);
16872 if (
N->getValueType(0) == MVT::i32 &&
N->isDivergent() &&
16873 TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
16879 return performXorCombine(
N, DCI);
16881 return performZeroExtendCombine(
N, DCI);
16883 return performSignExtendInRegCombine(
N, DCI);
16885 return performClassCombine(
N, DCI);
16887 return performFCanonicalizeCombine(
N, DCI);
16889 return performRcpCombine(
N, DCI);
16904 return performUCharToFloatCombine(
N, DCI);
16906 return performFCopySignCombine(
N, DCI);
16911 return performCvtF32UByteNCombine(
N, DCI);
16913 return performFMed3Combine(
N, DCI);
16915 return performCvtPkRTZCombine(
N, DCI);
16917 return performClampCombine(
N, DCI);
16920 EVT VT =
N->getValueType(0);
16923 if (VT == MVT::v2i16 || VT == MVT::v2f16 || VT == MVT::v2bf16) {
16926 EVT EltVT = Src.getValueType();
16927 if (EltVT != MVT::i16)
16928 Src = DAG.
getNode(ISD::BITCAST, SL, MVT::i16, Src);
16931 return DAG.
getNode(ISD::BITCAST, SL, VT, Ext);
16937 return performExtractVectorEltCombine(
N, DCI);
16939 return performInsertVectorEltCombine(
N, DCI);
16941 return performFPRoundCombine(
N, DCI);
16950 return performMemSDNodeCombine(MemNode, DCI);
16981 unsigned Opcode =
Node->getMachineOpcode();
16984 int D16Idx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::d16) - 1;
16985 if (D16Idx >= 0 &&
Node->getConstantOperandVal(D16Idx))
16988 SDNode *
Users[5] = {
nullptr};
16990 unsigned DmaskIdx =
16991 AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::dmask) - 1;
16992 unsigned OldDmask =
Node->getConstantOperandVal(DmaskIdx);
16993 unsigned NewDmask = 0;
16994 unsigned TFEIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::tfe) - 1;
16995 unsigned LWEIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::lwe) - 1;
16996 bool UsesTFC = (int(TFEIdx) >= 0 &&
Node->getConstantOperandVal(TFEIdx)) ||
16997 (
int(LWEIdx) >= 0 &&
Node->getConstantOperandVal(LWEIdx));
16998 unsigned TFCLane = 0;
16999 bool HasChain =
Node->getNumValues() > 1;
17001 if (OldDmask == 0) {
17009 TFCLane = OldBitsSet;
17013 for (SDUse &Use :
Node->uses()) {
17016 if (
Use.getResNo() != 0)
17019 SDNode *
User =
Use.getUser();
17022 if (!
User->isMachineOpcode() ||
17023 User->getMachineOpcode() != TargetOpcode::EXTRACT_SUBREG)
17035 if (UsesTFC && Lane == TFCLane) {
17040 for (
unsigned i = 0, Dmask = OldDmask; (i <= Lane) && (Dmask != 0); i++) {
17042 Dmask &= ~(1 << Comp);
17050 NewDmask |= 1 << Comp;
17055 bool NoChannels = !NewDmask;
17062 if (OldBitsSet == 1)
17068 if (NewDmask == OldDmask)
17077 unsigned NewChannels = BitsSet + UsesTFC;
17081 assert(NewOpcode != -1 &&
17082 NewOpcode !=
static_cast<int>(
Node->getMachineOpcode()) &&
17083 "failed to find equivalent MIMG op");
17091 MVT SVT =
Node->getValueType(0).getVectorElementType().getSimpleVT();
17093 MVT ResultVT = NewChannels == 1
17096 : NewChannels == 5 ? 8
17098 SDVTList NewVTList =
17101 MachineSDNode *NewNode =
17110 if (NewChannels == 1) {
17120 for (
unsigned i = 0, Idx = AMDGPU::sub0; i < 5; ++i) {
17125 if (i || !NoChannels)
17130 if (NewUser != User) {
17140 Idx = AMDGPU::sub1;
17143 Idx = AMDGPU::sub2;
17146 Idx = AMDGPU::sub3;
17149 Idx = AMDGPU::sub4;
17160 Op =
Op.getOperand(0);
17181 MRI.createVirtualRegister(&AMDGPU::VReg_1RegClass), MVT::i1);
17185 Node->getOperand(0), SL, VReg, SrcVal,
17191 return ToResultReg.
getNode();
17196 for (
unsigned i = 0; i <
Node->getNumOperands(); ++i) {
17198 Ops.push_back(
Node->getOperand(i));
17204 Node->getOperand(i).getValueType(),
17205 Node->getOperand(i)),
17217 unsigned Opcode =
Node->getMachineOpcode();
17219 if (
TII->isImage(Opcode) && !
TII->get(Opcode).mayStore() &&
17220 !
TII->isGather4(Opcode) &&
17222 return adjustWritemask(
Node, DAG);
17225 if (Opcode == AMDGPU::INSERT_SUBREG || Opcode == AMDGPU::REG_SEQUENCE) {
17231 case AMDGPU::V_DIV_SCALE_F32_e64:
17232 case AMDGPU::V_DIV_SCALE_F64_e64: {
17242 (Src0 == Src1 || Src0 == Src2))
17298 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::vdata);
17299 unsigned InitIdx = 0;
17301 if (
TII->isImage(
MI)) {
17309 unsigned TFEVal = TFE ? TFE->
getImm() : 0;
17310 unsigned LWEVal = LWE ? LWE->
getImm() : 0;
17311 unsigned D16Val = D16 ? D16->getImm() : 0;
17313 if (!TFEVal && !LWEVal)
17324 assert(MO_Dmask &&
"Expected dmask operand in instruction");
17326 unsigned dmask = MO_Dmask->
getImm();
17331 bool Packed = !Subtarget->hasUnpackedD16VMem();
17333 InitIdx = D16Val && Packed ? ((ActiveLanes + 1) >> 1) + 1 : ActiveLanes + 1;
17339 TRI.getRegSizeInBits(*
TII->getOpRegClass(
MI, DstIdx)) / 32;
17340 if (DstSize < InitIdx)
17343 InitIdx =
TRI.getRegSizeInBits(*
TII->getOpRegClass(
MI, DstIdx)) / 32;
17351 Register PrevDst =
MRI.cloneVirtualRegister(
MI.getOperand(DstIdx).getReg());
17352 unsigned NewDst = 0;
17357 unsigned SizeLeft = Subtarget->usePRTStrictNull() ? InitIdx : 1;
17358 unsigned CurrIdx = Subtarget->usePRTStrictNull() ? 0 : (InitIdx - 1);
17361 for (; SizeLeft; SizeLeft--, CurrIdx++) {
17362 NewDst =
MRI.createVirtualRegister(
TII->getOpRegClass(
MI, DstIdx));
17382 MI.tieOperands(DstIdx,
MI.getNumOperands() - 1);
17395 if (
TII->isVOP3(
MI.getOpcode())) {
17397 TII->legalizeOperandsVOP3(
MRI,
MI);
17402 if (!
MI.getDesc().operands().empty()) {
17403 unsigned Opc =
MI.getOpcode();
17404 bool HasAGPRs = Info->mayNeedAGPRs();
17406 int16_t Src2Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src2);
17408 {AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0),
17409 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src1), Src2Idx}) {
17412 if ((
I == Src2Idx) && (HasAGPRs))
17415 if (!
Op.isReg() || !
Op.getReg().isVirtual())
17417 auto *RC =
TRI->getRegClassForReg(
MRI,
Op.getReg());
17418 if (!
TRI->hasAGPRs(RC))
17420 auto *Src =
MRI.getUniqueVRegDef(
Op.getReg());
17421 if (!Src || !Src->isCopy() ||
17422 !
TRI->isSGPRReg(
MRI, Src->getOperand(1).getReg()))
17424 auto *NewRC =
TRI->getEquivalentVGPRClass(RC);
17428 MRI.setRegClass(
Op.getReg(), NewRC);
17431 if (
TII->isMAI(
MI)) {
17436 int Src0Idx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(),
17437 AMDGPU::OpName::scale_src0);
17438 if (Src0Idx != -1) {
17439 int Src1Idx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(),
17440 AMDGPU::OpName::scale_src1);
17441 if (
TII->usesConstantBus(
MRI,
MI, Src0Idx) &&
17442 TII->usesConstantBus(
MRI,
MI, Src1Idx))
17443 TII->legalizeOpWithMove(
MI, Src1Idx);
17451 if (
auto *Src2 =
TII->getNamedOperand(
MI, AMDGPU::OpName::src2)) {
17452 if (Src2->isReg() && Src2->getReg().isVirtual()) {
17453 auto *RC =
TRI->getRegClassForReg(
MRI, Src2->getReg());
17454 if (
TRI->isVectorSuperClass(RC)) {
17455 auto *NewRC =
TRI->getEquivalentAGPRClass(RC);
17456 MRI.setRegClass(Src2->getReg(), NewRC);
17457 if (Src2->isTied())
17458 MRI.setRegClass(
MI.getOperand(0).getReg(), NewRC);
17467 if (
TII->isImage(
MI))
17468 TII->enforceOperandRCAlignment(
MI, AMDGPU::OpName::vaddr);
17542std::pair<unsigned, const TargetRegisterClass *>
17549 if (Constraint.
size() == 1) {
17553 if (VT == MVT::Other)
17556 switch (Constraint[0]) {
17563 RC = &AMDGPU::SReg_32RegClass;
17566 RC = &AMDGPU::SGPR_64RegClass;
17571 return std::pair(0U,
nullptr);
17578 RC = Subtarget->useRealTrue16Insts() ? &AMDGPU::VGPR_16RegClass
17579 : &AMDGPU::VGPR_32_Lo256RegClass;
17582 RC = Subtarget->has1024AddressableVGPRs()
17583 ?
TRI->getAlignedLo256VGPRClassForBitWidth(
BitWidth)
17586 return std::pair(0U,
nullptr);
17591 if (!Subtarget->hasMAIInsts())
17595 RC = &AMDGPU::AGPR_32RegClass;
17600 return std::pair(0U,
nullptr);
17605 }
else if (Constraint ==
"VA" && Subtarget->hasGFX90AInsts()) {
17609 RC = &AMDGPU::AV_32RegClass;
17612 RC =
TRI->getVectorSuperClassForBitWidth(
BitWidth);
17614 return std::pair(0U,
nullptr);
17623 return std::pair(0U, RC);
17626 if (Kind !=
'\0') {
17628 RC = &AMDGPU::VGPR_32_Lo256RegClass;
17629 }
else if (Kind ==
's') {
17630 RC = &AMDGPU::SGPR_32RegClass;
17631 }
else if (Kind ==
'a') {
17632 RC = &AMDGPU::AGPR_32RegClass;
17638 return std::pair(0U,
nullptr);
17644 return std::pair(0U,
nullptr);
17648 RC =
TRI->getVGPRClassForBitWidth(Width);
17650 RC =
TRI->getSGPRClassForBitWidth(Width);
17652 RC =
TRI->getAGPRClassForBitWidth(Width);
17654 Reg =
TRI->getMatchingSuperReg(Reg, AMDGPU::sub0, RC);
17659 return std::pair(0U,
nullptr);
17661 return std::pair(Reg, RC);
17667 return std::pair(0U,
nullptr);
17668 if (Idx < RC->getNumRegs())
17670 return std::pair(0U,
nullptr);
17676 Ret.second =
TRI->getPhysRegBaseClass(Ret.first);
17682 if (Constraint.
size() == 1) {
17683 switch (Constraint[0]) {
17693 }
else if (Constraint ==
"DA" || Constraint ==
"DB") {
17701 if (Constraint.
size() == 1) {
17702 switch (Constraint[0]) {
17710 }
else if (Constraint.
size() == 2) {
17711 if (Constraint ==
"VA")
17729 std::vector<SDValue> &
Ops,
17744 unsigned Size =
Op.getScalarValueSizeInBits();
17748 if (
Size == 16 && !Subtarget->has16BitInsts())
17752 Val =
C->getSExtValue();
17756 Val =
C->getValueAPF().bitcastToAPInt().getSExtValue();
17760 if (
Size != 16 ||
Op.getNumOperands() != 2)
17762 if (
Op.getOperand(0).isUndef() ||
Op.getOperand(1).isUndef())
17765 Val =
C->getSExtValue();
17769 Val =
C->getValueAPF().bitcastToAPInt().getSExtValue();
17779 if (Constraint.
size() == 1) {
17780 switch (Constraint[0]) {
17795 }
else if (Constraint.
size() == 2) {
17796 if (Constraint ==
"DA") {
17797 int64_t HiBits =
static_cast<int32_t
>(Val >> 32);
17798 int64_t LoBits =
static_cast<int32_t
>(Val);
17802 if (Constraint ==
"DB") {
17810 unsigned MaxSize)
const {
17811 unsigned Size = std::min<unsigned>(
Op.getScalarValueSizeInBits(), MaxSize);
17812 bool HasInv2Pi = Subtarget->hasInv2PiInlineImm();
17814 MVT VT =
Op.getSimpleValueType();
17839 switch (UnalignedClassID) {
17840 case AMDGPU::VReg_64RegClassID:
17841 return AMDGPU::VReg_64_Align2RegClassID;
17842 case AMDGPU::VReg_96RegClassID:
17843 return AMDGPU::VReg_96_Align2RegClassID;
17844 case AMDGPU::VReg_128RegClassID:
17845 return AMDGPU::VReg_128_Align2RegClassID;
17846 case AMDGPU::VReg_160RegClassID:
17847 return AMDGPU::VReg_160_Align2RegClassID;
17848 case AMDGPU::VReg_192RegClassID:
17849 return AMDGPU::VReg_192_Align2RegClassID;
17850 case AMDGPU::VReg_224RegClassID:
17851 return AMDGPU::VReg_224_Align2RegClassID;
17852 case AMDGPU::VReg_256RegClassID:
17853 return AMDGPU::VReg_256_Align2RegClassID;
17854 case AMDGPU::VReg_288RegClassID:
17855 return AMDGPU::VReg_288_Align2RegClassID;
17856 case AMDGPU::VReg_320RegClassID:
17857 return AMDGPU::VReg_320_Align2RegClassID;
17858 case AMDGPU::VReg_352RegClassID:
17859 return AMDGPU::VReg_352_Align2RegClassID;
17860 case AMDGPU::VReg_384RegClassID:
17861 return AMDGPU::VReg_384_Align2RegClassID;
17862 case AMDGPU::VReg_512RegClassID:
17863 return AMDGPU::VReg_512_Align2RegClassID;
17864 case AMDGPU::VReg_1024RegClassID:
17865 return AMDGPU::VReg_1024_Align2RegClassID;
17866 case AMDGPU::AReg_64RegClassID:
17867 return AMDGPU::AReg_64_Align2RegClassID;
17868 case AMDGPU::AReg_96RegClassID:
17869 return AMDGPU::AReg_96_Align2RegClassID;
17870 case AMDGPU::AReg_128RegClassID:
17871 return AMDGPU::AReg_128_Align2RegClassID;
17872 case AMDGPU::AReg_160RegClassID:
17873 return AMDGPU::AReg_160_Align2RegClassID;
17874 case AMDGPU::AReg_192RegClassID:
17875 return AMDGPU::AReg_192_Align2RegClassID;
17876 case AMDGPU::AReg_256RegClassID:
17877 return AMDGPU::AReg_256_Align2RegClassID;
17878 case AMDGPU::AReg_512RegClassID:
17879 return AMDGPU::AReg_512_Align2RegClassID;
17880 case AMDGPU::AReg_1024RegClassID:
17881 return AMDGPU::AReg_1024_Align2RegClassID;
17897 if (Info->isEntryFunction()) {
17904 unsigned MaxNumSGPRs = ST.getMaxNumSGPRs(MF);
17906 ? AMDGPU::SGPR_32RegClass.getRegister(MaxNumSGPRs - 1)
17907 :
TRI->getAlignedHighSGPRForRC(MF, 2,
17908 &AMDGPU::SGPR_64RegClass);
17909 Info->setSGPRForEXECCopy(SReg);
17911 assert(!
TRI->isSubRegister(Info->getScratchRSrcReg(),
17912 Info->getStackPtrOffsetReg()));
17913 if (Info->getStackPtrOffsetReg() != AMDGPU::SP_REG)
17914 MRI.replaceRegWith(AMDGPU::SP_REG, Info->getStackPtrOffsetReg());
17918 if (Info->getScratchRSrcReg() != AMDGPU::PRIVATE_RSRC_REG)
17919 MRI.replaceRegWith(AMDGPU::PRIVATE_RSRC_REG, Info->getScratchRSrcReg());
17921 if (Info->getFrameOffsetReg() != AMDGPU::FP_REG)
17922 MRI.replaceRegWith(AMDGPU::FP_REG, Info->getFrameOffsetReg());
17924 Info->limitOccupancy(MF);
17926 if (ST.isWave32() && !MF.
empty()) {
17927 for (
auto &
MBB : MF) {
17928 for (
auto &
MI :
MBB) {
17929 TII->fixImplicitOperands(
MI);
17939 if (ST.needsAlignedVGPRs()) {
17940 for (
unsigned I = 0, E =
MRI.getNumVirtRegs();
I != E; ++
I) {
17946 if (NewClassID != -1)
17947 MRI.setRegClass(Reg,
TRI->getRegClass(NewClassID));
17956 const APInt &DemandedElts,
17958 unsigned Depth)
const {
17960 unsigned Opc =
Op.getOpcode();
17963 unsigned IID =
Op.getConstantOperandVal(0);
17965 case Intrinsic::amdgcn_mbcnt_lo:
17966 case Intrinsic::amdgcn_mbcnt_hi: {
17972 IID == Intrinsic::amdgcn_mbcnt_lo ? ST.getWavefrontSizeLog2() : 5);
17982 Op, Known, DemandedElts, DAG,
Depth);
17998 unsigned MaxValue =
18005 unsigned BFEWidth,
bool SExt,
unsigned Depth) {
18009 unsigned Src1Cst = 0;
18010 if (Src1.
isImm()) {
18011 Src1Cst = Src1.
getImm();
18012 }
else if (Src1.
isReg()) {
18016 Src1Cst = Cst->Value.getZExtValue();
18027 if (Width >= BFEWidth)
18036 Known = Known.
sext(BFEWidth);
18038 Known = Known.
zext(BFEWidth);
18044 unsigned Depth)
const {
18047 switch (
MI->getOpcode()) {
18048 case AMDGPU::S_BFE_I32:
18051 case AMDGPU::S_BFE_U32:
18054 case AMDGPU::S_BFE_I64:
18057 case AMDGPU::S_BFE_U64:
18060 case AMDGPU::G_INTRINSIC:
18061 case AMDGPU::G_INTRINSIC_CONVERGENT: {
18064 case Intrinsic::amdgcn_workitem_id_x:
18067 case Intrinsic::amdgcn_workitem_id_y:
18070 case Intrinsic::amdgcn_workitem_id_z:
18073 case Intrinsic::amdgcn_mbcnt_lo:
18074 case Intrinsic::amdgcn_mbcnt_hi: {
18086 case Intrinsic::amdgcn_groupstaticsize: {
18097 case AMDGPU::G_AMDGPU_BUFFER_LOAD_UBYTE:
18100 case AMDGPU::G_AMDGPU_BUFFER_LOAD_USHORT:
18103 case AMDGPU::G_AMDGPU_SMED3:
18104 case AMDGPU::G_AMDGPU_UMED3: {
18105 auto [Dst, Src0, Src1, Src2] =
MI->getFirst4Regs();
18132 unsigned Depth)
const {
18139 AttributeList Attrs =
18141 if (
MaybeAlign RetAlign = Attrs.getRetAlignment())
18168 if (Header->getAlignment() != PrefAlign)
18169 return Header->getAlignment();
18171 unsigned LoopSize = 0;
18176 LoopSize +=
MBB->getAlignment().value() / 2;
18179 LoopSize +=
TII->getInstSizeInBytes(
MI);
18180 if (LoopSize > 192)
18185 if (LoopSize <= 64)
18188 if (LoopSize <= 128)
18189 return CacheLineAlign;
18195 auto I = Exit->getFirstNonDebugInstr();
18196 if (
I != Exit->end() &&
I->getOpcode() == AMDGPU::S_INST_PREFETCH)
18197 return CacheLineAlign;
18206 if (PreTerm == Pre->
begin() ||
18207 std::prev(PreTerm)->getOpcode() != AMDGPU::S_INST_PREFETCH)
18211 auto ExitHead = Exit->getFirstNonDebugInstr();
18212 if (ExitHead == Exit->end() ||
18213 ExitHead->getOpcode() != AMDGPU::S_INST_PREFETCH)
18218 return CacheLineAlign;
18226 N =
N->getOperand(0).getNode();
18227 if (
N->getOpcode() == ISD::INLINEASM ||
N->getOpcode() == ISD::INLINEASM_BR)
18236 switch (
N->getOpcode()) {
18244 if (Reg.isPhysical() ||
MRI.isLiveIn(Reg))
18245 return !
TRI->isSGPRReg(
MRI, Reg);
18251 return !
TRI->isSGPRReg(
MRI, Reg);
18255 unsigned AS = L->getAddressSpace();
18259 case ISD::CALLSEQ_END:
18288 return A->readMem() &&
A->writeMem();
18309 switch (Ty.getScalarSizeInBits()) {
18321 const APInt &DemandedElts,
18324 unsigned Depth)
const {
18329 if (Info->getMode().DX10Clamp)
18341 if (RMW->
hasMetadata(
"amdgpu.ignore.denormal.mode"))
18361 <<
"Hardware instruction generated for atomic "
18363 <<
" operation at memory scope " << MemScope;
18368 Type *EltTy = VT->getElementType();
18369 return VT->getNumElements() == 2 &&
18389 unsigned BW =
IT->getBitWidth();
18390 return BW == 32 || BW == 64;
18404 unsigned BW =
DL.getPointerSizeInBits(PT->getAddressSpace());
18405 return BW == 32 || BW == 64;
18408 if (Ty->isFloatTy() || Ty->isDoubleTy())
18412 return VT->getNumElements() == 2 &&
18413 VT->getElementType()->getPrimitiveSizeInBits() == 16;
18423 bool HasSystemScope) {
18430 if (HasSystemScope) {
18439 return RMW->
hasMetadata(
"amdgpu.no.fine.grained.memory");
18452 const MDNode *MD =
I->getMetadata(LLVMContext::MD_noalias_addrspace);
18478 DL.getTypeSizeInBits(RMW->
getType()) == 64 &&
18491 bool HasSystemScope =
18517 if (Subtarget->hasEmulatedSystemScopeAtomics())
18533 if (!HasSystemScope &&
18534 Subtarget->supportsAgentScopeFineGrainedRemoteMemoryAtomics())
18546 if (RMW->
hasMetadata(
"amdgpu.no.fine.grained.memory"))
18554 ConstVal && ConstVal->isNullValue())
18592 if (Ty->isFloatTy()) {
18597 if (Ty->isDoubleTy()) {
18618 if (Ty->isFloatTy() &&
18619 !Subtarget->hasMemoryAtomicFaddF32DenormalSupport() &&
18632 if (Subtarget->hasAtomicBufferGlobalPkAddF16Insts() &&
isV2F16(Ty))
18636 if (Subtarget->hasAtomicGlobalPkAddBF16Inst() &&
isV2BF16(Ty))
18640 if (Subtarget->hasAtomicBufferGlobalPkAddF16Insts() &&
isV2F16(Ty))
18645 if (Subtarget->hasAtomicBufferPkAddBF16Inst() &&
isV2BF16(Ty))
18650 if (Subtarget->hasFlatBufferGlobalAtomicFaddF64Inst() && Ty->isDoubleTy())
18654 if (Ty->isFloatTy()) {
18657 if (RMW->
use_empty() && Subtarget->hasAtomicFaddNoRtnInsts())
18660 if (!RMW->
use_empty() && Subtarget->hasAtomicFaddRtnInsts())
18665 Subtarget->hasAtomicBufferGlobalPkAddF16NoRtnInsts() &&
18673 if (Subtarget->hasFlatAtomicFaddF32Inst())
18682 if (Subtarget->hasLDSFPAtomicAddF32()) {
18683 if (RMW->
use_empty() && Subtarget->hasAtomicFaddNoRtnInsts())
18685 if (!RMW->
use_empty() && Subtarget->hasAtomicFaddRtnInsts())
18713 if (Subtarget->hasAtomicFMinFMaxF32FlatInsts() && Ty->isFloatTy())
18715 if (Subtarget->hasAtomicFMinFMaxF64FlatInsts() && Ty->isDoubleTy())
18719 if (Subtarget->hasAtomicFMinFMaxF32GlobalInsts() && Ty->isFloatTy())
18721 if (Subtarget->hasAtomicFMinFMaxF64GlobalInsts() && Ty->isDoubleTy())
18774 if (RC == &AMDGPU::VReg_1RegClass && !isDivergent)
18775 return Subtarget->isWave64() ? &AMDGPU::SReg_64RegClass
18776 : &AMDGPU::SReg_32RegClass;
18777 if (!
TRI->isSGPRClass(RC) && !isDivergent)
18778 return TRI->getEquivalentSGPRClass(RC);
18779 if (
TRI->isSGPRClass(RC) && isDivergent)
18780 return TRI->getEquivalentVGPRClass(RC);
18792 unsigned WaveSize) {
18797 if (!
IT ||
IT->getBitWidth() != WaveSize)
18802 if (!Visited.
insert(V).second)
18804 bool Result =
false;
18805 for (
const auto *U : V->users()) {
18807 if (V == U->getOperand(1)) {
18812 case Intrinsic::amdgcn_if_break:
18813 case Intrinsic::amdgcn_if:
18814 case Intrinsic::amdgcn_else:
18819 if (V == U->getOperand(0)) {
18824 case Intrinsic::amdgcn_end_cf:
18825 case Intrinsic::amdgcn_loop:
18831 Result =
hasCFUser(U, Visited, WaveSize);
18840 const Value *V)
const {
18842 if (CI->isInlineAsm()) {
18851 for (
auto &TC : TargetConstraints) {
18865 return hasCFUser(V, Visited, Subtarget->getWavefrontSize());
18893 return MRI.hasOneNonDBGUse(N0);
18900 if (
I.getMetadata(
"amdgpu.noclobber"))
18902 if (
I.getMetadata(
"amdgpu.last.use"))
18912 if (!Def->isMachineOpcode())
18922 if (
II.isCompare() &&
II.hasImplicitDefOfPhysReg(AMDGPU::SCC)) {
18923 PhysReg = AMDGPU::SCC;
18925 TRI->getMinimalPhysRegClass(PhysReg, Def->getSimpleValueType(ResNo));
18991 Alignment = RMW->getAlign();
19004 bool FullFlatEmulation =
19006 ((Subtarget->hasAtomicFaddInsts() && RMW->getType()->isFloatTy()) ||
19007 (Subtarget->hasFlatBufferGlobalAtomicFaddF64Inst() &&
19008 RMW->getType()->isDoubleTy()));
19011 bool ReturnValueIsUsed = !AI->
use_empty();
19020 if (FullFlatEmulation) {
19031 std::prev(BB->
end())->eraseFromParent();
19032 Builder.SetInsertPoint(BB);
19034 Value *LoadedShared =
nullptr;
19035 if (FullFlatEmulation) {
19036 CallInst *IsShared = Builder.CreateIntrinsic(Intrinsic::amdgcn_is_shared,
19037 {Addr},
nullptr,
"is.shared");
19038 Builder.CreateCondBr(IsShared, SharedBB, CheckPrivateBB);
19039 Builder.SetInsertPoint(SharedBB);
19040 Value *CastToLocal = Builder.CreateAddrSpaceCast(
19046 LoadedShared = Clone;
19048 Builder.CreateBr(PhiBB);
19049 Builder.SetInsertPoint(CheckPrivateBB);
19052 CallInst *IsPrivate = Builder.CreateIntrinsic(Intrinsic::amdgcn_is_private,
19053 {Addr},
nullptr,
"is.private");
19054 Builder.CreateCondBr(IsPrivate, PrivateBB, GlobalBB);
19056 Builder.SetInsertPoint(PrivateBB);
19058 Value *CastToPrivate = Builder.CreateAddrSpaceCast(
19061 Value *LoadedPrivate;
19063 LoadedPrivate = Builder.CreateAlignedLoad(
19064 RMW->getType(), CastToPrivate, RMW->getAlign(),
"loaded.private");
19067 LoadedPrivate, RMW->getValOperand());
19069 Builder.CreateAlignedStore(NewVal, CastToPrivate, RMW->getAlign());
19071 auto [ResultLoad, Equal] =
19077 LoadedPrivate = Builder.CreateInsertValue(Insert, Equal, 1);
19080 Builder.CreateBr(PhiBB);
19082 Builder.SetInsertPoint(GlobalBB);
19086 if (FullFlatEmulation) {
19087 Value *CastToGlobal = Builder.CreateAddrSpaceCast(
19096 if (!FullFlatEmulation) {
19101 MDNode *RangeNotPrivate =
19104 LoadedGlobal->
setMetadata(LLVMContext::MD_noalias_addrspace,
19108 Builder.CreateBr(PhiBB);
19110 Builder.SetInsertPoint(PhiBB);
19112 if (ReturnValueIsUsed) {
19115 if (FullFlatEmulation)
19122 Builder.CreateBr(ExitBB);
19126 unsigned PtrOpIdx) {
19127 Value *PtrOp =
I->getOperand(PtrOpIdx);
19134 I->setOperand(PtrOpIdx, ASCast);
19146 ConstVal && ConstVal->isNullValue()) {
19176 "Expand Atomic Load only handles SCRATCH -> FLAT conversion");
19184 "Expand Atomic Store only handles SCRATCH -> FLAT conversion");
19199 LoadInst *LI = Builder.CreateAlignedLoad(
static bool isMul(MachineInstr *MI)
unsigned const MachineRegisterInfo * MRI
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static constexpr std::pair< ImplicitArgumentMask, StringLiteral > ImplicitAttrs[]
static bool allUsesHaveSourceMods(MachineInstr &MI, MachineRegisterInfo &MRI, unsigned CostThreshold=4)
Contains the definition of a TargetInstrInfo class that is common to all AMD GPUs.
static bool isNoUnsignedWrap(MachineInstr *Addr)
static bool parseTexFail(uint64_t TexFailCtrl, bool &TFE, bool &LWE, bool &IsTexFail)
static void packImage16bitOpsToDwords(MachineIRBuilder &B, MachineInstr &MI, SmallVectorImpl< Register > &PackedAddrs, unsigned ArgOffset, const AMDGPU::ImageDimIntrinsicInfo *Intr, bool IsA16, bool IsG16)
Turn a set of s16 typed registers in AddrRegs into a dword sized vector with s16 typed elements.
static bool isKnownNonNull(Register Val, MachineRegisterInfo &MRI, const AMDGPUTargetMachine &TM, unsigned AddrSpace)
Return true if the value is a known valid address, such that a null check is not necessary.
Provides AMDGPU specific target descriptions.
The AMDGPU TargetMachine interface definition for hw codegen targets.
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
Function Alias Analysis Results
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
#define LLVM_ATTRIBUTE_UNUSED
static std::optional< SDByteProvider > calculateByteProvider(SDValue Op, unsigned Index, unsigned Depth, std::optional< uint64_t > VectorIndex, unsigned StartingIndex=0)
static bool isSigned(unsigned int Opcode)
Utilities for dealing with flags related to floating point properties and mode controls.
AMD GCN specific subclass of TargetSubtarget.
Provides analysis for querying information about KnownBits during GISel passes.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
const HexagonInstrInfo * TII
iv Induction Variable Users
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Contains matchers for matching SSA Machine Instructions.
mir Rename Register Operands
Machine Check Debug Module
static bool isUndef(const MachineInstr &MI)
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static unsigned getAddressSpace(const Value *V, unsigned MaxLookup)
uint64_t IntrinsicInst * II
static constexpr MCPhysReg SPReg
const SmallVectorImpl< MachineOperand > & Cond
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Contains matchers for matching SelectionDAG nodes and values.
static void r0(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
static void r3(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
static void r2(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
static void r1(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
#define FP_DENORM_FLUSH_NONE
#define FP_DENORM_FLUSH_IN_FLUSH_OUT
static cl::opt< bool > UseSelectionDAGPTRADD("amdgpu-use-sdag-ptradd", cl::Hidden, cl::desc("Generate ISD::PTRADD nodes for 64-bit pointer arithmetic in the " "SelectionDAG ISel"), cl::init(false))
static void reservePrivateMemoryRegs(const TargetMachine &TM, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info)
static SDValue adjustLoadValueTypeImpl(SDValue Result, EVT LoadVT, const SDLoc &DL, SelectionDAG &DAG, bool Unpacked)
static MachineBasicBlock * emitIndirectSrc(MachineInstr &MI, MachineBasicBlock &MBB, const GCNSubtarget &ST)
static bool denormalModeIsFlushAllF64F16(const MachineFunction &MF)
static bool isAtomicRMWLegalIntTy(Type *Ty)
static void knownBitsForWorkitemID(const GCNSubtarget &ST, GISelValueTracking &VT, KnownBits &Known, unsigned Dim)
static bool flatInstrMayAccessPrivate(const Instruction *I)
Return if a flat address space atomicrmw can access private memory.
static std::pair< unsigned, int > computeIndirectRegAndOffset(const SIRegisterInfo &TRI, const TargetRegisterClass *SuperRC, unsigned VecReg, int Offset)
static bool denormalModeIsFlushAllF32(const MachineFunction &MF)
static bool addresses16Bits(int Mask)
static bool isClampZeroToOne(SDValue A, SDValue B)
static bool supportsMin3Max3(const GCNSubtarget &Subtarget, unsigned Opc, EVT VT)
static unsigned findFirstFreeSGPR(CCState &CCInfo)
static uint32_t getPermuteMask(SDValue V)
static SDValue lowerLaneOp(const SITargetLowering &TLI, SDNode *N, SelectionDAG &DAG)
static int getAlignedAGPRClassID(unsigned UnalignedClassID)
static void processPSInputArgs(SmallVectorImpl< ISD::InputArg > &Splits, CallingConv::ID CallConv, ArrayRef< ISD::InputArg > Ins, BitVector &Skipped, FunctionType *FType, SIMachineFunctionInfo *Info)
static void getCoopAtomicOperandsInfo(const CallInst &CI, bool IsLoad, TargetLoweringBase::IntrinsicInfo &Info)
static uint64_t getIdentityValueFor64BitWaveReduction(unsigned Opc)
static SDValue selectSOffset(SDValue SOffset, SelectionDAG &DAG, const GCNSubtarget *Subtarget)
static SDValue getLoadExtOrTrunc(SelectionDAG &DAG, ISD::LoadExtType ExtType, SDValue Op, const SDLoc &SL, EVT VT)
static bool globalMemoryFPAtomicIsLegal(const GCNSubtarget &Subtarget, const AtomicRMWInst *RMW, bool HasSystemScope)
static void fixMasks(SmallVectorImpl< DotSrc > &Srcs, unsigned ChainLength)
static bool is32bitWaveReduceOperation(unsigned Opc)
static TargetLowering::AtomicExpansionKind atomicSupportedIfLegalIntType(const AtomicRMWInst *RMW)
static SDValue strictFPExtFromF16(SelectionDAG &DAG, SDValue Src)
Return the source of an fp_extend from f16 to f32, or a converted FP constant.
static bool isAtomicRMWLegalXChgTy(const AtomicRMWInst *RMW)
static bool bitOpWithConstantIsReducible(unsigned Opc, uint32_t Val)
static void convertScratchAtomicToFlatAtomic(Instruction *I, unsigned PtrOpIdx)
static bool elementPairIsOddToEven(ArrayRef< int > Mask, int Elt)
static cl::opt< bool > DisableLoopAlignment("amdgpu-disable-loop-alignment", cl::desc("Do not align and prefetch loops"), cl::init(false))
static SDValue getDWordFromOffset(SelectionDAG &DAG, SDLoc SL, SDValue Src, unsigned DWordOffset)
static MachineBasicBlock::iterator loadM0FromVGPR(const SIInstrInfo *TII, MachineBasicBlock &MBB, MachineInstr &MI, unsigned InitResultReg, unsigned PhiReg, int Offset, bool UseGPRIdxMode, Register &SGPRIdxReg)
static bool isImmConstraint(StringRef Constraint)
static SDValue padEltsToUndef(SelectionDAG &DAG, const SDLoc &DL, EVT CastVT, SDValue Src, int ExtraElts)
static SDValue lowerICMPIntrinsic(const SITargetLowering &TLI, SDNode *N, SelectionDAG &DAG)
static bool hasCFUser(const Value *V, SmallPtrSet< const Value *, 16 > &Visited, unsigned WaveSize)
static OptimizationRemark emitAtomicRMWLegalRemark(const AtomicRMWInst *RMW)
static unsigned SubIdx2Lane(unsigned Idx)
Helper function for adjustWritemask.
static TargetLowering::AtomicExpansionKind getPrivateAtomicExpansionKind(const GCNSubtarget &STI)
static bool addressMayBeAccessedAsPrivate(const MachineMemOperand *MMO, const SIMachineFunctionInfo &Info)
static MachineBasicBlock * lowerWaveReduce(MachineInstr &MI, MachineBasicBlock &BB, const GCNSubtarget &ST, unsigned Opc)
static bool elementPairIsContiguous(ArrayRef< int > Mask, int Elt)
static bool isV2BF16(Type *Ty)
static ArgDescriptor allocateSGPR32InputImpl(CCState &CCInfo, const TargetRegisterClass *RC, unsigned NumArgRegs)
static SDValue getMad64_32(SelectionDAG &DAG, const SDLoc &SL, EVT VT, SDValue N0, SDValue N1, SDValue N2, bool Signed)
static SDValue resolveSources(SelectionDAG &DAG, SDLoc SL, SmallVectorImpl< DotSrc > &Srcs, bool IsSigned, bool IsAny)
static bool hasNon16BitAccesses(uint64_t PermMask, SDValue &Op, SDValue &OtherOp)
static void placeSources(ByteProvider< SDValue > &Src0, ByteProvider< SDValue > &Src1, SmallVectorImpl< DotSrc > &Src0s, SmallVectorImpl< DotSrc > &Src1s, int Step)
static EVT memVTFromLoadIntrReturn(const SITargetLowering &TLI, const DataLayout &DL, Type *Ty, unsigned MaxNumLanes)
static MachineBasicBlock::iterator emitLoadM0FromVGPRLoop(const SIInstrInfo *TII, MachineRegisterInfo &MRI, MachineBasicBlock &OrigBB, MachineBasicBlock &LoopBB, const DebugLoc &DL, const MachineOperand &Idx, unsigned InitReg, unsigned ResultReg, unsigned PhiReg, unsigned InitSaveExecReg, int Offset, bool UseGPRIdxMode, Register &SGPRIdxReg)
static SDValue matchPERM(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static bool isFrameIndexOp(SDValue Op)
static ConstantFPSDNode * getSplatConstantFP(SDValue Op)
static void allocateSGPR32Input(CCState &CCInfo, ArgDescriptor &Arg)
static void knownBitsForSBFE(const MachineInstr &MI, GISelValueTracking &VT, KnownBits &Known, const APInt &DemandedElts, unsigned BFEWidth, bool SExt, unsigned Depth)
static bool isExtendedFrom16Bits(SDValue &Operand)
static std::optional< bool > checkDot4MulSignedness(const SDValue &N, ByteProvider< SDValue > &Src0, ByteProvider< SDValue > &Src1, const SDValue &S0Op, const SDValue &S1Op, const SelectionDAG &DAG)
static bool vectorEltWillFoldAway(SDValue Op)
static SDValue getSPDenormModeValue(uint32_t SPDenormMode, SelectionDAG &DAG, const SIMachineFunctionInfo *Info, const GCNSubtarget *ST)
static uint32_t getConstantPermuteMask(uint32_t C)
static MachineBasicBlock * emitIndirectDst(MachineInstr &MI, MachineBasicBlock &MBB, const GCNSubtarget &ST)
static void setM0ToIndexFromSGPR(const SIInstrInfo *TII, MachineRegisterInfo &MRI, MachineInstr &MI, int Offset)
static ArgDescriptor allocateVGPR32Input(CCState &CCInfo, unsigned Mask=~0u, ArgDescriptor Arg=ArgDescriptor())
static MachineBasicBlock * Expand64BitScalarArithmetic(MachineInstr &MI, MachineBasicBlock *BB)
static std::pair< MachineBasicBlock *, MachineBasicBlock * > splitBlockForLoop(MachineInstr &MI, MachineBasicBlock &MBB, bool InstInLoop)
static uint32_t getIdentityValueFor32BitWaveReduction(unsigned Opc)
static unsigned getBasePtrIndex(const MemSDNode *N)
MemSDNode::getBasePtr() does not work for intrinsics, which needs to offset by the chain and intrinsi...
static LLVM_ATTRIBUTE_UNUSED bool isCopyFromRegOfInlineAsm(const SDNode *N)
static void allocateFixedSGPRInputImpl(CCState &CCInfo, const TargetRegisterClass *RC, MCRegister Reg)
static SDValue constructRetValue(SelectionDAG &DAG, MachineSDNode *Result, ArrayRef< EVT > ResultTypes, bool IsTexFail, bool Unpacked, bool IsD16, int DMaskPop, int NumVDataDwords, bool IsAtomicPacked16Bit, const SDLoc &DL)
static std::optional< ByteProvider< SDValue > > handleMulOperand(const SDValue &MulOperand)
static SDValue lowerFCMPIntrinsic(const SITargetLowering &TLI, SDNode *N, SelectionDAG &DAG)
static Register getIndirectSGPRIdx(const SIInstrInfo *TII, MachineRegisterInfo &MRI, MachineInstr &MI, int Offset)
static SDValue emitNonHSAIntrinsicError(SelectionDAG &DAG, const SDLoc &DL, EVT VT)
static EVT memVTFromLoadIntrData(const SITargetLowering &TLI, const DataLayout &DL, Type *Ty, unsigned MaxNumLanes)
static unsigned minMaxOpcToMin3Max3Opc(unsigned Opc)
static unsigned getExtOpcodeForPromotedOp(SDValue Op)
static SDValue lowerBALLOTIntrinsic(const SITargetLowering &TLI, SDNode *N, SelectionDAG &DAG)
static SDValue buildSMovImm32(SelectionDAG &DAG, const SDLoc &DL, uint64_t Val)
static SDValue tryFoldMADwithSRL(SelectionDAG &DAG, const SDLoc &SL, SDValue MulLHS, SDValue MulRHS, SDValue AddRHS)
static unsigned getIntrMemWidth(unsigned IntrID)
static SDValue getBuildDwordsVector(SelectionDAG &DAG, SDLoc DL, ArrayRef< SDValue > Elts)
static SDNode * findUser(SDValue Value, unsigned Opcode)
Helper function for LowerBRCOND.
static unsigned addPermMasks(unsigned First, unsigned Second)
static uint64_t clearUnusedBits(uint64_t Val, unsigned Size)
static SDValue getFPTernOp(SelectionDAG &DAG, unsigned Opcode, const SDLoc &SL, EVT VT, SDValue A, SDValue B, SDValue C, SDValue GlueChain, SDNodeFlags Flags)
static bool isV2F16OrV2BF16(Type *Ty)
static bool atomicIgnoresDenormalModeOrFPModeIsFTZ(const AtomicRMWInst *RMW)
static SDValue emitRemovedIntrinsicError(SelectionDAG &DAG, const SDLoc &DL, EVT VT)
static SDValue getFPBinOp(SelectionDAG &DAG, unsigned Opcode, const SDLoc &SL, EVT VT, SDValue A, SDValue B, SDValue GlueChain, SDNodeFlags Flags)
static SDValue buildPCRelGlobalAddress(SelectionDAG &DAG, const GlobalValue *GV, const SDLoc &DL, int64_t Offset, EVT PtrVT, unsigned GAFlags=SIInstrInfo::MO_NONE)
static cl::opt< bool > UseDivergentRegisterIndexing("amdgpu-use-divergent-register-indexing", cl::Hidden, cl::desc("Use indirect register addressing for divergent indexes"), cl::init(false))
static const std::optional< ByteProvider< SDValue > > calculateSrcByte(const SDValue Op, uint64_t DestByte, uint64_t SrcIndex=0, unsigned Depth=0)
static bool isV2F16(Type *Ty)
static void allocateSGPR64Input(CCState &CCInfo, ArgDescriptor &Arg)
SI DAG Lowering interface definition.
Interface definition for SIRegisterInfo.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static constexpr int Concat[]
static const AMDGPUFunctionArgInfo FixedABIFunctionInfo
void setFuncArgInfo(const Function &F, const AMDGPUFunctionArgInfo &ArgInfo)
static std::optional< uint32_t > getLDSKernelIdMetadata(const Function &F)
uint32_t getLDSSize() const
void setUsesDynamicLDS(bool DynLDS)
void setDynLDSAlign(const Function &F, const GlobalVariable &GV)
bool isEntryFunction() const
unsigned getWavefrontSize() const
static unsigned numBitsSigned(SDValue Op, SelectionDAG &DAG)
SDValue SplitVectorLoad(SDValue Op, SelectionDAG &DAG) const
Split a vector load into 2 loads of half the vector.
void analyzeFormalArgumentsCompute(CCState &State, const SmallVectorImpl< ISD::InputArg > &Ins) const
The SelectionDAGBuilder will automatically promote function arguments with illegal types.
SDValue LowerF64ToF16Safe(SDValue Src, const SDLoc &DL, SelectionDAG &DAG) const
SDValue storeStackInputValue(SelectionDAG &DAG, const SDLoc &SL, SDValue Chain, SDValue ArgVal, int64_t Offset) const
void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const override
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
SDValue splitBinaryBitConstantOpImpl(DAGCombinerInfo &DCI, const SDLoc &SL, unsigned Opc, SDValue LHS, uint32_t ValLo, uint32_t ValHi) const
Split the 64-bit value LHS into two 32-bit components, and perform the binary operation Opc to it wit...
SDValue lowerUnhandledCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals, StringRef Reason) const
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
SDValue addTokenForArgument(SDValue Chain, SelectionDAG &DAG, MachineFrameInfo &MFI, int ClobberedFI) const
bool isKnownNeverNaNForTargetNode(SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, bool SNaN=false, unsigned Depth=0) const override
If SNaN is false,.
static bool needsDenormHandlingF32(const SelectionDAG &DAG, SDValue Src, SDNodeFlags Flags)
uint32_t getImplicitParameterOffset(const MachineFunction &MF, const ImplicitParameter Param) const
Helper function that returns the byte offset of the given type of implicit parameter.
SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const
virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op, SelectionDAG &DAG) const
SDValue loadInputValue(SelectionDAG &DAG, const TargetRegisterClass *RC, EVT VT, const SDLoc &SL, const ArgDescriptor &Arg) const
static EVT getEquivalentMemType(LLVMContext &Context, EVT VT)
SDValue CreateLiveInRegister(SelectionDAG &DAG, const TargetRegisterClass *RC, Register Reg, EVT VT, const SDLoc &SL, bool RawReg=false) const
Helper function that adds Reg to the LiveIn list of the DAG's MachineFunction.
SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const
Split a vector store into 2 stores of half the vector.
std::pair< SDValue, SDValue > split64BitValue(SDValue Op, SelectionDAG &DAG) const
Return 64-bit value Op as two 32-bit integers.
AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI)
static CCAssignFn * CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg)
static CCAssignFn * CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg)
Selects the correct CCAssignFn for a given CallingConvention value.
static unsigned numBitsUnsigned(SDValue Op, SelectionDAG &DAG)
static bool allowApproxFunc(const SelectionDAG &DAG, SDNodeFlags Flags)
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &DL, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array,...
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
SDValue performRcpCombine(SDNode *N, DAGCombinerInfo &DCI) const
static bool shouldFoldFNegIntoSrc(SDNode *FNeg, SDValue FNegSrc)
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
SDValue WidenOrSplitVectorLoad(SDValue Op, SelectionDAG &DAG) const
Widen a suitably aligned v3 load.
SDValue getHiHalf64(SDValue Op, SelectionDAG &DAG) const
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
const std::array< unsigned, 3 > & getDims() const
static const LaneMaskConstants & get(const GCNSubtarget &ST)
const unsigned XorTermOpc
const unsigned AndSaveExecOpc
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVM_READONLY int getExactLog2Abs() const
APInt bitcastToAPInt() const
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
unsigned countr_zero() const
Count the number of trailing zero bits.
bool isOneBitSet(unsigned BitNo) const
Determine if this APInt Value only has the specified bit set.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
This class represents an incoming formal argument to a Function.
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
const Function * getParent() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
An instruction that atomically checks whether a specified value is in a memory location,...
Value * getNewValOperand()
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Value * getCompareOperand()
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
static unsigned getPointerOperandIndex()
an instruction that atomically reads a memory location, combines it with another value,...
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
static unsigned getPointerOperandIndex()
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Min
*p = old <signed v ? old : v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
Value * getPointerOperand()
void setOperation(BinOp Operation)
BinOp getOperation() const
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this rmw instruction.
static LLVM_ABI StringRef getOperationName(BinOp Op)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
bool isCompareAndSwap() const
Returns true if this SDNode represents cmpxchg atomic operation, false otherwise.
This class holds the attributes for a particular argument, parameter, function, or return value.
LLVM_ABI MemoryEffects getMemoryEffects() const
LLVM_ABI bool getValueAsBool() const
Return the attribute's value as a boolean.
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
A "pseudo-class" with methods for operating on BUILD_VECTORs.
Represents known origin of an individual byte in combine pattern.
static ByteProvider getConstantZero()
static ByteProvider getSrc(std::optional< ISelOp > Val, int64_t ByteOffset, int64_t VectorOffset)
std::optional< ISelOp > Src
CCState - This class holds information needed while lowering arguments and return values.
MachineFunction & getMachineFunction() const
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set,...
static LLVM_ABI bool resultsCompatible(CallingConv::ID CalleeCC, CallingConv::ID CallerCC, MachineFunction &MF, LLVMContext &C, const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn CalleeFn, CCAssignFn CallerFn)
Returns true if the results of the two calling conventions are compatible.
LLVM_ABI void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
MCRegister AllocateReg(MCPhysReg Reg)
AllocateReg - Attempt to allocate one register.
LLVM_ABI bool CheckReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
CheckReturn - Analyze the return values of a function, returning true if the return can be performed ...
LLVM_ABI void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
int64_t AllocateStack(unsigned Size, Align Alignment)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
LLVM_ABI void AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeCallOperands - Analyze the outgoing arguments to a call, incorporating info about the passed v...
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
bool isAllocated(MCRegister Reg) const
isAllocated - Return true if the specified register (or an alias) is allocated.
LLVM_ABI void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
CCValAssign - Represent assignment of one arg/retval to a location.
Register getLocReg() const
LocInfo getLocInfo() const
int64_t getLocMemOffset() const
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
Value * getArgOperand(unsigned i) const
unsigned arg_size() const
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static bool isFPPredicate(Predicate P)
static bool isIntPredicate(Predicate P)
const APFloat & getValueAPF() const
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
bool isNegative() const
Return true if the value is negative.
bool isInfinity() const
Return true if the value is an infinity.
This is the shared class of boolean and integer constants.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
uint64_t getZExtValue() const
const APInt & getAPIntValue() const
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
LLVM_ABI Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Diagnostic information for unsupported feature in backend.
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Register DemoteRegister
DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg allocated to hold a pointer to ...
const Value * getValueFromVirtualReg(Register Vreg)
This method is called from TargetLowerinInfo::isSDNodeSourceOfDivergence to get the Value correspondi...
Class to represent function types.
Type * getParamType(unsigned i) const
Parameter type accessors.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
iterator_range< arg_iterator > args()
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
Argument * getArg(unsigned i) const
bool hasMinimum3Maximum3F32() const
bool supportsAgentScopeFineGrainedRemoteMemoryAtomics() const
const SIInstrInfo * getInstrInfo() const override
bool hasMin3Max3PKF16() const
const SIRegisterInfo * getRegisterInfo() const override
bool hasMinimum3Maximum3PKF16() const
bool hasGloballyAddressableScratch() const
bool hasMinimum3Maximum3F16() const
bool hasRestrictedSOffset() const
bool hasMin3Max3_16() const
bool hasEmulatedSystemScopeAtomics() const
unsigned getKnownHighZeroBitsForFrameIndex() const
Return the number of high bits known to be zero for a frame index.
bool hasShaderCyclesHiLoRegisters() const
unsigned getMaxPrivateElementSize(bool ForBufferRSrc=false) const
bool hasKernargSegmentPtr() const
bool hasDispatchID() const
bool hasPrivateSegmentBuffer() const
unsigned getNumFreeUserSGPRs()
bool hasImplicitBufferPtr() const
bool hasPrivateSegmentSize() const
bool hasDispatchPtr() const
bool hasFlatScratchInit() const
const MachineFunction & getMachineFunction() const
virtual void computeKnownBitsImpl(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
int64_t getOffset() const
LLVM_ABI unsigned getAddressSpace() const
const GlobalValue * getGlobal() const
bool hasExternalLinkage() const
unsigned getAddressSpace() const
Module * getParent()
Get the module that this global value is contained inside of...
Type * getValueType() const
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
LLVM_ABI InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
Class to represent integer types.
A wrapper class for inspecting calls to intrinsic functions.
constexpr unsigned getScalarSizeInBits() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr LLT changeElementSize(unsigned NewEltSize) const
If this type is a vector, return a vector with the same number of elements but the new element size.
This is an important class for using LLVM in a threaded context.
LLVM_ABI void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
LLVM_ABI SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID.
An instruction for reading from memory.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this load instruction.
static unsigned getPointerOperandIndex()
This class is used to represent ISD::LOAD nodes.
const SDValue & getBasePtr() const
const SDValue & getOffset() const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Describe properties that are true of each instruction in the target description file.
Wrapper class representing physical registers. Should be passed by value.
LLVM_ABI MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
const MDOperand & getOperand(unsigned I) const
Helper class for constructing bundles of MachineInstrs.
MachineBasicBlock::instr_iterator begin() const
Return an iterator to the first bundled instruction.
uint64_t getScalarSizeInBits() const
bool bitsLE(MVT VT) const
Return true if this has no more bits than VT.
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool isScalableVector() const
Return true if this is a vector value type where the runtime length is machine dependent.
static LLVM_ABI MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
static MVT getVectorVT(MVT VT, unsigned NumElements)
static MVT getIntegerVT(unsigned BitWidth)
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI MachineBasicBlock * splitAt(MachineInstr &SplitInst, bool UpdateLiveIns=true, LiveIntervals *LIS=nullptr)
Split a basic block into 2 pieces at SplitPoint.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
bool hasCalls() const
Return true if the current function has any function calls.
void setHasTailCall(bool V=true)
void setReturnAddressIsTaken(bool s)
bool hasStackObjects() const
Return true if there are any stack objects in this function.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
void push_back(MachineBasicBlock *MBB)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & setOperandDead(unsigned OpIdx) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
@ MOVolatile
The memory access is volatile.
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MONonTemporal
The memory access is non-temporal.
@ MOInvariant
The memory access always returns the same value (or traps).
@ MOStore
The memory access writes data.
const MachinePointerInfo & getPointerInfo() const
Flags getFlags() const
Return the raw flags of the source value,.
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
Align getBaseAlign() const
Return the minimum known alignment in bytes of the base address, without the offset.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static MachineOperand CreateImm(int64_t Val)
void setIsUndef(bool Val=true)
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI void clearKillFlags(Register Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
LLVM_ABI void setType(Register VReg, LLT Ty)
Set the low-level type of VReg to Ty.
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.
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
const MachinePointerInfo & getPointerInfo() const
const SDValue & getChain() const
EVT getMemoryVT() const
Return the type of the in-memory value.
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
bool doesNotAccessMemory() const
Whether this function accesses no memory.
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool hasOneUse() const
Return true if there is exactly one use of this node.
value_iterator value_end() const
SDNodeFlags getFlags() const
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
SDVTList getVTList() const
const SDValue & getOperand(unsigned Num) const
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
user_iterator user_begin() const
Provide iteration support to walk over all users of an SDNode.
op_iterator op_end() const
value_iterator value_begin() const
op_iterator op_begin() const
Represents a use of a SDNode.
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
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
bool isMachineOpcode() const
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned i) const
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
unsigned getMachineOpcode() const
unsigned getOpcode() const
static unsigned getMaxMUBUFImmOffset(const GCNSubtarget &ST)
static unsigned getDSShaderTypeValue(const MachineFunction &MF)
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
bool isWholeWaveFunction() const
bool hasWorkGroupIDZ() const
AMDGPU::ClusterDimsAttr getClusterDims() const
std::tuple< const ArgDescriptor *, const TargetRegisterClass *, LLT > getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const
unsigned getBytesInStackArgArea() const
const AMDGPUGWSResourcePseudoSourceValue * getGWSPSV(const AMDGPUTargetMachine &TM)
static unsigned getSubRegFromChannel(unsigned Channel, unsigned NumRegs=1)
static LLVM_READONLY const TargetRegisterClass * getSGPRClassForBitWidth(unsigned BitWidth)
static bool isVGPRClass(const TargetRegisterClass *RC)
static bool isSGPRClass(const TargetRegisterClass *RC)
static bool isAGPRClass(const TargetRegisterClass *RC)
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
bool isTypeDesirableForOp(unsigned Op, EVT VT) const override
Return true if the target has native support for the specified value type and it is 'desirable' to us...
SDNode * PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const override
Fold the instructions after selecting them.
SDValue splitTernaryVectorOp(SDValue Op, SelectionDAG &DAG) const
MachineSDNode * wrapAddr64Rsrc(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr) const
bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, EVT VT) const override
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
SDValue lowerGET_ROUNDING(SDValue Op, SelectionDAG &DAG) const
bool requiresUniformRegister(MachineFunction &MF, const Value *V) const override
Allows target to decide about the register class of the specific value that is live outside the defin...
bool isFMADLegal(const SelectionDAG &DAG, const SDNode *N) const override
Returns true if be combined with to form an ISD::FMAD.
AtomicExpansionKind shouldExpandAtomicStoreInIR(StoreInst *SI) const override
Returns how the given (atomic) store should be expanded by the IR-level AtomicExpand pass into.
void bundleInstWithWaitcnt(MachineInstr &MI) const
Insert MI into a BUNDLE with an S_WAITCNT 0 immediately following it.
SDValue lowerROTR(SDValue Op, SelectionDAG &DAG) const
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
Return the type to use for a scalar shift opcode, given the shifted amount type.
SDValue LowerCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
MVT getPointerTy(const DataLayout &DL, unsigned AS) const override
Map address space 7 to MVT::amdgpuBufferFatPointer because that's its in-memory representation.
bool denormalsEnabledForType(const SelectionDAG &DAG, EVT VT) const
void insertCopiesSplitCSR(MachineBasicBlock *Entry, const SmallVectorImpl< MachineBasicBlock * > &Exits) const override
Insert explicit copies in entry and exit blocks.
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the ValueType of the result of SETCC operations.
SDNode * legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const
Legalize target independent instructions (e.g.
bool allowsMisalignedMemoryAccessesImpl(unsigned Size, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *IsFast=nullptr) const
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
SDValue lowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const
const GCNSubtarget * getSubtarget() const
bool enableAggressiveFMAFusion(EVT VT) const override
Return true if target always benefits from combining into FMA for a given value type.
bool shouldEmitGOTReloc(const GlobalValue *GV) const
bool isCanonicalized(SelectionDAG &DAG, SDValue Op, unsigned MaxDepth=5) const
void CollectTargetIntrinsicOperands(const CallInst &I, SmallVectorImpl< SDValue > &Ops, SelectionDAG &DAG) const override
SDValue splitUnaryVectorOp(SDValue Op, SelectionDAG &DAG) const
SDValue lowerGET_FPENV(SDValue Op, SelectionDAG &DAG) const
bool checkForPhysRegDependency(SDNode *Def, SDNode *User, unsigned Op, const TargetRegisterInfo *TRI, const TargetInstrInfo *TII, MCRegister &PhysReg, int &Cost) const override
Allows the target to handle physreg-carried dependency in target-specific way.
void allocateSpecialInputSGPRs(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
void allocateLDSKernelId(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
SDValue LowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const
bool isReassocProfitable(SelectionDAG &DAG, SDValue N0, SDValue N1) const override
void allocateHSAUserSGPRs(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
ArrayRef< MCPhysReg > getRoundingControlRegisters() const override
Returns a 0 terminated array of rounding control registers that can be attached into strict FP call.
ConstraintType getConstraintType(StringRef Constraint) const override
Given a constraint, return the type of constraint it is for this target.
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &DL, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array,...
const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent) const override
Return the register class that should be used for the specified value type.
void AddMemOpInit(MachineInstr &MI) const
MachineMemOperand::Flags getTargetMMOFlags(const Instruction &I) const override
This callback is used to inspect load/store instructions and add target-specific MachineMemOperand fl...
bool isLegalGlobalAddressingMode(const AddrMode &AM) const
void computeKnownBitsForFrameIndex(int FrameIdx, KnownBits &Known, const MachineFunction &MF) const override
Determine which of the bits of FrameIndex FIOp are known to be 0.
bool shouldConvertConstantLoadToIntImm(const APInt &Imm, Type *Ty) const override
Return true if it is beneficial to convert a load of a constant to just the constant itself.
Align getPrefLoopAlignment(MachineLoop *ML) const override
Return the preferred loop alignment.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
void emitExpandAtomicStore(StoreInst *SI) const override
Perform a atomic store using a target-specific way.
AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override
Returns how the given (atomic) load should be expanded by the IR-level AtomicExpand pass.
Align computeKnownAlignForTargetInstr(GISelValueTracking &Analysis, Register R, const MachineRegisterInfo &MRI, unsigned Depth=0) const override
Determine the known alignment for the pointer value R.
bool getAsmOperandConstVal(SDValue Op, uint64_t &Val) const
bool isShuffleMaskLegal(ArrayRef< int >, EVT) const override
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations,...
void emitExpandAtomicLoad(LoadInst *LI) const override
Perform a atomic load using a target-specific way.
EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op, const AttributeList &FuncAttributes) const override
Returns the target specific optimal type for load and store operations as a result of memset,...
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
Register getRegisterByName(const char *RegName, LLT VT, const MachineFunction &MF) const override
Return the register ID of the name passed in.
void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
Lower the specified operand into the Ops vector.
LLT getPreferredShiftAmountTy(LLT Ty) const override
Return the preferred type to use for a shift opcode, given the shifted amount type is ShiftValueTy.
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS, Instruction *I=nullptr) const override
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
SDValue lowerSET_FPENV(SDValue Op, SelectionDAG &DAG) const
bool shouldPreservePtrArith(const Function &F, EVT PtrVT) const override
True if target has some particular form of dealing with pointer arithmetic semantics for pointers wit...
void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const override
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
SDValue lowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const
void allocateSpecialInputVGPRsFixed(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
Allocate implicit function VGPR arguments in fixed registers.
LoadInst * lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const override
On some platforms, an AtomicRMW that never actually modifies the value (such as fetch_add of 0) can b...
MachineBasicBlock * emitGWSMemViolTestLoop(MachineInstr &MI, MachineBasicBlock *BB) const
bool getAddrModeArguments(const IntrinsicInst *I, SmallVectorImpl< Value * > &Ops, Type *&AccessTy) const override
CodeGenPrepare sinks address calculations into the same BB as Load/Store instructions reading the add...
bool checkAsmConstraintValA(SDValue Op, uint64_t Val, unsigned MaxSize=64) const
AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
bool shouldEmitFixup(const GlobalValue *GV) const
MachineBasicBlock * splitKillBlock(MachineInstr &MI, MachineBasicBlock *BB) const
void emitExpandAtomicCmpXchg(AtomicCmpXchgInst *CI) const override
Perform a cmpxchg expansion using a target-specific method.
bool hasMemSDNodeUser(SDNode *N) const
bool isSDNodeSourceOfDivergence(const SDNode *N, FunctionLoweringInfo *FLI, UniformityInfo *UA) const override
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
bool isEligibleForTailCallOptimization(SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SmallVectorImpl< ISD::InputArg > &Ins, SelectionDAG &DAG) const
bool isMemOpHasNoClobberedMemOperand(const SDNode *N) const
bool isLegalFlatAddressingMode(const AddrMode &AM, unsigned AddrSpace) const
SDValue LowerCallResult(SDValue Chain, SDValue InGlue, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &DL, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals, bool isThisReturn, SDValue ThisVal) const
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &DL, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
AtomicExpansionKind shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override
Returns how the given atomic cmpxchg should be expanded by the IR-level AtomicExpand pass.
bool isFPExtFoldable(const SelectionDAG &DAG, unsigned Opcode, EVT DestVT, EVT SrcVT) const override
Return true if an fpext operation input to an Opcode operation is free (for instance,...
void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const override
Assign the register class depending on the number of bits set in the writemask.
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
void allocateSpecialInputVGPRs(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
Allocate implicit function VGPR arguments at the end of allocated user arguments.
void finalizeLowering(MachineFunction &MF) const override
Execute target specific actions to finalize target lowering.
static bool isNonGlobalAddrSpace(unsigned AS)
void emitExpandAtomicAddrSpacePredicate(Instruction *AI) const
MachineSDNode * buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr, uint32_t RsrcDword1, uint64_t RsrcDword2And3) const
Return a resource descriptor with the 'Add TID' bit enabled The TID (Thread ID) is multiplied by the ...
unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain targets require unusual breakdowns of certain types.
bool mayBeEmittedAsTailCall(const CallInst *) const override
Return true if the target may be able emit the call instruction as a tail call.
void passSpecialInputs(CallLoweringInfo &CLI, CCState &CCInfo, const SIMachineFunctionInfo &Info, SmallVectorImpl< std::pair< unsigned, SDValue > > &RegsToPass, SmallVectorImpl< SDValue > &MemOpChains, SDValue Chain) const
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
bool checkAsmConstraintVal(SDValue Op, StringRef Constraint, uint64_t Val) const
bool isKnownNeverNaNForTargetNode(SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, bool SNaN=false, unsigned Depth=0) const override
If SNaN is false,.
void emitExpandAtomicRMW(AtomicRMWInst *AI) const override
Perform a atomicrmw expansion using a target-specific way.
static bool shouldExpandVectorDynExt(unsigned EltSize, unsigned NumElem, bool IsDivergentIdx, const GCNSubtarget *Subtarget)
Check if EXTRACT_VECTOR_ELT/INSERT_VECTOR_ELT (<n x e>, var-idx) should be expanded into a set of cmp...
bool shouldUseLDSConstAddress(const GlobalValue *GV) const
bool supportSplitCSR(MachineFunction *MF) const override
Return true if the target supports that a subset of CSRs for the given machine function is handled ex...
bool isExtractVecEltCheap(EVT VT, unsigned Index) const override
Return true if extraction of a scalar element from the given vector type at the given index is cheap.
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
bool allowsMisalignedMemoryAccesses(LLT Ty, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *IsFast=nullptr) const override
LLT handling variant.
bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT, unsigned Index) const override
Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type from this source type with ...
bool canMergeStoresTo(unsigned AS, EVT MemVT, const MachineFunction &MF) const override
Returns if it's reasonable to merge stores to MemVT size.
SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const
SITargetLowering(const TargetMachine &tm, const GCNSubtarget &STI)
void computeKnownBitsForTargetInstr(GISelValueTracking &Analysis, Register R, KnownBits &Known, const APInt &DemandedElts, const MachineRegisterInfo &MRI, unsigned Depth=0) const override
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
bool isFreeAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast from SrcAS to DestAS is "cheap", such that e.g.
bool shouldEmitPCReloc(const GlobalValue *GV) const
void initializeSplitCSR(MachineBasicBlock *Entry) const override
Perform necessary initialization to handle a subset of CSRs explicitly via copies.
void allocateSpecialEntryInputVGPRs(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
void allocatePreloadKernArgSGPRs(CCState &CCInfo, SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< ISD::InputArg > &Ins, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL, SDValue V) const
bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, MachineFunction &MF, unsigned IntrinsicID) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
SDValue splitBinaryVectorOp(SDValue Op, SelectionDAG &DAG) const
unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const override
Certain targets such as MIPS require that some types such as vectors are always broken down into scal...
MVT getPointerMemTy(const DataLayout &DL, unsigned AS) const override
Similarly, the in-memory representation of a p7 is {p8, i32}, aka v8i32 when padding is added.
void allocateSystemSGPRs(CCState &CCInfo, MachineFunction &MF, SIMachineFunctionInfo &Info, CallingConv::ID CallConv, bool IsShader) const
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, LLVMContext &Context, const Type *RetTy) const override
This hook should be implemented to check whether the return values described by the Outs array can fi...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
SDValue getExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT, unsigned Opcode)
Convert Op, which must be of integer type, to the integer type VT, by either any/sign/zero-extending ...
SDValue getExtractVectorElt(const SDLoc &DL, EVT VT, SDValue Vec, unsigned Idx)
Extract element at Idx from Vec.
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
LLVM_ABI SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS, unsigned DestAS)
Return an AddrSpaceCastSDNode.
bool isKnownNeverSNaN(SDValue Op, const APInt &DemandedElts, unsigned Depth=0) const
const TargetSubtargetInfo & getSubtarget() const
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
const Pass * getPass() const
LLVM_ABI SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI SDValue getShiftAmountConstant(uint64_t Val, EVT VT, const SDLoc &DL)
LLVM_ABI SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget=false, bool IsOpaque=false)
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 void ExtractVectorElements(SDValue Op, SmallVectorImpl< SDValue > &Args, unsigned Start=0, unsigned Count=0, EVT EltVT=EVT())
Append the extracted elements from Start to Count out of the vector Op in Args.
LLVM_ABI SDValue getAtomicLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT MemVT, EVT VT, SDValue Chain, SDValue Ptr, MachineMemOperand *MMO)
LLVM_ABI SDValue getFreeze(SDValue V)
Return a freeze using the SDLoc of the value operand.
LLVM_ABI bool isConstantIntBuildVectorOrConstantInt(SDValue N, bool AllowOpaques=true) const
Test whether the given value is a constant int or similar node.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
LLVM_ABI SDValue UnrollVectorOp(SDNode *N, unsigned ResNE=0)
Utility function used by legalize and lowering to "unroll" a vector operation by splitting out the sc...
LLVM_ABI SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
LLVM_ABI bool haveNoCommonBitsSet(SDValue A, SDValue B) const
Return true if A and B have no common bits set.
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, LocationSize Size=LocationSize::precise(0), const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
LLVM_ABI SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Val, MachineMemOperand *MMO)
Gets a node for an atomic op, produces result (if relevant) and chain and takes 2 operands.
LLVM_ABI SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool AlwaysInline, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), BatchAAResults *BatchAA=nullptr)
std::pair< SDValue, SDValue > SplitVectorOperand(const SDNode *N, unsigned OpNo)
Split the node's operand with EXTRACT_SUBVECTOR and return the low/high part.
LLVM_ABI SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
const TargetLowering & getTargetLoweringInfo() const
LLVM_ABI std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
Compute the VTs needed for the low/hi parts of a type which is split (or expanded) into two not neces...
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
LLVM_ABI SDValue getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by first bitcasting (from potentia...
LLVM_ABI SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type.
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT)
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
LLVM_ABI void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
LLVM_ABI SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value.
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getTokenFactor(const SDLoc &DL, SmallVectorImpl< SDValue > &Vals)
Creates a new TokenFactor containing Vals.
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags=SDNodeFlags())
Returns sum of the base pointer and offset.
SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
LLVM_ABI void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
LLVM_ABI void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
LLVM_ABI SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
LLVM_ABI SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either sign-extending or trunca...
const TargetMachine & getTarget() const
LLVM_ABI SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either any-extending or truncat...
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
LLVM_ABI bool isKnownNeverNaN(SDValue Op, const APInt &DemandedElts, bool SNaN=false, unsigned Depth=0) const
Test whether the given SDValue (or all elements of it, if it is a vector) is known to never be NaN in...
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
Return the number of times the sign bit of the register is replicated into the other bits.
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,...
LLVM_ABI SDValue getVectorIdxConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVM_ABI void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
MachineFunction & getMachineFunction() const
SDValue getPOISON(EVT VT)
Return a POISON node. POISON does not have a useful SDLoc.
SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op)
Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all elements.
LLVM_ABI SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
LLVM_ABI KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
LLVM_ABI SDValue getRegisterMask(const uint32_t *RegMask)
LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
LLVM_ABI SDValue getCondCode(ISD::CondCode Cond)
LLVM_ABI bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, TypeSize Offset)
Create an add instruction with appropriate flags when used for addressing some offset of an object.
LLVMContext * getContext() const
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
LLVM_ABI SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
LLVM_ABI std::pair< SDValue, SDValue > SplitScalar(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the scalar node with EXTRACT_ELEMENT using the provided VTs and return the low/high part.
LLVM_ABI SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
int getMaskElt(unsigned Idx) const
ArrayRef< int > getMask() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Information about stack frame layout on the target.
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
TargetInstrInfo - Interface to description of machine instruction set.
Type * Ty
Same as OrigTy, or partially legalized for soft float libcalls.
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
virtual void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
const TargetMachine & getTargetMachine() const
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
void setHasExtractBitsInsn(bool hasExtractInsn=true)
Tells the code generator that the target has BitExtract instructions.
virtual TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const
Return the preferred vector type legalization action.
virtual unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const
Certain targets such as MIPS require that some types such as vectors are always broken down into scal...
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
virtual Align getPrefLoopAlignment(MachineLoop *ML=nullptr) const
Return the preferred loop alignment.
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
@ ZeroOrOneBooleanContent
bool isOperationLegalOrCustom(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
virtual bool isNarrowingProfitable(SDNode *N, EVT SrcVT, EVT DestVT) const
Return true if it's profitable to narrow operations of type SrcVT to DestVT.
void setStackPointerRegisterToSaveRestore(Register R)
If set to a physical register, this specifies the register that llvm.savestack/llvm....
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
bool allowsMemoryAccessForAlignment(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const
This function returns true if the memory access is aligned or if the target allows this specific unal...
virtual MVT getPointerMemTy(const DataLayout &DL, uint32_t AS=0) const
Return the in-memory pointer type for the given address space, defaults to the pointer type from the ...
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
virtual void computeKnownBitsForFrameIndex(int FIOp, KnownBits &Known, const MachineFunction &MF) const
Determine which of the bits of FrameIndex FIOp are known to be 0.
SDValue scalarizeVectorStore(StoreSDNode *ST, SelectionDAG &DAG) const
std::vector< AsmOperandInfo > AsmOperandInfoVector
SDValue SimplifyMultipleUseDemandedBits(SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts, SelectionDAG &DAG, unsigned Depth=0) const
More limited version of SimplifyDemandedBits that can be used to "lookthrough" ops that don't contrib...
SDValue expandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG) const
Expands an unaligned store to 2 half-size stores for integer values, and possibly more for vectors.
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
bool parametersInCSRMatch(const MachineRegisterInfo &MRI, const uint32_t *CallerPreservedMask, const SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< SDValue > &OutVals) const
Check whether parameters to a call that are passed in callee saved registers are the same as from the...
std::pair< SDValue, SDValue > expandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Expands an unaligned load to 2 half-size loads for an integer, and possibly more for vectors.
SDValue expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *N, SelectionDAG &DAG) const
Expand fminimumnum/fmaximumnum into multiple comparison with selects.
virtual bool isTypeDesirableForOp(unsigned, EVT VT) const
Return true if the target has native support for the specified value type and it is 'desirable' to us...
std::pair< SDValue, SDValue > scalarizeVectorLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Turn load of vector type into a load of the individual elements.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts, KnownBits &Known, TargetLoweringOpt &TLO, unsigned Depth=0, bool AssumeSingleUse=false) const
Look at Op.
TargetLowering(const TargetLowering &)=delete
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
virtual AsmOperandInfoVector ParseConstraints(const DataLayout &DL, const TargetRegisterInfo *TRI, const CallBase &Call) const
Split up the constraint string from the inline assembly value into the specific constraints and their...
SDValue expandRoundInexactToOdd(EVT ResultVT, SDValue Op, const SDLoc &DL, SelectionDAG &DAG) const
Truncate Op to ResultVT.
virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, SDValue Op, SelectionDAG *DAG=nullptr) const
Determines the constraint code and constraint type to use for the specific AsmOperandInfo,...
virtual void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
SDValue expandFMINNUM_FMAXNUM(SDNode *N, SelectionDAG &DAG) const
Expand fminnum/fmaxnum into fminnum_ieee/fmaxnum_ieee with quieted inputs.
Primary interface to the complete machine description for the target machine.
const Triple & getTargetTriple() const
bool shouldAssumeDSOLocal(const GlobalValue *GV) const
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.
unsigned getNumRegs() const
Return the number of registers in this class.
unsigned getID() const
Return the register class ID number.
MCRegister getRegister(unsigned i) const
Return the specified register in the class.
int getCopyCost() const
Return the cost of copying a value between two registers in this class.
iterator begin() const
begin/end - Return all of the registers in this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
OSType getOS() const
Get the parsed operating system type of this triple.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isFunctionTy() const
True if this is an instance of FunctionType.
bool isIntegerTy() const
True if this is an instance of IntegerType.
LLVM_ABI const fltSemantics & getFltSemantics() const
bool isVoidTy() const
Return true if this is 'void'.
A Use represents the edge between a Value definition and its users.
LLVM_ABI void set(Value *Val)
User * getUser() const
Returns the User that contains this Use.
LLVM_ABI unsigned getOperandNo() const
Return the operand # of this use in its User.
const Use & getOperandUse(unsigned i) const
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Type * getElementType() const
constexpr ScalarTy getFixedValue() const
constexpr bool isZero() const
const ParentTy * getParent() const
self_iterator getIterator()
#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.
@ BUFFER_STRIDED_POINTER
Address space for 192-bit fat buffer pointers with an additional index.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
@ STREAMOUT_REGISTER
Internal address spaces. Can be freely renumbered.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ BUFFER_FAT_POINTER
Address space for 160-bit buffer fat pointers.
@ PRIVATE_ADDRESS
Address space for private memory.
@ BUFFER_RESOURCE
Address space for 128-bit buffer resources.
@ BUFFER_ATOMIC_COND_SUB_U32
@ TBUFFER_LOAD_FORMAT_D16
@ TBUFFER_STORE_FORMAT_D16
@ BUFFER_STORE_FORMAT_D16
@ TC_RETURN_GFX_WholeWave
@ CLAMP
CLAMP value between 0.0 and 1.0.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi)
LLVM_READONLY const MIMGG16MappingInfo * getMIMGG16MappingInfo(unsigned G)
LLVM_READONLY int getGlobalSaddrOp(uint16_t Opcode)
bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi)
int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, unsigned VDataDwords, unsigned VAddrDwords)
LLVM_READNONE constexpr bool isShader(CallingConv::ID CC)
bool shouldEmitConstantsToTextSection(const Triple &TT)
bool isFlatGlobalAddrSpace(unsigned AS)
const uint64_t FltRoundToHWConversionTable
bool isGFX12Plus(const MCSubtargetInfo &STI)
unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler)
bool isGFX11(const MCSubtargetInfo &STI)
bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val)
Checks if Val is inside MD, a !range-like metadata.
LLVM_READNONE bool isLegalDPALU_DPPControl(const MCSubtargetInfo &ST, unsigned DC)
LLVM_READNONE constexpr bool mayTailCallThisCC(CallingConv::ID CC)
Return true if we might ever do TCO for calls with this calling convention.
unsigned getAMDHSACodeObjectVersion(const Module &M)
LLVM_READONLY bool hasNamedOperand(uint64_t Opcode, OpName NamedIdx)
LLVM_READNONE constexpr bool isKernel(CallingConv::ID CC)
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
LLVM_READNONE constexpr bool isCompute(CallingConv::ID CC)
bool isIntrinsicSourceOfDivergence(unsigned IntrID)
LLVM_READNONE bool isInlinableIntLiteral(int64_t Literal)
Is this literal inlinable, and not one of the values intended for floating point values.
bool getMUBUFTfe(unsigned Opc)
bool isGFX11Plus(const MCSubtargetInfo &STI)
std::optional< unsigned > getInlineEncodingV2F16(uint32_t Literal)
std::tuple< char, unsigned, unsigned > parseAsmConstraintPhysReg(StringRef Constraint)
Returns a valid charcode or 0 in the first entry if this is a valid physical register constraint.
bool isGFX10Plus(const MCSubtargetInfo &STI)
LLVM_READONLY int getVOPe64(uint16_t Opcode)
@ TowardZeroF32_TowardNegativeF64
bool isUniformMMO(const MachineMemOperand *MMO)
std::optional< unsigned > getInlineEncodingV2I16(uint32_t Literal)
uint32_t decodeFltRoundToHWConversionTable(uint32_t FltRounds)
Read the hardware rounding mode equivalent of a AMDGPUFltRounds value.
bool isGFX1250(const MCSubtargetInfo &STI)
bool isExtendedGlobalAddrSpace(unsigned AS)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfo(unsigned DimEnum)
std::optional< unsigned > getInlineEncodingV2BF16(uint32_t Literal)
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
LLVM_READNONE constexpr bool isChainCC(CallingConv::ID CC)
int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels)
const ImageDimIntrinsicInfo * getImageDimIntrinsicInfo(unsigned Intr)
bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi)
LLVM_READNONE constexpr bool canGuaranteeTCO(CallingConv::ID CC)
LLVM_READNONE constexpr bool isGraphics(CallingConv::ID CC)
bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi)
Is this literal inlinable.
const RsrcIntrinsic * lookupRsrcIntrinsic(unsigned Intr)
const uint64_t FltRoundConversionTable
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ MaxID
The highest possible ID. Must be some 2^k - 1.
@ AMDGPU_Gfx
Used for AMD graphics targets.
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ C
The default llvm calling convention, compatible with C.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
@ BSWAP
Byte Swap and Counting operators.
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
@ ADD
Simple integer binary arithmetic operators.
@ 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)...
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
@ FADD
Simple binary floating point operators.
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
@ 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...
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
@ SSUBO
Same for subtraction.
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
@ IS_FPCLASS
Performs a check of floating point class property, defined by IEEE-754.
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
@ UNDEF
UNDEF - An undefined node.
@ EXTRACT_ELEMENT
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant,...
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
@ GET_ROUNDING
Returns current rounding mode: -1 Undefined 0 Round to 0 1 Round to nearest, ties to even 2 Round to ...
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
@ SHL
Shift and rotation operations.
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
@ EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR.
@ 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.
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
@ SMULO
Same for multiplication.
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ 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...
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ 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.
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
@ 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,...
LLVM_ABI CondCode getSetCCSwappedOperands(CondCode Operation)
Return the operation corresponding to (Y op X) when given the operation for (X op Y).
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
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).
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
LLVM_ABI AttributeList getAttributes(LLVMContext &C, ID id, FunctionType *FT)
Return the attributes for an intrinsic.
LLVM_ABI FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys={})
Return the function type for an intrinsic.
BinaryOp_match< SpecificConstantMatch, SrcTy, TargetOpcode::G_SUB > m_Neg(const SrcTy &&Src)
Matches a register negated by a G_SUB.
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
GFCstOrSplatGFCstMatch m_GFCstOrSplat(std::optional< FPValueAndVReg > &FPValReg)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Define
Register definition.
@ Kill
The last use of a register.
@ Undef
Value of the register doesn't matter.
bool sd_match(SDNode *N, const SelectionDAG *DAG, Pattern &&P)
@ System
Synchronized with respect to all concurrently executing threads.
initializer< Ty > init(const Ty &Val)
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
NodeAddr< NodeBase * > Node
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
GenericUniformityInfo< SSAContext > UniformityInfo
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
FunctionAddr VTableAddr Value
ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred)
getICmpCondCode - Return the ISD condition code corresponding to the given LLVM IR integer condition ...
LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
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.
std::pair< Value *, Value * > buildCmpXchgValue(IRBuilderBase &Builder, Value *Ptr, Value *Cmp, Value *Val, Align Alignment)
Emit IR to implement the given cmpxchg operation on values in registers, returning the new value.
LLVM_ABI SDValue peekThroughBitcasts(SDValue V)
Return the non-bitcasted source operand of V if it exists.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
constexpr int64_t minIntN(int64_t N)
Gets the minimum value for a N-bit signed integer.
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
LLVM_ABI ConstantFPSDNode * isConstOrConstSplatFP(SDValue N, bool AllowUndefs=false)
Returns the SDNode if it is a constant splat BuildVector or constant float.
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
bool isReleaseOrStronger(AtomicOrdering AO)
static const MachineMemOperand::Flags MONoClobber
Mark the MMO of a uniform load if there are no potentially clobbering stores on any path from the sta...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
AtomicOrderingCABI
Atomic ordering for C11 / C++11's memory models.
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred)
getFCmpCondCode - Return the ISD condition code corresponding to the given LLVM IR floating-point con...
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...
static const MachineMemOperand::Flags MOCooperative
Mark the MMO of cooperative load/store atomics.
Value * buildAtomicRMWValue(AtomicRMWInst::BinOp Op, IRBuilderBase &Builder, Value *Loaded, Value *Val)
Emit IR to implement the given atomicrmw operation on values in registers, returning the new value.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
unsigned getUndefRegState(bool B)
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
FunctionAddr VTableAddr Next
DWARFExpression::Operation Op
unsigned M0(unsigned Val)
ArrayRef(const T &OneElt) -> ArrayRef< T >
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.
constexpr int64_t maxIntN(int64_t N)
Gets the maximum value for a N-bit signed integer.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::optional< ValueAndVReg > getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT returns its...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
static const MachineMemOperand::Flags MOLastUse
Mark the MMO of a load as the last use.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
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 Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
int popcount(T Value) noexcept
Count the number of set bits in a value.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
@ CLUSTER_WORKGROUP_MAX_ID_X
@ CLUSTER_WORKGROUP_MAX_ID_Z
@ CLUSTER_WORKGROUP_MAX_FLAT_ID
@ CLUSTER_WORKGROUP_MAX_ID_Y
ArgDescriptor WorkItemIDZ
ArgDescriptor WorkItemIDY
std::tuple< const ArgDescriptor *, const TargetRegisterClass *, LLT > getPreloadedValue(PreloadedValue Value) const
ArgDescriptor WorkItemIDX
static constexpr uint64_t encode(Fields... Values)
static std::tuple< typename Fields::ValueType... > decode(uint64_t Encoded)
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI const fltSemantics & IEEEhalf() LLVM_READNONE
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
static ArgDescriptor createStack(unsigned Offset, unsigned Mask=~0u)
MCRegister getRegister() const
static ArgDescriptor createArg(const ArgDescriptor &Arg, unsigned Mask)
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)
Helper struct shared between Function Specialization and SCCP Solver.
Represent subnormal handling kind for floating point instruction inputs and outputs.
@ Dynamic
Denormals have unknown treatment.
static constexpr DenormalMode getPreserveSign()
static constexpr DenormalMode getIEEE()
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
EVT changeTypeToInteger() const
Return the type converted to an equivalently sized integer or vector with integer element type.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
bool isByteSized() const
Return true if the bit size is a multiple of 8.
EVT changeElementType(EVT EltVT) const
Return a VT for a type whose attributes match ourselves with the exception of the element type that i...
uint64_t getScalarSizeInBits() const
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
TypeSize getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
bool isVector() const
Return true if this is a vector value type.
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
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.
EVT changeVectorElementType(EVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
LLVM_ABI const fltSemantics & getFltSemantics() const
Returns an APFloat semantics tag appropriate for the value type.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
bool isInteger() const
Return true if this is an integer or a vector integer type.
unsigned getPointerAddrSpace() const
unsigned getByValSize() const
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
bool isUnknown() const
Returns true if we don't know any bits.
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
void resetAll()
Resets the known state of all bits.
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from addition of LHS and RHS.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
int64_t Offset
Offset - This is an offset from the base Value*.
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
static LLVM_ABI MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
These are IR-level optimization flags that may be propagated to SDNodes.
bool hasNoUnsignedWrap() const
bool hasAllowContract() const
bool hasNoSignedWrap() const
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...
This structure contains all information that is necessary for lowering calls.
SDValue ConvergenceControlToken
SmallVector< ISD::InputArg, 32 > Ins
SmallVector< ISD::OutputArg, 32 > Outs
SmallVector< SDValue, 32 > OutVals
bool isBeforeLegalize() const