48#include "llvm/IR/IntrinsicsAMDGPU.h"
49#include "llvm/IR/IntrinsicsR600.h"
63#define DEBUG_TYPE "si-lower"
82 unsigned NumSGPRs = AMDGPU::SGPR_32RegClass.getNumRegs();
83 for (
unsigned Reg = 0;
Reg < NumSGPRs; ++
Reg) {
85 return AMDGPU::SGPR0 +
Reg;
101 TRI->getDefaultVectorSuperClassForBitWidth(32);
107 TRI->getDefaultVectorSuperClassForBitWidth(64);
145 TRI->getDefaultVectorSuperClassForBitWidth(320));
149 TRI->getDefaultVectorSuperClassForBitWidth(352));
153 TRI->getDefaultVectorSuperClassForBitWidth(384));
157 TRI->getDefaultVectorSuperClassForBitWidth(512));
164 TRI->getDefaultVectorSuperClassForBitWidth(1024));
166 if (Subtarget->has16BitInsts()) {
167 if (Subtarget->useRealTrue16Insts()) {
197 TRI->getDefaultVectorSuperClassForBitWidth(1024));
213 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
214 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
215 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32,
216 MVT::i1, MVT::v32i32},
220 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
221 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
222 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32,
223 MVT::i1, MVT::v32i32},
241 if (Subtarget->hasBF16PackedInsts()) {
311 {MVT::f32, MVT::i32, MVT::i64, MVT::f64, MVT::i1},
Expand);
318 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
319 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
320 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32},
323 {MVT::v2f32, MVT::v3f32, MVT::v4f32, MVT::v5f32,
324 MVT::v6f32, MVT::v7f32, MVT::v8f32, MVT::v9f32,
325 MVT::v10f32, MVT::v11f32, MVT::v12f32, MVT::v16f32},
329 {MVT::v2i1, MVT::v4i1, MVT::v2i8, MVT::v4i8, MVT::v2i16,
330 MVT::v3i16, MVT::v4i16, MVT::Other},
335 {MVT::i1, MVT::i32, MVT::i64, MVT::f32, MVT::f64},
Expand);
351 {MVT::v8i32, MVT::v8f32, MVT::v9i32, MVT::v9f32, MVT::v10i32,
352 MVT::v10f32, MVT::v11i32, MVT::v11f32, MVT::v12i32, MVT::v12f32,
353 MVT::v16i32, MVT::v16f32, MVT::v2i64, MVT::v2f64, MVT::v4i16,
354 MVT::v4f16, MVT::v4bf16, MVT::v3i64, MVT::v3f64, MVT::v6i32,
355 MVT::v6f32, MVT::v4i64, MVT::v4f64, MVT::v8i64, MVT::v8f64,
356 MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16, MVT::v16f16,
357 MVT::v16bf16, MVT::v16i64, MVT::v16f64, MVT::v32i32, MVT::v32f32,
358 MVT::v32i16, MVT::v32f16, MVT::v32bf16}) {
393 for (
MVT Vec64 : {MVT::v2i64, MVT::v2f64}) {
407 for (
MVT Vec64 : {MVT::v3i64, MVT::v3f64}) {
421 for (
MVT Vec64 : {MVT::v4i64, MVT::v4f64}) {
435 for (
MVT Vec64 : {MVT::v8i64, MVT::v8f64}) {
449 for (
MVT Vec64 : {MVT::v16i64, MVT::v16f64}) {
464 {MVT::v4i32, MVT::v4f32, MVT::v8i32, MVT::v8f32,
465 MVT::v16i32, MVT::v16f32, MVT::v32i32, MVT::v32f32},
468 if (Subtarget->hasPkMovB32()) {
489 {MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::v2i8, MVT::v4i8,
490 MVT::v8i8, MVT::v4i16, MVT::v4f16, MVT::v4bf16},
495 {MVT::v3i32, MVT::v3f32, MVT::v4i32, MVT::v4f32},
Custom);
499 {MVT::v5i32, MVT::v5f32, MVT::v6i32, MVT::v6f32,
500 MVT::v7i32, MVT::v7f32, MVT::v8i32, MVT::v8f32,
501 MVT::v9i32, MVT::v9f32, MVT::v10i32, MVT::v10f32,
502 MVT::v11i32, MVT::v11f32, MVT::v12i32, MVT::v12f32},
526 if (Subtarget->hasSMemRealTime() ||
531 if (Subtarget->has16BitInsts()) {
541 if (Subtarget->hasMadMacF32Insts())
559 if (Subtarget->hasIntClamp())
562 if (Subtarget->hasAddNoCarryInsts())
568 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
571 {MVT::f64, MVT::f32},
Legal);
575 {MVT::f64, MVT::f32},
Custom);
580 {MVT::f64, MVT::f32},
Legal);
583 if (Subtarget->haveRoundOpsF64())
613 if (Subtarget->has16BitInsts()) {
661 if (!Subtarget->useRealTrue16Insts() ||
662 !Subtarget->d16PreservesUnusedBits()) {
663 for (
MVT VT : {MVT::i16, MVT::f16, MVT::bf16}) {
669 if (!Subtarget->useRealTrue16Insts()) {
670 for (
MVT VT : {MVT::i16, MVT::f16, MVT::bf16}) {
682 if (Subtarget->hasBF16TransInsts())
698 {MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::v4i16, MVT::v4f16,
699 MVT::v4bf16, MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16,
700 MVT::v16f16, MVT::v16bf16, MVT::v32i16, MVT::v32f16}) {
735 if (Subtarget->hasVCvtPkIU16F32())
738 {MVT::v2i16, MVT::v4i16, MVT::v8i16, MVT::v16i16, MVT::v32i16},
745 {MVT::v2i16, MVT::v2f16, MVT::v2bf16},
Legal);
845 {MVT::v2f16, MVT::v2bf16, MVT::v4f16, MVT::v4bf16,
846 MVT::v8f16, MVT::v8bf16, MVT::v16f16, MVT::v16bf16,
847 MVT::v32f16, MVT::v32bf16},
849 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
856 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
Custom);
867 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
871 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
876 {MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16, MVT::v16f16,
877 MVT::v16bf16, MVT::v32i16, MVT::v32f16, MVT::v32bf16}) {
884 if (Subtarget->hasVOP3PInsts()) {
895 {MVT::v2i16, MVT::v2f16, MVT::v2bf16},
Custom);
898 {MVT::v4f16, MVT::v4i16, MVT::v4bf16, MVT::v8f16,
899 MVT::v8i16, MVT::v8bf16, MVT::v16f16, MVT::v16i16,
900 MVT::v16bf16, MVT::v32f16, MVT::v32i16, MVT::v32bf16},
903 for (
MVT VT : {MVT::v4i16, MVT::v8i16, MVT::v16i16, MVT::v32i16})
911 for (
MVT VT : {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16})
917 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
927 {MVT::v2f16, MVT::v4f16},
Custom);
933 if (Subtarget->hasBF16PackedInsts()) {
939 for (
MVT VT : {MVT::v4bf16, MVT::v8bf16, MVT::v16bf16, MVT::v32bf16})
947 if (Subtarget->hasAnyPackedFP32Ops()) {
951 {MVT::v4f32, MVT::v8f32, MVT::v16f32, MVT::v32f32},
954 if (Subtarget->hasAnyPackedFP64Ops()) {
960 {MVT::v4f64, MVT::v8f64, MVT::v16f64, MVT::v32f64},
Custom);
962 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
969 {MVT::v4f64, MVT::v8f64, MVT::v16f64, MVT::v32f64},
Custom);
978 {MVT::v4f64, MVT::v8f64, MVT::v16f64, MVT::v32f64},
983 if (Subtarget->hasAnyPackedU64Ops()) {
987 {MVT::v4i64, MVT::v8i64, MVT::v16i64, MVT::v32i64},
994 if (Subtarget->has16BitInsts()) {
1009 {MVT::v4i16, MVT::v4f16, MVT::v4bf16, MVT::v2i8, MVT::v4i8,
1010 MVT::v8i8, MVT::v8i16, MVT::v8f16, MVT::v8bf16,
1011 MVT::v16i16, MVT::v16f16, MVT::v16bf16, MVT::v32i16,
1012 MVT::v32f16, MVT::v32bf16},
1017 if (Subtarget->useVMulU64Inst())
1019 else if (Subtarget->hasScalarSMulU64())
1022 if (Subtarget->hasMad64_32())
1025 if (Subtarget->hasSafeSmemPrefetch() || Subtarget->hasVmemPrefInsts())
1031 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
1033 {MVT::f16, MVT::f32, MVT::f64, MVT::v2f16},
Legal);
1036 if (Subtarget->hasMinimum3Maximum3F32())
1039 if (Subtarget->hasMinimum3Maximum3PKF16()) {
1043 if (!Subtarget->hasMinimum3Maximum3F16())
1049 if (Subtarget->hasVOP3PInsts()) {
1052 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
1056 if (Subtarget->useMinMaxI64Insts())
1061 {MVT::Other, MVT::f32, MVT::v4f32, MVT::i16, MVT::f16,
1062 MVT::bf16, MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::i128,
1067 {MVT::v2f16, MVT::v2i16, MVT::v2bf16, MVT::v3f16,
1068 MVT::v3i16, MVT::v4f16, MVT::v4i16, MVT::v4bf16,
1069 MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::Other, MVT::f16,
1070 MVT::i16, MVT::bf16, MVT::i8, MVT::i128},
1085 SBufferLoadDiagnosticVTs.set(VT.SimpleTy);
1090 {MVT::Other, MVT::v2i16, MVT::v2f16, MVT::v2bf16,
1091 MVT::v3i16, MVT::v3f16, MVT::v4f16, MVT::v4i16,
1092 MVT::v4bf16, MVT::v8i16, MVT::v8f16, MVT::v8bf16,
1093 MVT::f16, MVT::i16, MVT::bf16, MVT::i8, MVT::i128},
1108 if (Subtarget->hasBF16ConversionInsts()) {
1110 {MVT::bf16, MVT::v2bf16},
Custom);
1114 if (Subtarget->hasBF16TransInsts()) {
1118 const bool HasE5M3ConversionInsts =
1119 Subtarget->hasFP8ConversionInsts() && Subtarget->hasFP8E5M3Insts();
1120 if (Subtarget->hasOCPFP8ConversionInsts() || HasE5M3ConversionInsts) {
1131 if (Subtarget->hasFP8F16ConversionInsts()) {
1136 if (Subtarget->hasCvtPkF16F32Inst()) {
1138 {MVT::v2f16, MVT::v4f16, MVT::v8f16, MVT::v16f16},
1191 if (Subtarget->has16BitInsts() && !Subtarget->hasMed3_16())
1232 static const MCPhysReg RCRegs[] = {AMDGPU::MODE};
1245 EVT DestVT,
EVT SrcVT)
const {
1247 ((((Opcode ==
ISD::FMAD && Subtarget->hasMadMixInsts()) ||
1248 (Opcode ==
ISD::FMA && Subtarget->hasFmaMixInsts())) &&
1250 (Opcode ==
ISD::FMA && Subtarget->hasFmaMixBF16Insts() &&
1257 LLT DestTy,
LLT SrcTy)
const {
1258 return ((Opcode == TargetOpcode::G_FMAD && Subtarget->hasMadMixInsts()) ||
1259 (Opcode == TargetOpcode::G_FMA && Subtarget->hasFmaMixInsts())) &&
1261 SrcTy.getScalarSizeInBits() == 16 &&
1282 return Subtarget->has16BitInsts()
1288 return Subtarget->has16BitInsts() ? MVT::i16 : MVT::i32;
1292 if (!Subtarget->has16BitInsts() && VT.
getSizeInBits() == 16)
1314 return (NumElts + 1) / 2;
1320 return NumElts * ((
Size + 31) / 32);
1329 unsigned &NumIntermediates,
MVT &RegisterVT)
const {
1338 MVT SimpleIntermediateVT =
1340 IntermediateVT = SimpleIntermediateVT;
1341 RegisterVT = Subtarget->has16BitInsts() ? SimpleIntermediateVT : MVT::i32;
1342 NumIntermediates = (NumElts + 1) / 2;
1343 return (NumElts + 1) / 2;
1348 IntermediateVT = RegisterVT;
1349 NumIntermediates = NumElts;
1350 return NumIntermediates;
1355 RegisterVT = MVT::i16;
1356 IntermediateVT = ScalarVT;
1357 NumIntermediates = NumElts;
1358 return NumIntermediates;
1362 RegisterVT = MVT::i32;
1363 IntermediateVT = ScalarVT;
1364 NumIntermediates = NumElts;
1365 return NumIntermediates;
1369 RegisterVT = MVT::i32;
1370 IntermediateVT = RegisterVT;
1371 NumIntermediates = NumElts * ((
Size + 31) / 32);
1372 return NumIntermediates;
1377 Context,
CC, VT, IntermediateVT, NumIntermediates, RegisterVT);
1382 unsigned MaxNumLanes) {
1383 assert(MaxNumLanes != 0);
1387 unsigned NumElts = std::min(MaxNumLanes, VT->getNumElements());
1392 return TLI.getValueType(
DL, Ty);
1398 unsigned MaxNumLanes) {
1404 assert(ST->getNumContainedTypes() == 2 &&
1405 ST->getContainedType(1)->isIntegerTy(32));
1419 return MVT::amdgpuBufferFatPointer;
1421 DL.getPointerSizeInBits(AS) == 192)
1422 return MVT::amdgpuBufferStridedPointer;
1431 DL.getPointerSizeInBits(AS) == 160) ||
1433 DL.getPointerSizeInBits(AS) == 192))
1440 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
1441 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
1442 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1444 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
1445 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
1446 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1447 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
1448 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
1449 case Intrinsic::amdgcn_flat_load_monitor_b32:
1450 case Intrinsic::amdgcn_global_load_monitor_b32:
1452 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
1453 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
1454 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1455 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
1456 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
1457 case Intrinsic::amdgcn_flat_load_monitor_b64:
1458 case Intrinsic::amdgcn_global_load_monitor_b64:
1460 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
1461 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128:
1462 case Intrinsic::amdgcn_global_store_async_from_lds_b128:
1463 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B:
1464 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B:
1465 case Intrinsic::amdgcn_flat_load_monitor_b128:
1466 case Intrinsic::amdgcn_global_load_monitor_b128:
1502 unsigned IntrID)
const {
1504 if (CI.
hasMetadata(LLVMContext::MD_invariant_load))
1520 bool IsSPrefetch = BufInfo && BufInfo->
Kind == AMDGPU::BufferKindPrefetch;
1521 std::optional<unsigned> AuxArg =
1536 if (RsrcIntr->IsImage) {
1551 Info.ptrVal = RsrcArg;
1555 if (RsrcIntr->IsImage) {
1556 unsigned MaxNumLanes = 4;
1571 std::numeric_limits<unsigned>::max());
1581 if (RsrcIntr->IsImage) {
1595 if (BufInfo && BufInfo->
Kind == AMDGPU::BufferKindLoadToLDS) {
1611 CI.
getContext(), Width * 8 * Subtarget->getWavefrontSize());
1621 if (BufInfo && BufInfo->
Kind == AMDGPU::BufferKindAtomicLoad) {
1624 std::numeric_limits<unsigned>::max());
1634 if ((RsrcIntr->IsImage && BaseOpcode->
NoReturn) || IsSPrefetch) {
1636 Info.memVT = MVT::i32;
1649 case Intrinsic::amdgcn_ds_ordered_add:
1650 case Intrinsic::amdgcn_ds_ordered_swap: {
1664 case Intrinsic::amdgcn_ds_add_gs_reg_rtn:
1665 case Intrinsic::amdgcn_ds_sub_gs_reg_rtn: {
1668 Info.ptrVal =
nullptr;
1674 case Intrinsic::amdgcn_ds_append:
1675 case Intrinsic::amdgcn_ds_consume: {
1689 case Intrinsic::amdgcn_ds_atomic_async_barrier_arrive_b64:
1690 case Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64: {
1691 Info.opc = (IntrID == Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64)
1696 Info.memVT = MVT::i64;
1704 case Intrinsic::amdgcn_image_bvh_dual_intersect_ray:
1705 case Intrinsic::amdgcn_image_bvh_intersect_ray:
1706 case Intrinsic::amdgcn_image_bvh8_intersect_ray: {
1709 MVT::getVT(IntrID == Intrinsic::amdgcn_image_bvh_intersect_ray
1712 ->getElementType(0));
1721 case Intrinsic::amdgcn_global_atomic_fmin_num:
1722 case Intrinsic::amdgcn_global_atomic_fmax_num:
1723 case Intrinsic::amdgcn_global_atomic_ordered_add_b64:
1724 case Intrinsic::amdgcn_flat_atomic_fmin_num:
1725 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
1736 case Intrinsic::amdgcn_cluster_load_b32:
1737 case Intrinsic::amdgcn_cluster_load_b64:
1738 case Intrinsic::amdgcn_cluster_load_b128:
1739 case Intrinsic::amdgcn_ds_load_tr6_b96:
1740 case Intrinsic::amdgcn_ds_load_tr4_b64:
1741 case Intrinsic::amdgcn_ds_load_tr8_b64:
1742 case Intrinsic::amdgcn_ds_load_tr16_b128:
1743 case Intrinsic::amdgcn_global_load_tr6_b96:
1744 case Intrinsic::amdgcn_global_load_tr4_b64:
1745 case Intrinsic::amdgcn_global_load_tr_b64:
1746 case Intrinsic::amdgcn_global_load_tr_b128:
1747 case Intrinsic::amdgcn_ds_read_tr4_b64:
1748 case Intrinsic::amdgcn_ds_read_tr6_b96:
1749 case Intrinsic::amdgcn_ds_read_tr8_b64:
1750 case Intrinsic::amdgcn_ds_read_tr16_b64: {
1759 case Intrinsic::amdgcn_flat_load_monitor_b32:
1760 case Intrinsic::amdgcn_flat_load_monitor_b64:
1761 case Intrinsic::amdgcn_flat_load_monitor_b128:
1762 case Intrinsic::amdgcn_global_load_monitor_b32:
1763 case Intrinsic::amdgcn_global_load_monitor_b64:
1764 case Intrinsic::amdgcn_global_load_monitor_b128: {
1775 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
1776 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
1777 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B: {
1788 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
1789 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
1790 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
1801 case Intrinsic::amdgcn_ds_gws_init:
1802 case Intrinsic::amdgcn_ds_gws_barrier:
1803 case Intrinsic::amdgcn_ds_gws_sema_v:
1804 case Intrinsic::amdgcn_ds_gws_sema_br:
1805 case Intrinsic::amdgcn_ds_gws_sema_p:
1806 case Intrinsic::amdgcn_ds_gws_sema_release_all: {
1816 Info.memVT = MVT::i32;
1818 Info.align =
Align(4);
1820 if (IntrID == Intrinsic::amdgcn_ds_gws_barrier)
1827 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
1828 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
1829 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
1830 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
1831 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
1832 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
1833 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
1834 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128: {
1849 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1850 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1851 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1852 case Intrinsic::amdgcn_global_store_async_from_lds_b128: {
1867 case Intrinsic::amdgcn_av_load_b8:
1868 case Intrinsic::amdgcn_av_load_b16:
1869 case Intrinsic::amdgcn_av_load_b32:
1870 case Intrinsic::amdgcn_av_load_b64:
1871 case Intrinsic::amdgcn_av_load_b128:
1872 case Intrinsic::amdgcn_av_store_b8:
1873 case Intrinsic::amdgcn_av_store_b16:
1874 case Intrinsic::amdgcn_av_store_b32:
1875 case Intrinsic::amdgcn_av_store_b64:
1876 case Intrinsic::amdgcn_av_store_b128: {
1882 Info.align =
Align(Info.memVT.getStoreSize());
1891 unsigned ScopeIdx = CI.
arg_size() - 1;
1895 Info.ssid = Ctx.getOrInsertSyncScopeID(Scope);
1899 case Intrinsic::amdgcn_load_to_lds:
1900 case Intrinsic::amdgcn_load_async_to_lds:
1901 case Intrinsic::amdgcn_global_load_lds:
1902 case Intrinsic::amdgcn_global_load_async_lds: {
1921 Width * 8 * Subtarget->getWavefrontSize());
1927 case Intrinsic::amdgcn_ds_bvh_stack_rtn:
1928 case Intrinsic::amdgcn_ds_bvh_stack_push4_pop1_rtn:
1929 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop1_rtn:
1930 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop2_rtn: {
1940 Info.memVT = MVT::i32;
1942 Info.align =
Align(4);
1948 case Intrinsic::amdgcn_s_prefetch_data:
1949 case Intrinsic::amdgcn_s_prefetch_inst:
1950 case Intrinsic::amdgcn_flat_prefetch:
1951 case Intrinsic::amdgcn_global_prefetch: {
1966 Type *&AccessTy)
const {
1967 Value *Ptr =
nullptr;
1968 switch (
II->getIntrinsicID()) {
1969 case Intrinsic::amdgcn_cluster_load_b128:
1970 case Intrinsic::amdgcn_cluster_load_b64:
1971 case Intrinsic::amdgcn_cluster_load_b32:
1972 case Intrinsic::amdgcn_ds_append:
1973 case Intrinsic::amdgcn_ds_consume:
1974 case Intrinsic::amdgcn_ds_load_tr8_b64:
1975 case Intrinsic::amdgcn_ds_load_tr16_b128:
1976 case Intrinsic::amdgcn_ds_load_tr4_b64:
1977 case Intrinsic::amdgcn_ds_load_tr6_b96:
1978 case Intrinsic::amdgcn_ds_read_tr4_b64:
1979 case Intrinsic::amdgcn_ds_read_tr6_b96:
1980 case Intrinsic::amdgcn_ds_read_tr8_b64:
1981 case Intrinsic::amdgcn_ds_read_tr16_b64:
1982 case Intrinsic::amdgcn_ds_ordered_add:
1983 case Intrinsic::amdgcn_ds_ordered_swap:
1984 case Intrinsic::amdgcn_ds_atomic_async_barrier_arrive_b64:
1985 case Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64:
1986 case Intrinsic::amdgcn_flat_atomic_fmax_num:
1987 case Intrinsic::amdgcn_flat_atomic_fmin_num:
1988 case Intrinsic::amdgcn_global_atomic_fmax_num:
1989 case Intrinsic::amdgcn_global_atomic_fmin_num:
1990 case Intrinsic::amdgcn_global_atomic_ordered_add_b64:
1991 case Intrinsic::amdgcn_global_load_tr_b64:
1992 case Intrinsic::amdgcn_global_load_tr_b128:
1993 case Intrinsic::amdgcn_global_load_tr4_b64:
1994 case Intrinsic::amdgcn_global_load_tr6_b96:
1995 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1996 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1997 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1998 case Intrinsic::amdgcn_global_store_async_from_lds_b128:
1999 case Intrinsic::amdgcn_av_load_b8:
2000 case Intrinsic::amdgcn_av_load_b16:
2001 case Intrinsic::amdgcn_av_load_b32:
2002 case Intrinsic::amdgcn_av_load_b64:
2003 case Intrinsic::amdgcn_av_load_b128:
2004 case Intrinsic::amdgcn_av_store_b8:
2005 case Intrinsic::amdgcn_av_store_b16:
2006 case Intrinsic::amdgcn_av_store_b32:
2007 case Intrinsic::amdgcn_av_store_b64:
2008 case Intrinsic::amdgcn_av_store_b128:
2009 Ptr =
II->getArgOperand(0);
2011 case Intrinsic::amdgcn_load_to_lds:
2012 case Intrinsic::amdgcn_load_async_to_lds:
2013 case Intrinsic::amdgcn_global_load_lds:
2014 case Intrinsic::amdgcn_global_load_async_lds:
2015 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
2016 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
2017 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
2018 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
2019 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
2020 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
2021 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
2022 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128:
2023 Ptr =
II->getArgOperand(1);
2028 AccessTy =
II->getType();
2034 unsigned AddrSpace)
const {
2035 if (!Subtarget->hasFlatInstOffsets()) {
2042 FlatAddrSpace FlatVariant =
2045 : FlatAddrSpace::FLAT;
2047 return AM.
Scale == 0 &&
2048 (AM.
BaseOffs == 0 || Subtarget->getInstrInfo()->isLegalFLATOffset(
2049 AM.
BaseOffs, AddrSpace, FlatVariant));
2053 if (Subtarget->hasFlatGlobalInsts())
2056 if (!Subtarget->hasAddr64() || Subtarget->useFlatForGlobal()) {
2069 return isLegalMUBUFAddressingMode(AM);
2072bool SITargetLowering::isLegalMUBUFAddressingMode(
const AddrMode &AM)
const {
2083 if (!
TII->isLegalMUBUFImmOffset(AM.BaseOffs))
2095 if (AM.HasBaseReg) {
2127 return isLegalMUBUFAddressingMode(AM);
2129 if (!Subtarget->hasScalarSubwordLoads()) {
2134 if (Ty->isSized() &&
DL.getTypeStoreSize(Ty) < 4)
2182 return Subtarget->hasFlatScratchEnabled()
2184 : isLegalMUBUFAddressingMode(AM);
2231 unsigned Size,
unsigned AddrSpace,
Align Alignment,
2240 if (!Subtarget->hasUnalignedDSAccessEnabled() && Alignment <
Align(4))
2243 Align RequiredAlignment(
2245 if (Subtarget->hasLDSMisalignedBugInWGPMode() &&
Size > 32 &&
2246 Alignment < RequiredAlignment)
2261 if (!Subtarget->hasUsableDSOffset() && Alignment <
Align(8))
2267 RequiredAlignment =
Align(4);
2269 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2285 *IsFast = (Alignment >= RequiredAlignment) ? 64
2286 : (Alignment <
Align(4)) ? 32
2293 if (!Subtarget->hasDS96AndDS128())
2299 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2308 *IsFast = (Alignment >= RequiredAlignment) ? 96
2309 : (Alignment <
Align(4)) ? 32
2316 if (!Subtarget->hasDS96AndDS128() || !Subtarget->useDS128())
2322 RequiredAlignment =
Align(8);
2324 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2333 *IsFast = (Alignment >= RequiredAlignment) ? 128
2334 : (Alignment <
Align(4)) ? 32
2351 *IsFast = (Alignment >= RequiredAlignment) ?
Size : 0;
2353 return Alignment >= RequiredAlignment ||
2354 Subtarget->hasUnalignedDSAccessEnabled();
2362 bool AlignedBy4 = Alignment >=
Align(4);
2363 if (Subtarget->hasUnalignedScratchAccessEnabled()) {
2365 *IsFast = AlignedBy4 ?
Size : 1;
2370 *IsFast = AlignedBy4;
2381 return Alignment >=
Align(4) ||
2382 Subtarget->hasUnalignedBufferAccessEnabled();
2395 if (!Subtarget->hasRelaxedBufferOOBMode() &&
2410 return Size >= 32 && Alignment >=
Align(4);
2415 unsigned *IsFast)
const {
2417 Alignment, Flags, IsFast);
2422 unsigned AddrSpace,
Align Alignment,
2424 unsigned *IsFast)
const {
2430 Alignment, Flags, IsFast);
2441 if (
Op.size() >= 16 &&
2445 if (
Op.size() >= 8 &&
Op.isDstAligned(
Align(4)))
2463 unsigned DestAS)
const {
2466 Subtarget->hasGloballyAddressableScratch()) {
2497 unsigned Index)
const {
2511 unsigned MinAlign = Subtarget->useRealTrue16Insts() ? 16 : 32;
2516 if (Subtarget->has16BitInsts() && VT == MVT::i16) {
2550 if (Subtarget->hasScalarSubwordLoads() &&
N->getOpcode() ==
ISD::LOAD &&
2601 auto [InputPtrReg, RC, ArgTy] =
2611 Chain, SL,
MRI.getLiveInVirtReg(InputPtrReg->getRegister()), PtrVT);
2617 const SDLoc &SL)
const {
2624 const SDLoc &SL)
const {
2627 std::optional<uint32_t> KnownSize =
2629 if (KnownSize.has_value())
2656 Val = getFPExtOrFPRound(DAG, Val, SL, VT);
2671SDValue SITargetLowering::lowerKernargMemParameter(
2676 MachinePointerInfo PtrInfo =
2685 int64_t OffsetDiff =
Offset - AlignDownOffset;
2691 SDValue Ptr = lowerKernArgParameterPtr(DAG, SL, Chain, AlignDownOffset);
2702 ArgVal = convertArgType(DAG, VT, MemVT, SL, ArgVal,
Signed, Arg);
2707 SDValue Ptr = lowerKernArgParameterPtr(DAG, SL, Chain,
Offset);
2721 const SDLoc &SL)
const {
2768 MachinePointerInfo PtrInfo =
2794 SDValue ConvertedVal = convertABITypeToValueType(DAG, ArgValue, VA, SL);
2795 if (ConvertedVal == ArgValue)
2796 return ConvertedVal;
2808 DAG.
getMachineNode(AMDGPU::S_GETREG_B32_const, SL, VT, ClusterIdField);
2812SDValue SITargetLowering::lowerWorkGroupId(
2817 if (!Subtarget->hasClusters())
2818 return getPreloadedValue(DAG, MFI, VT, WorkGroupIdPV);
2826 SDValue ClusterIdXYZ = getPreloadedValue(DAG, MFI, VT, WorkGroupIdPV);
2827 SDLoc SL(ClusterIdXYZ);
2828 SDValue ClusterMaxIdXYZ = getPreloadedValue(DAG, MFI, VT, ClusterMaxIdPV);
2831 SDValue ClusterWorkGroupIdXYZ =
2832 getPreloadedValue(DAG, MFI, VT, ClusterWorkGroupIdPV);
2842 return ClusterIdXYZ;
2854SDValue SITargetLowering::lowerClusterWorkGroupValue(
2857 if (!Subtarget->hasClusters())
2866 return getPreloadedValue(DAG, MFI, VT, PV);
2882SDValue SITargetLowering::getPreloadedValue(
2885 const ArgDescriptor *
Reg =
nullptr;
2890 const ArgDescriptor WorkGroupIDX =
2898 const ArgDescriptor WorkGroupIDZ =
2900 const ArgDescriptor ClusterWorkGroupIDX =
2902 const ArgDescriptor ClusterWorkGroupIDY =
2904 const ArgDescriptor ClusterWorkGroupIDZ =
2906 const ArgDescriptor ClusterWorkGroupMaxIDX =
2908 const ArgDescriptor ClusterWorkGroupMaxIDY =
2910 const ArgDescriptor ClusterWorkGroupMaxIDZ =
2912 const ArgDescriptor ClusterWorkGroupMaxFlatID =
2915 auto LoadConstant = [&](
unsigned N) {
2919 if (Subtarget->hasArchitectedSGPRs() &&
2927 Reg = &WorkGroupIDX;
2928 RC = &AMDGPU::SReg_32RegClass;
2932 Reg = &WorkGroupIDY;
2933 RC = &AMDGPU::SReg_32RegClass;
2937 Reg = &WorkGroupIDZ;
2938 RC = &AMDGPU::SReg_32RegClass;
2942 if (HasFixedDims && ClusterDims.
getDims()[0] == 1)
2943 return LoadConstant(0);
2944 Reg = &ClusterWorkGroupIDX;
2945 RC = &AMDGPU::SReg_32RegClass;
2949 if (HasFixedDims && ClusterDims.
getDims()[1] == 1)
2950 return LoadConstant(0);
2951 Reg = &ClusterWorkGroupIDY;
2952 RC = &AMDGPU::SReg_32RegClass;
2956 if (HasFixedDims && ClusterDims.
getDims()[2] == 1)
2957 return LoadConstant(0);
2958 Reg = &ClusterWorkGroupIDZ;
2959 RC = &AMDGPU::SReg_32RegClass;
2964 return LoadConstant(ClusterDims.
getDims()[0] - 1);
2965 Reg = &ClusterWorkGroupMaxIDX;
2966 RC = &AMDGPU::SReg_32RegClass;
2971 return LoadConstant(ClusterDims.
getDims()[1] - 1);
2972 Reg = &ClusterWorkGroupMaxIDY;
2973 RC = &AMDGPU::SReg_32RegClass;
2978 return LoadConstant(ClusterDims.
getDims()[2] - 1);
2979 Reg = &ClusterWorkGroupMaxIDZ;
2980 RC = &AMDGPU::SReg_32RegClass;
2985 const std::array<unsigned, 3> &Dims = ClusterDims.
getDims();
2986 return LoadConstant(Dims[0] * Dims[1] * Dims[2] - 1);
2988 Reg = &ClusterWorkGroupMaxFlatID;
2989 RC = &AMDGPU::SReg_32RegClass;
3020 for (
unsigned I = 0,
E = Ins.
size(), PSInputNum = 0;
I !=
E; ++
I) {
3024 "vector type argument should have been split");
3029 bool SkipArg = !Arg->
Used && !Info->isPSInputAllocated(PSInputNum);
3037 "unexpected vector split in ps argument type");
3051 Info->markPSInputAllocated(PSInputNum);
3053 Info->markPSInputEnabled(PSInputNum);
3069 if (Info.hasWorkItemIDX()) {
3071 MRI.setType(MF.
addLiveIn(Reg, &AMDGPU::VGPR_32RegClass), I32);
3075 (Subtarget->hasPackedTID() && Info.hasWorkItemIDY()) ? 0x3ff : ~0u;
3079 if (Info.hasWorkItemIDY()) {
3080 assert(Info.hasWorkItemIDX());
3081 if (Subtarget->hasPackedTID()) {
3082 Info.setWorkItemIDY(
3085 unsigned Reg = AMDGPU::VGPR1;
3086 MRI.setType(MF.
addLiveIn(Reg, &AMDGPU::VGPR_32RegClass), I32);
3093 if (Info.hasWorkItemIDZ()) {
3094 assert(Info.hasWorkItemIDX() && Info.hasWorkItemIDY());
3095 if (Subtarget->hasPackedTID()) {
3096 Info.setWorkItemIDZ(
3099 unsigned Reg = AMDGPU::VGPR2;
3100 MRI.setType(MF.
addLiveIn(Reg, &AMDGPU::VGPR_32RegClass), I32);
3110 unsigned NumArgRegs) {
3113 if (RegIdx == ArgSGPRs.
size())
3116 unsigned Reg = ArgSGPRs[RegIdx];
3161 const unsigned Mask = 0x3ff;
3170 auto &
ArgInfo = Info.getArgInfo();
3182 if (Info.hasImplicitArgPtr())
3190 if (Info.hasWorkGroupIDX())
3193 if (Info.hasWorkGroupIDY())
3196 if (Info.hasWorkGroupIDZ())
3199 if (Info.hasLDSKernelId())
3210 Register ImplicitBufferPtrReg = Info.addImplicitBufferPtr(
TRI);
3211 MF.
addLiveIn(ImplicitBufferPtrReg, &AMDGPU::SGPR_64RegClass);
3217 Register PrivateSegmentBufferReg = Info.addPrivateSegmentBuffer(
TRI);
3218 MF.
addLiveIn(PrivateSegmentBufferReg, &AMDGPU::SGPR_128RegClass);
3223 Register DispatchPtrReg = Info.addDispatchPtr(
TRI);
3224 MF.
addLiveIn(DispatchPtrReg, &AMDGPU::SGPR_64RegClass);
3230 MF.
addLiveIn(QueuePtrReg, &AMDGPU::SGPR_64RegClass);
3236 Register InputPtrReg = Info.addKernargSegmentPtr(
TRI);
3245 MF.
addLiveIn(DispatchIDReg, &AMDGPU::SGPR_64RegClass);
3250 Register FlatScratchInitReg = Info.addFlatScratchInit(
TRI);
3251 MF.
addLiveIn(FlatScratchInitReg, &AMDGPU::SGPR_64RegClass);
3256 Register PrivateSegmentSizeReg = Info.addPrivateSegmentSize(
TRI);
3257 MF.
addLiveIn(PrivateSegmentSizeReg, &AMDGPU::SGPR_32RegClass);
3272 unsigned LastExplicitArgOffset = Subtarget->getExplicitKernelArgOffset();
3274 bool InPreloadSequence =
true;
3276 bool AlignedForImplictArgs =
false;
3277 unsigned ImplicitArgOffset = 0;
3278 for (
auto &Arg :
F.args()) {
3279 if (!InPreloadSequence || !Arg.hasInRegAttr())
3282 unsigned ArgIdx = Arg.getArgNo();
3285 if (InIdx < Ins.
size() &&
3286 (!Ins[InIdx].isOrigArg() || Ins[InIdx].getOrigArgIndex() != ArgIdx))
3289 for (; InIdx < Ins.
size() && Ins[InIdx].isOrigArg() &&
3290 Ins[InIdx].getOrigArgIndex() == ArgIdx;
3292 assert(ArgLocs[ArgIdx].isMemLoc());
3293 auto &ArgLoc = ArgLocs[InIdx];
3295 unsigned ArgOffset = ArgLoc.getLocMemOffset();
3297 unsigned NumAllocSGPRs =
3298 alignTo(ArgLoc.getLocVT().getFixedSizeInBits(), 32) / 32;
3301 if (Arg.hasAttribute(
"amdgpu-hidden-argument")) {
3302 if (!AlignedForImplictArgs) {
3304 alignTo(LastExplicitArgOffset,
3305 Subtarget->getAlignmentForImplicitArgPtr()) -
3306 LastExplicitArgOffset;
3307 AlignedForImplictArgs =
true;
3309 ArgOffset += ImplicitArgOffset;
3313 if (ArgLoc.getLocVT().getStoreSize() < 4 && Alignment < 4) {
3314 assert(InIdx >= 1 &&
"No previous SGPR");
3315 Info.getArgInfo().PreloadKernArgs[InIdx].Regs.push_back(
3316 Info.getArgInfo().PreloadKernArgs[InIdx - 1].Regs[0]);
3320 unsigned Padding = ArgOffset - LastExplicitArgOffset;
3321 unsigned PaddingSGPRs =
alignTo(Padding, 4) / 4;
3324 InPreloadSequence =
false;
3330 TRI.getSGPRClassForBitWidth(NumAllocSGPRs * 32);
3332 Info.addPreloadedKernArg(
TRI, RC, NumAllocSGPRs, InIdx, PaddingSGPRs);
3334 if (PreloadRegs->
size() > 1)
3335 RC = &AMDGPU::SGPR_32RegClass;
3336 for (
auto &Reg : *PreloadRegs) {
3342 LastExplicitArgOffset = NumAllocSGPRs * 4 + ArgOffset;
3351 if (Info.hasLDSKernelId()) {
3352 Register Reg = Info.addLDSKernelId();
3353 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3362 bool IsShader)
const {
3363 bool HasArchitectedSGPRs = Subtarget->hasArchitectedSGPRs();
3364 if (Subtarget->hasUserSGPRInit16BugInWave32() && !IsShader) {
3370 assert(!HasArchitectedSGPRs &&
"Unhandled feature for the subtarget");
3372 unsigned CurrentUserSGPRs = Info.getNumUserSGPRs();
3376 unsigned NumRequiredSystemSGPRs =
3377 Info.hasWorkGroupIDX() + Info.hasWorkGroupIDY() +
3378 Info.hasWorkGroupIDZ() + Info.hasWorkGroupInfo();
3379 for (
unsigned i = NumRequiredSystemSGPRs + CurrentUserSGPRs; i < 16; ++i) {
3380 Register Reg = Info.addReservedUserSGPR();
3381 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3386 if (!HasArchitectedSGPRs) {
3387 if (Info.hasWorkGroupIDX()) {
3388 Register Reg = Info.addWorkGroupIDX();
3389 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3393 if (Info.hasWorkGroupIDY()) {
3394 Register Reg = Info.addWorkGroupIDY();
3395 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3399 if (Info.hasWorkGroupIDZ()) {
3400 Register Reg = Info.addWorkGroupIDZ();
3401 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3406 if (Info.hasWorkGroupInfo()) {
3407 Register Reg = Info.addWorkGroupInfo();
3408 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3412 if (Info.hasPrivateSegmentWaveByteOffset()) {
3414 unsigned PrivateSegmentWaveByteOffsetReg;
3417 PrivateSegmentWaveByteOffsetReg =
3418 Info.getPrivateSegmentWaveByteOffsetSystemSGPR();
3422 if (PrivateSegmentWaveByteOffsetReg == AMDGPU::NoRegister) {
3424 Info.setPrivateSegmentWaveByteOffset(PrivateSegmentWaveByteOffsetReg);
3427 PrivateSegmentWaveByteOffsetReg = Info.addPrivateSegmentWaveByteOffset();
3429 MF.
addLiveIn(PrivateSegmentWaveByteOffsetReg, &AMDGPU::SGPR_32RegClass);
3430 CCInfo.
AllocateReg(PrivateSegmentWaveByteOffsetReg);
3433 assert(!Subtarget->hasUserSGPRInit16BugInWave32() || IsShader ||
3434 Info.getNumPreloadedSGPRs() >= 16);
3449 if (HasStackObjects)
3450 Info.setHasNonSpillStackObjects(
true);
3455 HasStackObjects =
true;
3459 bool RequiresStackAccess = HasStackObjects || MFI.
hasCalls();
3461 if (!ST.hasFlatScratchEnabled()) {
3462 if (RequiresStackAccess && ST.isAmdHsaOrMesa(MF.
getFunction())) {
3469 Info.setScratchRSrcReg(PrivateSegmentBufferReg);
3471 unsigned ReservedBufferReg =
TRI.reservedPrivateSegmentBufferReg(MF);
3481 Info.setScratchRSrcReg(ReservedBufferReg);
3500 if (!
MRI.isLiveIn(AMDGPU::SGPR32)) {
3501 Info.setStackPtrOffsetReg(AMDGPU::SGPR32);
3508 for (
unsigned Reg : AMDGPU::SGPR_32RegClass) {
3509 if (!
MRI.isLiveIn(
Reg)) {
3510 Info.setStackPtrOffsetReg(
Reg);
3515 if (Info.getStackPtrOffsetReg() == AMDGPU::SP_REG)
3522 if (ST.getFrameLowering()->hasFP(MF)) {
3523 Info.setFrameOffsetReg(AMDGPU::SGPR33);
3539 const MCPhysReg *IStart =
TRI->getCalleeSavedRegsViaCopy(Entry->getParent());
3548 if (AMDGPU::SReg_64RegClass.
contains(*
I))
3549 RC = &AMDGPU::SGPR_64RegClass;
3550 else if (AMDGPU::SReg_32RegClass.
contains(*
I))
3551 RC = &AMDGPU::SGPR_32RegClass;
3557 Entry->addLiveIn(*
I);
3562 for (
auto *Exit : Exits)
3564 TII->get(TargetOpcode::COPY), *
I)
3579 bool IsError =
false;
3583 Fn,
"unsupported non-compute shaders with HSA",
DL.getDebugLoc()));
3601 !Info->hasLDSKernelId() && !Info->hasWorkItemIDX() &&
3602 !Info->hasWorkItemIDY() && !Info->hasWorkItemIDZ());
3604 if (!Subtarget->hasFlatScratchEnabled())
3609 !Subtarget->hasArchitectedSGPRs())
3610 assert(!Info->hasWorkGroupIDX() && !Info->hasWorkGroupIDY() &&
3611 !Info->hasWorkGroupIDZ());
3614 bool IsWholeWaveFunc = Info->isWholeWaveFunction();
3632 if ((Info->getPSInputAddr() & 0x7F) == 0 ||
3633 ((Info->getPSInputAddr() & 0xF) == 0 && Info->isPSInputAllocated(11))) {
3636 Info->markPSInputAllocated(0);
3637 Info->markPSInputEnabled(0);
3639 if (Subtarget->isAmdPalOS()) {
3648 unsigned PsInputBits = Info->getPSInputAddr() & Info->getPSInputEnable();
3649 if ((PsInputBits & 0x7F) == 0 ||
3650 ((PsInputBits & 0xF) == 0 && (PsInputBits >> 11 & 1)))
3653 }
else if (IsKernel) {
3654 assert(Info->hasWorkGroupIDX() && Info->hasWorkItemIDX());
3666 if (IsKernel && Subtarget->hasKernargPreload())
3670 }
else if (!IsGraphics) {
3675 if (!Subtarget->hasFlatScratchEnabled())
3687 Info->setNumWaveDispatchSGPRs(
3689 Info->setNumWaveDispatchVGPRs(
3691 }
else if (Info->getNumKernargPreloadedSGPRs()) {
3692 Info->setNumWaveDispatchSGPRs(Info->getNumUserSGPRs());
3697 if (IsWholeWaveFunc) {
3699 {MVT::i1, MVT::Other}, Chain);
3711 for (
unsigned i = IsWholeWaveFunc ? 1 : 0, e = Ins.
size(), ArgIdx = 0; i != e;
3722 if (IsEntryFunc && VA.
isMemLoc()) {
3746 if (Arg.
isOrigArg() && Info->getArgInfo().PreloadKernArgs.count(i)) {
3750 int64_t OffsetDiff =
Offset - AlignDownOffset;
3757 Info->getArgInfo().PreloadKernArgs.find(i)->getSecond().Regs[0];
3768 NewArg = convertArgType(DAG, VT, MemVT,
DL, ArgVal,
3769 Ins[i].Flags.isSExt(), &Ins[i]);
3777 Info->getArgInfo().PreloadKernArgs.find(i)->getSecond().Regs;
3780 if (PreloadRegs.
size() == 1) {
3781 Register VReg =
MRI.getLiveInVirtReg(PreloadRegs[0]);
3786 TRI->getRegSizeInBits(*RC)));
3794 for (
auto Reg : PreloadRegs) {
3801 PreloadRegs.size()),
3818 NewArg = convertArgType(DAG, VT, MemVT,
DL, NewArg,
3819 Ins[i].Flags.isSExt(), &Ins[i]);
3831 "hidden argument in kernel signature was not preloaded",
3837 lowerKernargMemParameter(DAG, VT, MemVT,
DL, Chain,
Offset,
3838 Alignment, Ins[i].Flags.isSExt(), &Ins[i]);
3858 if (!IsEntryFunc && VA.
isMemLoc()) {
3859 SDValue Val = lowerStackParameter(DAG, VA,
DL, Chain, Arg);
3870 if (AMDGPU::VGPR_32RegClass.
contains(Reg))
3871 RC = &AMDGPU::VGPR_32RegClass;
3872 else if (AMDGPU::SGPR_32RegClass.
contains(Reg))
3873 RC = &AMDGPU::SGPR_32RegClass;
3879 if (Arg.
Flags.
isInReg() && RC == &AMDGPU::VGPR_32RegClass) {
3885 ReadFirstLane, Val);
3894 Val = convertABITypeToValueType(DAG, Val, VA,
DL);
3903 Info->setBytesInStackArgArea(StackArgSize);
3905 return Chains.
empty() ? Chain
3914 const Type *RetTy)
const {
3927 unsigned MaxNumVGPRs = Subtarget->getMaxNumVGPRs(MF);
3928 unsigned TotalNumVGPRs = Subtarget->getAddressableNumArchVGPRs();
3929 for (
unsigned i = MaxNumVGPRs; i < TotalNumVGPRs; ++i)
3930 if (CCInfo.
isAllocated(AMDGPU::VGPR_32RegClass.getRegister(i)))
3953 Info->setIfReturnsVoid(Outs.
empty());
3954 bool IsWaveEnd = Info->returnsVoid() && IsShader;
3973 for (
unsigned I = 0, RealRVLocIdx = 0, E = RVLocs.
size();
I != E;
3974 ++
I, ++RealRVLocIdx) {
3978 SDValue Arg = OutVals[RealRVLocIdx];
4002 ReadFirstLane, Arg);
4009 if (!Info->isEntryFunction()) {
4015 if (AMDGPU::SReg_64RegClass.
contains(*
I))
4017 else if (AMDGPU::SReg_32RegClass.
contains(*
I))
4030 unsigned Opc = AMDGPUISD::ENDPGM;
4032 Opc = Info->isWholeWaveFunction() ? AMDGPUISD::WHOLE_WAVE_RETURN
4033 : IsShader ? AMDGPUISD::RETURN_TO_EPILOG
4034 : AMDGPUISD::RET_GLUE;
4065 Val = convertABITypeToValueType(DAG, Val, VA,
DL);
4118 const auto [OutgoingArg, ArgRC, ArgTy] =
4123 const auto [IncomingArg, IncomingArgRC, Ty] =
4125 assert(IncomingArgRC == ArgRC);
4128 EVT ArgVT =
TRI->getSpillSize(*ArgRC) == 8 ? MVT::i64 : MVT::i32;
4136 InputReg = getImplicitArgPtr(DAG,
DL);
4138 std::optional<uint32_t> Id =
4140 if (Id.has_value()) {
4151 if (OutgoingArg->isRegister()) {
4152 RegsToPass.emplace_back(OutgoingArg->getRegister(), InputReg);
4153 if (!CCInfo.
AllocateReg(OutgoingArg->getRegister()))
4156 unsigned SpecialArgOffset =
4167 auto [OutgoingArg, ArgRC, Ty] =
4170 std::tie(OutgoingArg, ArgRC, Ty) =
4173 std::tie(OutgoingArg, ArgRC, Ty) =
4188 const bool NeedWorkItemIDX = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-x");
4189 const bool NeedWorkItemIDY = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-y");
4190 const bool NeedWorkItemIDZ = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-z");
4195 if (Subtarget->getMaxWorkitemID(
F, 0) != 0) {
4203 NeedWorkItemIDY && Subtarget->getMaxWorkitemID(
F, 1) != 0) {
4213 NeedWorkItemIDZ && Subtarget->getMaxWorkitemID(
F, 2) != 0) {
4222 if (!InputReg && (NeedWorkItemIDX || NeedWorkItemIDY || NeedWorkItemIDZ)) {
4223 if (!IncomingArgX && !IncomingArgY && !IncomingArgZ) {
4234 : IncomingArgY ? *IncomingArgY
4241 if (OutgoingArg->isRegister()) {
4243 RegsToPass.emplace_back(OutgoingArg->getRegister(), InputReg);
4269 if (Callee->isDivergent())
4276 const uint32_t *CallerPreserved =
TRI->getCallPreservedMask(MF, CallerCC);
4280 if (!CallerPreserved)
4283 bool CCMatch = CallerCC == CalleeCC;
4296 if (Arg.hasByValAttr())
4310 const uint32_t *CalleePreserved =
TRI->getCallPreservedMask(MF, CalleeCC);
4311 if (!
TRI->regmaskSubsetEqual(CallerPreserved, CalleePreserved))
4320 CCState CCInfo(CalleeCC, IsVarArg, MF, ArgLocs, Ctx);
4333 for (
const auto &[CCVA, ArgVal] :
zip_equal(ArgLocs, OutVals)) {
4335 if (!CCVA.isRegLoc())
4340 if (ArgVal->
isDivergent() &&
TRI->isSGPRPhysReg(CCVA.getLocReg())) {
4342 dbgs() <<
"Cannot tail call due to divergent outgoing argument in "
4366enum ChainCallArgIdx {
4388 bool UsesDynamicVGPRs =
false;
4389 if (IsChainCallConv) {
4394 auto RequestedExecIt =
4396 return Arg.OrigArgIndex == 2;
4398 assert(RequestedExecIt != CLI.
Outs.end() &&
"No node for EXEC");
4400 size_t SpecialArgsBeginIdx = RequestedExecIt - CLI.
Outs.begin();
4403 CLI.
Outs.erase(RequestedExecIt, CLI.
Outs.end());
4406 "Haven't popped all the special args");
4409 CLI.
Args[ChainCallArgIdx::Exec];
4410 if (!RequestedExecArg.
Ty->
isIntegerTy(Subtarget->getWavefrontSize()))
4418 ArgNode->getAPIntValue(),
DL, ArgNode->getValueType(0)));
4420 ChainCallSpecialArgs.
push_back(Arg.Node);
4423 PushNodeOrTargetConstant(RequestedExecArg);
4429 if (FlagsValue.
isZero()) {
4430 if (CLI.
Args.size() > ChainCallArgIdx::Flags + 1)
4432 "no additional args allowed if flags == 0");
4434 if (CLI.
Args.size() != ChainCallArgIdx::FallbackCallee + 1) {
4438 if (!Subtarget->isWave32()) {
4440 CLI, InVals,
"dynamic VGPR mode is only supported for wave32");
4443 UsesDynamicVGPRs =
true;
4444 std::for_each(CLI.
Args.begin() + ChainCallArgIdx::NumVGPRs,
4445 CLI.
Args.end(), PushNodeOrTargetConstant);
4454 bool IsSibCall =
false;
4468 "unsupported call to variadic function ");
4476 "unsupported required tail call to function ");
4481 Outs, OutVals, Ins, DAG);
4485 "site marked musttail or on llvm.amdgcn.cs.chain");
4492 if (!TailCallOpt && IsTailCall)
4516 if (!Subtarget->hasFlatScratchEnabled()) {
4539 auto *
TRI = Subtarget->getRegisterInfo();
4546 if (!IsSibCall || IsChainCallConv) {
4547 if (!Subtarget->hasFlatScratchEnabled()) {
4553 RegsToPass.emplace_back(
4561 const unsigned NumSpecialInputs = RegsToPass.size();
4563 MVT PtrVT = MVT::i32;
4566 for (
unsigned i = 0, e = ArgLocs.
size(); i != e; ++i) {
4595 RegsToPass.push_back(std::pair(VA.
getLocReg(), Arg));
4603 int32_t
Offset = LocMemOffset;
4610 unsigned OpSize = Flags.isByVal() ? Flags.getByValSize()
4616 ? Flags.getNonZeroByValAlign()
4643 if (Outs[i].Flags.isByVal()) {
4645 DAG.
getConstant(Outs[i].Flags.getByValSize(),
DL, MVT::i32);
4648 Outs[i].Flags.getNonZeroByValAlign(),
4649 Outs[i].Flags.getNonZeroByValAlign(),
4651 nullptr, std::nullopt, DstInfo,
4657 DAG.
getStore(Chain,
DL, Arg, DstAddr, DstInfo, Alignment);
4663 if (!MemOpChains.
empty())
4679 unsigned ArgIdx = 0;
4680 for (
auto [Reg, Val] : RegsToPass) {
4681 if (ArgIdx++ >= NumSpecialInputs &&
4682 (IsChainCallConv || !Val->
isDivergent()) &&
TRI->isSGPRPhysReg(Reg)) {
4708 if (IsTailCall && !IsSibCall) {
4713 std::vector<SDValue>
Ops({Chain});
4719 Ops.push_back(Callee);
4736 Ops.push_back(Callee);
4747 if (IsChainCallConv)
4752 for (
auto &[Reg, Val] : RegsToPass)
4756 const uint32_t *Mask =
TRI->getCallPreservedMask(MF, CallConv);
4757 assert(Mask &&
"Missing call preserved mask for calling convention");
4767 MVT::Glue, GlueOps),
4772 Ops.push_back(InGlue);
4778 unsigned OPC = AMDGPUISD::TC_RETURN;
4781 OPC = AMDGPUISD::TC_RETURN_GFX;
4785 OPC = UsesDynamicVGPRs ? AMDGPUISD::TC_RETURN_CHAIN_DVGPR
4786 : AMDGPUISD::TC_RETURN_CHAIN;
4792 if (Info->isWholeWaveFunction())
4793 OPC = AMDGPUISD::TC_RETURN_GFX_WholeWave;
4803 Chain =
Call.getValue(0);
4804 InGlue =
Call.getValue(1);
4806 uint64_t CalleePopBytes = NumBytes;
4827 EVT VT =
Op.getValueType();
4841 "Stack grows upwards for AMDGPU");
4843 Chain = BaseAddr.getValue(1);
4845 const bool HasFlatScratch = Subtarget->hasFlatScratchEnabled();
4846 const unsigned WavefrontSizeLog2 = Subtarget->getWavefrontSizeLog2();
4849 if (Alignment > StackAlign) {
4850 uint64_t ScaledAlignment = Alignment.value()
4851 << (HasFlatScratch ? 0 : WavefrontSizeLog2);
4852 uint64_t StackAlignMask = ScaledAlignment - 1;
4859 assert(
Size.getValueType() == MVT::i32 &&
"Size must be 32-bit");
4868 DAG.
getConstant(WavefrontSizeLog2, dl, MVT::i32));
4879 if (!HasFlatScratch) {
4882 DAG.
getConstant(WavefrontSizeLog2, dl, MVT::i32));
4899 if (
Op.getValueType() != MVT::i32)
4918 assert(
Op.getValueType() == MVT::i32);
4927 Op.getOperand(0), IntrinID, GetRoundBothImm);
4961 SDValue RoundModeTimesNumBits =
4981 TableEntry, EnumOffset);
4997 static_cast<uint32_t>(ConstMode->getZExtValue()),
5009 if (UseReducedTable) {
5015 SDValue RoundModeTimesNumBits =
5035 SDValue RoundModeTimesNumBits =
5044 NewMode = TruncTable;
5053 ReadFirstLaneID, NewMode);
5066 IntrinID, RoundBothImm, NewMode);
5074 return Op.getOperand(0);
5079 if (!Subtarget->hasSafeSmemPrefetch() && !
Op.getConstantOperandVal(4))
5088 SDValue Src =
Op.getOperand(IsStrict ? 1 : 0);
5089 EVT SrcVT = Src.getValueType();
5098 EVT DstVT =
Op.getValueType();
5107 if (
Op.getValueType() != MVT::i64)
5121 Op.getOperand(0), IntrinID, ModeHwRegImm);
5123 Op.getOperand(0), IntrinID, TrapHwRegImm);
5137 if (
Op.getOperand(1).getValueType() != MVT::i64)
5149 ReadFirstLaneID, NewModeReg);
5151 ReadFirstLaneID, NewTrapReg);
5153 unsigned ModeHwReg =
5156 unsigned TrapHwReg =
5164 IntrinID, ModeHwRegImm, NewModeReg);
5167 IntrinID, TrapHwRegImm, NewTrapReg);
5175 .
Case(
"m0", AMDGPU::M0)
5176 .
Case(
"exec", AMDGPU::EXEC)
5177 .
Case(
"exec_lo", AMDGPU::EXEC_LO)
5178 .
Case(
"exec_hi", AMDGPU::EXEC_HI)
5179 .
Case(
"flat_scratch", AMDGPU::FLAT_SCR)
5180 .
Case(
"flat_scratch_lo", AMDGPU::FLAT_SCR_LO)
5181 .
Case(
"flat_scratch_hi", AMDGPU::FLAT_SCR_HI)
5182 .
Case(
"src_flat_scratch_base", AMDGPU::SRC_FLAT_SCRATCH_BASE)
5183 .
Case(
"src_flat_scratch_base_lo", AMDGPU::SRC_FLAT_SCRATCH_BASE_LO)
5184 .
Case(
"src_flat_scratch_base_hi", AMDGPU::SRC_FLAT_SCRATCH_BASE_HI)
5190 if (!Subtarget->hasFlatScrRegister() &&
5191 TRI->regsOverlap(Reg, AMDGPU::FLAT_SCR))
5194 if (!Subtarget->hasGloballyAddressableScratch() &&
5195 TRI->regsOverlap(Reg, AMDGPU::SRC_FLAT_SCRATCH_BASE))
5200 case AMDGPU::EXEC_LO:
5201 case AMDGPU::EXEC_HI:
5202 case AMDGPU::FLAT_SCR_LO:
5203 case AMDGPU::FLAT_SCR_HI:
5204 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
5205 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
5210 case AMDGPU::FLAT_SCR:
5211 case AMDGPU::SRC_FLAT_SCRATCH_BASE:
5230 MI.setDesc(
TII->getKillTerminatorFromPseudo(
MI.getOpcode()));
5239static std::pair<MachineBasicBlock *, MachineBasicBlock *>
5261 auto Next = std::next(
I);
5272 MBB.addSuccessor(LoopBB);
5274 return std::pair(LoopBB, RemainderBB);
5281 auto I =
MI.getIterator();
5282 auto E = std::next(
I);
5304 Src->setIsKill(
false);
5314 BuildMI(*LoopBB, LoopBB->begin(),
DL,
TII->get(AMDGPU::S_SETREG_IMM32_B32))
5320 Register Reg =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5323 BuildMI(*LoopBB,
I,
DL,
TII->get(AMDGPU::S_GETREG_B32), Reg)
5347 unsigned InitReg,
unsigned ResultReg,
unsigned PhiReg,
5348 unsigned InitSaveExecReg,
int Offset,
bool UseGPRIdxMode,
5358 Register PhiExec =
MRI.createVirtualRegister(BoolRC);
5359 Register NewExec =
MRI.createVirtualRegister(BoolRC);
5361 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5362 Register CondReg =
MRI.createVirtualRegister(BoolRC);
5370 BuildMI(LoopBB,
I,
DL,
TII->get(TargetOpcode::PHI), PhiExec)
5377 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), CurrentIdxReg)
5381 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::V_CMP_EQ_U32_e64), CondReg)
5383 .
addReg(Idx.getReg(), {}, Idx.getSubReg());
5390 MRI.setSimpleHint(NewExec, CondReg);
5392 if (UseGPRIdxMode) {
5394 SGPRIdxReg = CurrentIdxReg;
5396 SGPRIdxReg =
MRI.createVirtualRegister(&AMDGPU::SGPR_32RegClass);
5397 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::S_ADD_I32), SGPRIdxReg)
5408 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::S_ADD_I32), AMDGPU::M0)
5441 unsigned InitResultReg,
unsigned PhiReg,
int Offset,
5442 bool UseGPRIdxMode,
Register &SGPRIdxReg) {
5450 const auto *BoolXExecRC =
TRI->getWaveMaskRegClass();
5452 Register SaveExec =
MRI.createVirtualRegister(BoolXExecRC);
5453 Register TmpExec =
MRI.createVirtualRegister(BoolXExecRC);
5469 InitResultReg, DstReg, PhiReg, TmpExec,
5470 Offset, UseGPRIdxMode, SGPRIdxReg);
5476 LoopBB->removeSuccessor(RemainderBB);
5478 LoopBB->addSuccessor(LandingPad);
5489static std::pair<unsigned, int>
5493 int NumElts =
TRI.getRegSizeInBits(*SuperRC) / 32;
5498 return std::pair(AMDGPU::sub0,
Offset);
5512 assert(Idx->getReg() != AMDGPU::NoRegister);
5537 return Idx->getReg();
5539 Register Tmp =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5557 Register SrcReg =
TII->getNamedOperand(
MI, AMDGPU::OpName::src)->getReg();
5558 int Offset =
TII->getNamedOperand(
MI, AMDGPU::OpName::offset)->getImm();
5564 std::tie(SubReg,
Offset) =
5567 const bool UseGPRIdxMode = ST.useVGPRIndexMode();
5570 if (
TII->getRegisterInfo().isSGPRClass(IdxRC)) {
5574 if (UseGPRIdxMode) {
5581 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
true);
5590 .
addReg(SrcReg, {}, SubReg)
5594 MI.eraseFromParent();
5603 Register PhiReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5604 Register InitReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5610 UseGPRIdxMode, SGPRIdxReg);
5614 if (UseGPRIdxMode) {
5616 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
true);
5618 BuildMI(*LoopBB, InsPt,
DL, GPRIDXDesc, Dst)
5623 BuildMI(*LoopBB, InsPt,
DL,
TII->get(AMDGPU::V_MOVRELS_B32_e32), Dst)
5624 .
addReg(SrcReg, {}, SubReg)
5628 MI.eraseFromParent();
5645 int Offset =
TII->getNamedOperand(
MI, AMDGPU::OpName::offset)->getImm();
5653 std::tie(SubReg,
Offset) =
5655 const bool UseGPRIdxMode = ST.useVGPRIndexMode();
5657 if (Idx->getReg() == AMDGPU::NoRegister) {
5668 MI.eraseFromParent();
5673 if (
TII->getRegisterInfo().isSGPRClass(IdxRC)) {
5677 if (UseGPRIdxMode) {
5681 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
false);
5690 const MCInstrDesc &MovRelDesc =
TII->getIndirectRegWriteMovRelPseudo(
5691 TRI.getRegSizeInBits(*VecRC), 32,
false);
5697 MI.eraseFromParent();
5704 Register PhiReg =
MRI.createVirtualRegister(VecRC);
5708 UseGPRIdxMode, SGPRIdxReg);
5711 if (UseGPRIdxMode) {
5713 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
false);
5715 BuildMI(*LoopBB, InsPt,
DL, GPRIDXDesc, Dst)
5721 const MCInstrDesc &MovRelDesc =
TII->getIndirectRegWriteMovRelPseudo(
5722 TRI.getRegSizeInBits(*VecRC), 32,
false);
5723 BuildMI(*LoopBB, InsPt,
DL, MovRelDesc, Dst)
5729 MI.eraseFromParent();
5745 bool IsAdd = (
MI.getOpcode() == AMDGPU::S_ADD_U64_PSEUDO);
5746 if (ST.hasScalarAddSub64()) {
5748 unsigned Opc = IsAdd ? AMDGPU::S_ADD_U64 : AMDGPU::S_SUB_U64;
5758 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5759 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5762 MI,
MRI, Src0, BoolRC, AMDGPU::sub0, &AMDGPU::SReg_32RegClass);
5764 MI,
MRI, Src0, BoolRC, AMDGPU::sub1, &AMDGPU::SReg_32RegClass);
5767 MI,
MRI, Src1, BoolRC, AMDGPU::sub0, &AMDGPU::SReg_32RegClass);
5769 MI,
MRI, Src1, BoolRC, AMDGPU::sub1, &AMDGPU::SReg_32RegClass);
5774 unsigned LoOpc = IsAdd ? AMDGPU::S_ADD_U32 : AMDGPU::S_SUB_U32;
5775 unsigned HiOpc = IsAdd ? AMDGPU::S_ADDC_U32 : AMDGPU::S_SUBB_U32;
5781 Hi.setOperandDead(3);
5788 MI.eraseFromParent();
5802 Register SrcCond =
MI.getOperand(3).getReg();
5804 Register DstLo =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5805 Register DstHi =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5807 Register SrcCondCopy =
MRI.createVirtualRegister(CondRC);
5810 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src0);
5812 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src1);
5814 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), Src0Idx));
5816 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), Src1Idx));
5819 TRI->getSubRegisterClass(Src0RC, AMDGPU::sub0);
5821 TRI->getSubRegisterClass(Src1RC, AMDGPU::sub1);
5824 MI,
MRI, Src0, Src0RC, AMDGPU::sub0, Src0SubRC);
5826 MI,
MRI, Src1, Src1RC, AMDGPU::sub0, Src1SubRC);
5829 MI,
MRI, Src0, Src0RC, AMDGPU::sub1, Src0SubRC);
5831 MI,
MRI, Src1, Src1RC, AMDGPU::sub1, Src1SubRC);
5853 MI.eraseFromParent();
5858 case AMDGPU::S_MIN_U32:
5859 return std::numeric_limits<uint32_t>::max();
5860 case AMDGPU::S_MIN_I32:
5861 return std::numeric_limits<int32_t>::max();
5862 case AMDGPU::S_MAX_U32:
5863 return std::numeric_limits<uint32_t>::min();
5864 case AMDGPU::S_MAX_I32:
5865 return std::numeric_limits<int32_t>::min();
5866 case AMDGPU::V_ADD_F32_e64:
5868 case AMDGPU::V_SUB_F32_e64:
5870 case AMDGPU::S_ADD_I32:
5871 case AMDGPU::S_SUB_I32:
5872 case AMDGPU::S_OR_B32:
5873 case AMDGPU::S_XOR_B32:
5874 return std::numeric_limits<uint32_t>::min();
5875 case AMDGPU::S_AND_B32:
5876 return std::numeric_limits<uint32_t>::max();
5877 case AMDGPU::V_MIN_F32_e64:
5878 case AMDGPU::V_MAX_F32_e64:
5880 case AMDGPU::V_CMP_LT_U64_e64:
5881 return std::numeric_limits<uint64_t>::max();
5882 case AMDGPU::V_CMP_LT_I64_e64:
5883 return std::numeric_limits<int64_t>::max();
5884 case AMDGPU::V_CMP_GT_U64_e64:
5885 return std::numeric_limits<uint64_t>::min();
5886 case AMDGPU::V_CMP_GT_I64_e64:
5887 return std::numeric_limits<int64_t>::min();
5888 case AMDGPU::V_MIN_F64_e64:
5889 case AMDGPU::V_MAX_F64_e64:
5890 case AMDGPU::V_MIN_NUM_F64_e64:
5891 case AMDGPU::V_MAX_NUM_F64_e64:
5892 return 0x7FF8000000000000;
5893 case AMDGPU::S_ADD_U64_PSEUDO:
5894 case AMDGPU::S_SUB_U64_PSEUDO:
5895 case AMDGPU::S_OR_B64:
5896 case AMDGPU::S_XOR_B64:
5897 return std::numeric_limits<uint64_t>::min();
5898 case AMDGPU::S_AND_B64:
5899 return std::numeric_limits<uint64_t>::max();
5900 case AMDGPU::V_ADD_F64_e64:
5901 case AMDGPU::V_ADD_F64_pseudo_e64:
5902 return 0x8000000000000000;
5909 return Opc == AMDGPU::S_MIN_U32 ||
Opc == AMDGPU::S_MIN_I32 ||
5910 Opc == AMDGPU::S_MAX_U32 ||
Opc == AMDGPU::S_MAX_I32 ||
5911 Opc == AMDGPU::S_ADD_I32 ||
Opc == AMDGPU::S_SUB_I32 ||
5912 Opc == AMDGPU::S_AND_B32 ||
Opc == AMDGPU::S_OR_B32 ||
5913 Opc == AMDGPU::S_XOR_B32 ||
Opc == AMDGPU::V_MIN_F32_e64 ||
5914 Opc == AMDGPU::V_MAX_F32_e64 ||
Opc == AMDGPU::V_ADD_F32_e64 ||
5915 Opc == AMDGPU::V_SUB_F32_e64;
5919 return Opc == AMDGPU::V_MIN_F32_e64 ||
Opc == AMDGPU::V_MAX_F32_e64 ||
5920 Opc == AMDGPU::V_ADD_F32_e64 ||
Opc == AMDGPU::V_SUB_F32_e64 ||
5921 Opc == AMDGPU::V_MIN_F64_e64 ||
Opc == AMDGPU::V_MAX_F64_e64 ||
5922 Opc == AMDGPU::V_MIN_NUM_F64_e64 ||
Opc == AMDGPU::V_MAX_NUM_F64_e64 ||
5923 Opc == AMDGPU::V_ADD_F64_e64 ||
Opc == AMDGPU::V_ADD_F64_pseudo_e64;
5926static std::tuple<unsigned, unsigned>
5930 case AMDGPU::S_MIN_U32:
5931 DPPOpc = AMDGPU::V_MIN_U32_dpp;
5933 case AMDGPU::S_MIN_I32:
5934 DPPOpc = AMDGPU::V_MIN_I32_dpp;
5936 case AMDGPU::S_MAX_U32:
5937 DPPOpc = AMDGPU::V_MAX_U32_dpp;
5939 case AMDGPU::S_MAX_I32:
5940 DPPOpc = AMDGPU::V_MAX_I32_dpp;
5942 case AMDGPU::S_ADD_I32:
5943 case AMDGPU::S_SUB_I32:
5944 DPPOpc = ST.hasAddNoCarryInsts() ? AMDGPU::V_ADD_U32_dpp
5945 : AMDGPU::V_ADD_CO_U32_dpp;
5947 case AMDGPU::S_AND_B32:
5948 DPPOpc = AMDGPU::V_AND_B32_dpp;
5950 case AMDGPU::S_OR_B32:
5951 DPPOpc = AMDGPU::V_OR_B32_dpp;
5953 case AMDGPU::S_XOR_B32:
5954 DPPOpc = AMDGPU::V_XOR_B32_dpp;
5956 case AMDGPU::V_ADD_F32_e64:
5957 case AMDGPU::V_SUB_F32_e64:
5958 DPPOpc = AMDGPU::V_ADD_F32_dpp;
5960 case AMDGPU::V_MIN_F32_e64:
5961 DPPOpc = AMDGPU::V_MIN_F32_dpp;
5963 case AMDGPU::V_MAX_F32_e64:
5964 DPPOpc = AMDGPU::V_MAX_F32_dpp;
5966 case AMDGPU::V_CMP_LT_U64_e64:
5967 case AMDGPU::V_CMP_LT_I64_e64:
5968 case AMDGPU::V_CMP_GT_U64_e64:
5969 case AMDGPU::V_CMP_GT_I64_e64:
5970 case AMDGPU::S_ADD_U64_PSEUDO:
5971 case AMDGPU::S_SUB_U64_PSEUDO:
5972 case AMDGPU::S_AND_B64:
5973 case AMDGPU::S_OR_B64:
5974 case AMDGPU::S_XOR_B64:
5975 case AMDGPU::V_MIN_NUM_F64_e64:
5976 case AMDGPU::V_MIN_F64_e64:
5977 case AMDGPU::V_MAX_NUM_F64_e64:
5978 case AMDGPU::V_MAX_F64_e64:
5979 case AMDGPU::V_ADD_F64_pseudo_e64:
5980 case AMDGPU::V_ADD_F64_e64:
5981 DPPOpc = AMDGPU::V_MOV_B64_DPP_PSEUDO;
5986 unsigned ClampOpc =
Opc;
5987 if (
Opc == AMDGPU::V_SUB_F32_e64)
5988 ClampOpc = AMDGPU::V_ADD_F32_e64;
5989 if (!ST.getInstrInfo()->isVALU(
Opc,
false)) {
5990 if (
Opc == AMDGPU::S_SUB_I32)
5991 ClampOpc = AMDGPU::S_ADD_I32;
5992 if (
Opc == AMDGPU::S_ADD_U64_PSEUDO ||
Opc == AMDGPU::S_SUB_U64_PSEUDO)
5993 ClampOpc = AMDGPU::V_ADD_CO_U32_e64;
5994 else if (
Opc == AMDGPU::S_AND_B64)
5995 ClampOpc = AMDGPU::V_AND_B32_e64;
5996 else if (
Opc == AMDGPU::S_OR_B64)
5997 ClampOpc = AMDGPU::V_OR_B32_e64;
5998 else if (
Opc == AMDGPU::S_XOR_B64)
5999 ClampOpc = AMDGPU::V_XOR_B32_e64;
6001 ClampOpc = ST.getInstrInfo()->getVALUOp(ClampOpc);
6003 return {DPPOpc, ClampOpc};
6006static std::pair<Register, Register>
6013 TRI->getSubRegisterClass(SrcRC, AMDGPU::sub0);
6015 TII->buildExtractSubReg(
MI,
MRI,
Op, SrcRC, AMDGPU::sub0, SrcSubRC);
6017 TII->buildExtractSubReg(
MI,
MRI,
Op, SrcRC, AMDGPU::sub1, SrcSubRC);
6018 return {Op1L, Op1H};
6032 bool isSGPR =
TRI->isSGPRClass(
MRI.getRegClass(SrcReg));
6034 unsigned Stratergy =
static_cast<unsigned>(
MI.getOperand(2).
getImm());
6035 enum WAVE_REDUCE_STRATEGY :
unsigned {
DEFAULT = 0, ITERATIVE = 1, DPP = 2 };
6037 unsigned MIOpc =
MI.getOpcode();
6051 case AMDGPU::S_MIN_U32:
6052 case AMDGPU::S_MIN_I32:
6053 case AMDGPU::V_MIN_F32_e64:
6054 case AMDGPU::S_MAX_U32:
6055 case AMDGPU::S_MAX_I32:
6056 case AMDGPU::V_MAX_F32_e64:
6057 case AMDGPU::S_AND_B32:
6058 case AMDGPU::S_OR_B32: {
6064 case AMDGPU::V_CMP_LT_U64_e64:
6065 case AMDGPU::V_CMP_LT_I64_e64:
6066 case AMDGPU::V_CMP_GT_U64_e64:
6067 case AMDGPU::V_CMP_GT_I64_e64:
6068 case AMDGPU::V_MIN_F64_e64:
6069 case AMDGPU::V_MIN_NUM_F64_e64:
6070 case AMDGPU::V_MAX_F64_e64:
6071 case AMDGPU::V_MAX_NUM_F64_e64:
6072 case AMDGPU::S_AND_B64:
6073 case AMDGPU::S_OR_B64: {
6079 case AMDGPU::S_XOR_B32:
6080 case AMDGPU::S_XOR_B64:
6081 case AMDGPU::S_ADD_I32:
6082 case AMDGPU::S_ADD_U64_PSEUDO:
6083 case AMDGPU::V_ADD_F32_e64:
6084 case AMDGPU::V_ADD_F64_e64:
6085 case AMDGPU::V_ADD_F64_pseudo_e64:
6086 case AMDGPU::S_SUB_I32:
6087 case AMDGPU::S_SUB_U64_PSEUDO:
6088 case AMDGPU::V_SUB_F32_e64: {
6091 Register ExecMask =
MRI.createVirtualRegister(WaveMaskRegClass);
6093 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6095 bool IsWave32 = ST.isWave32();
6096 unsigned MovOpc = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
6097 MCRegister ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
6098 unsigned BitCountOpc =
6099 IsWave32 ? AMDGPU::S_BCNT1_I32_B32 : AMDGPU::S_BCNT1_I32_B64;
6103 auto NewAccumulator =
6109 case AMDGPU::S_XOR_B32:
6110 case AMDGPU::S_XOR_B64: {
6116 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6118 .
addReg(NewAccumulator->getOperand(0).getReg())
6122 if (
TII->getImmOrMaterializedImm(
MRI, SrcReg) == 1) {
6124 if (
Opc == AMDGPU::S_XOR_B32) {
6129 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6131 BuildRegSequence(BB,
MI, DstReg, ParityRegister, DstHi);
6135 if (
Opc == AMDGPU::S_XOR_B32) {
6141 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6143 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6145 MRI.getRegClass(SrcReg), ST,
MRI);
6152 BuildRegSequence(BB,
MI, DstReg, DestSub0, DestSub1);
6156 case AMDGPU::S_SUB_I32: {
6157 Register NegatedVal =
MRI.createVirtualRegister(DstRegClass);
6165 .
addReg(NewAccumulator->getOperand(0).getReg());
6168 case AMDGPU::S_ADD_I32: {
6170 if (
TII->getImmOrMaterializedImm(
MRI, SrcReg) == 1) {
6173 .
addReg(NewAccumulator->getOperand(0).getReg());
6178 .
addReg(NewAccumulator->getOperand(0).getReg());
6181 case AMDGPU::S_ADD_U64_PSEUDO:
6182 case AMDGPU::S_SUB_U64_PSEUDO: {
6183 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6184 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6186 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6188 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6190 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6191 Register AddReg =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6193 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6195 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6197 MRI.getRegClass(SrcReg), ST,
MRI);
6199 if (
Opc == AMDGPU::S_ADD_U64_PSEUDO &&
6200 TII->getImmOrMaterializedImm(
MRI, SrcReg) == 1) {
6202 Register DstHi =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6204 BuildRegSequence(BB,
MI, DstReg,
6205 NewAccumulator->getOperand(0).getReg(), DstHi);
6208 if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
6211 .
addReg(NewAccumulator->getOperand(0).getReg())
6221 Register LowOpcode =
Opc == AMDGPU::S_SUB_U64_PSEUDO
6223 : NewAccumulator->getOperand(0).getReg();
6227 if (ST.hasScalarMulHiInsts()) {
6233 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6235 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6238 BuildMI(BB,
MI,
DL,
TII->get(AMDGPU::V_MUL_HI_U32_e64), VCarryReg)
6241 BuildMI(BB,
MI,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), CarryReg)
6248 Register HiVal =
Opc == AMDGPU::S_SUB_U64_PSEUDO ? AddReg : DestSub1;
6254 if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
6260 BuildRegSequence(BB,
MI, DstReg, DestSub0, DestSub1);
6263 case AMDGPU::V_ADD_F32_e64:
6264 case AMDGPU::V_ADD_F64_e64:
6265 case AMDGPU::V_ADD_F64_pseudo_e64:
6266 case AMDGPU::V_SUB_F32_e64: {
6269 Register ActiveLanesVreg =
MRI.createVirtualRegister(VregRC);
6270 Register DstVreg =
MRI.createVirtualRegister(VregRC);
6273 TII->get(is32BitOpc ? AMDGPU::V_CVT_F32_I32_e64
6274 : AMDGPU::V_CVT_F64_I32_e64),
6276 .
addReg(NewAccumulator->getOperand(0).getReg())
6281 unsigned srcMod = (MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F32 ||
6282 MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64)
6285 unsigned MulOpc = is32BitOpc ? AMDGPU::V_MUL_F32_e64
6287 ? AMDGPU::V_MUL_F64_pseudo_e64
6288 : AMDGPU::V_MUL_F64_e64;
6298 BuildMI(BB,
MI,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), DstReg)
6302 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6304 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6315 BuildRegSequence(BB,
MI, DstReg, LaneValueLoReg, LaneValueHiReg);
6327 bool NeedsMovDPP = !is32BitOpc;
6332 bool IsWave32 = ST.isWave32();
6333 unsigned MovOpcForExec = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
6334 unsigned ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
6335 if (Stratergy == WAVE_REDUCE_STRATEGY::ITERATIVE ||
6349 Register LoopIterator =
MRI.createVirtualRegister(WaveMaskRegClass);
6350 Register IdentityValReg =
MRI.createVirtualRegister(DstRegClass);
6351 Register AccumulatorReg =
MRI.createVirtualRegister(DstRegClass);
6352 Register ActiveBitsReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6353 Register NewActiveBitsReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6354 Register FF1Reg =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6355 Register LaneValueReg =
MRI.createVirtualRegister(DstRegClass);
6361 MI.getOpcode() == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64
6365 TII->get(is32BitOpc ? AMDGPU::S_MOV_B32
6366 : AMDGPU::S_MOV_B64_IMM_PSEUDO),
6375 I = ComputeLoop->begin();
6377 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::PHI), AccumulatorReg)
6381 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::PHI), ActiveBitsReg)
6385 I = ComputeLoop->end();
6389 IsWave32 ? AMDGPU::S_FF1_I32_B32 : AMDGPU::S_FF1_I32_B64;
6394 bool hasSrc0Modifier = AMDGPU::getNamedOperandIdx(
6395 Opc, AMDGPU::OpName::src0_modifiers) != -1;
6396 bool hasSrc1Modifier = AMDGPU::getNamedOperandIdx(
6397 Opc, AMDGPU::OpName::src1_modifiers) != -1;
6399 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::clamp) != -1;
6401 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel) != -1;
6403 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::omod) != -1;
6404 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
6408 if (ST.getInstrInfo()->isVALU(
Opc,
false)) {
6410 Register LaneValVgpr =
MRI.createVirtualRegister(SrcRegClass);
6411 Register VgprResultReg =
MRI.createVirtualRegister(SrcRegClass);
6412 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::COPY), LaneValVgpr)
6414 OpDstReg = VgprResultReg;
6415 LaneValueReg = LaneValVgpr;
6418 if (hasSrc0Modifier)
6420 OpInstr.addReg(AccumulatorReg);
6421 if (hasSrc1Modifier)
6423 OpInstr.addReg(LaneValueReg);
6431 OpInstr.setOperandDead(3);
6432 if (ST.getInstrInfo()->isVALU(
Opc,
false)) {
6433 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32),
6439 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6441 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6443 MRI.createVirtualRegister(&AMDGPU::SReg_64RegClass);
6445 MRI.getRegClass(SrcReg), ST,
MRI);
6447 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
6451 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
6455 auto LaneValue = BuildRegSequence(*ComputeLoop,
I, LaneValReg,
6456 LaneValueLoReg, LaneValueHiReg);
6458 case AMDGPU::S_OR_B64:
6459 case AMDGPU::S_AND_B64:
6460 case AMDGPU::S_XOR_B64: {
6463 .
addReg(LaneValue->getOperand(0).getReg())
6467 case AMDGPU::V_CMP_GT_I64_e64:
6468 case AMDGPU::V_CMP_GT_U64_e64:
6469 case AMDGPU::V_CMP_LT_I64_e64:
6470 case AMDGPU::V_CMP_LT_U64_e64: {
6471 Register LaneMaskReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6473 MRI.createVirtualRegister(WaveMaskRegClass);
6475 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src);
6477 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), SrcIdx));
6478 Register AccumulatorVReg =
MRI.createVirtualRegister(VregClass);
6481 BuildRegSequence(*ComputeLoop,
I, AccumulatorVReg, SrcReg0Sub0,
6484 .
addReg(LaneValue->getOperand(0).getReg())
6485 .
addReg(AccumulatorVReg);
6487 unsigned AndOpc = IsWave32 ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64;
6488 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AndOpc), ComparisonResultReg)
6492 NewAccumulator =
BuildMI(*ComputeLoop,
I,
DL,
6493 TII->get(AMDGPU::S_CSELECT_B64), DstReg)
6494 .
addReg(LaneValue->getOperand(0).getReg())
6498 case AMDGPU::V_MIN_F64_e64:
6499 case AMDGPU::V_MIN_NUM_F64_e64:
6500 case AMDGPU::V_MAX_F64_e64:
6501 case AMDGPU::V_MAX_NUM_F64_e64:
6502 case AMDGPU::V_ADD_F64_e64:
6503 case AMDGPU::V_ADD_F64_pseudo_e64: {
6505 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src);
6507 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), SrcIdx));
6508 Register AccumulatorVReg =
MRI.createVirtualRegister(VregRC);
6509 Register DstVreg =
MRI.createVirtualRegister(VregRC);
6511 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6513 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6514 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::COPY), AccumulatorVReg)
6517 MI.getOpcode() == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64
6523 .
addReg(LaneValue->getOperand(0).getReg())
6530 TII->get(AMDGPU::V_READFIRSTLANE_B32), LaneValLo);
6533 TII->get(AMDGPU::V_READFIRSTLANE_B32), LaneValHi);
6535 auto [Op1L, Op1H] =
ExtractSubRegs(*Iters, DstVregInst->getOperand(0),
6537 ReadLaneLo.addReg(Op1L);
6538 ReadLaneHi.addReg(Op1H);
6540 BuildRegSequence(*ComputeLoop,
I, DstReg, LaneValLo, LaneValHi);
6543 case AMDGPU::S_ADD_U64_PSEUDO:
6544 case AMDGPU::S_SUB_U64_PSEUDO: {
6547 .
addReg(LaneValue->getOperand(0).getReg())
6556 unsigned BITSETOpc =
6557 IsWave32 ? AMDGPU::S_BITSET0_B32 : AMDGPU::S_BITSET0_B64;
6558 BuildMI(*ComputeLoop,
I,
DL,
TII->get(BITSETOpc), NewActiveBitsReg)
6564 ActiveBits.addReg(NewActiveBitsReg).addMBB(ComputeLoop);
6568 if (!ST.hasScalarCompareEq64()) {
6570 Register LaneMaskReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6571 unsigned CMPOpc = IsWave32 ? AMDGPU::S_OR_B32 : AMDGPU::S_OR_B64;
6573 BuildMI(*ComputeLoop,
I,
DL,
TII->get(CMPOpc), LaneMaskReg);
6576 IsWave32 ? AMDGPU::S_CMP_LG_U32 : AMDGPU::S_CMP_LG_U64;
6577 SetSCCInstr =
BuildMI(*ComputeLoop,
I,
DL,
TII->get(CMPOpc));
6579 SetSCCInstr.
addReg(NewActiveBitsReg);
6580 if (ST.hasScalarCompareEq64())
6583 SetSCCInstr.
addReg(NewActiveBitsReg);
6584 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::S_CBRANCH_SCC1))
6589 assert(ST.hasDPP() &&
"Sub Target does not support DPP Operations");
6591 Register SrcWithIdentity =
MRI.createVirtualRegister(SrcRegClass);
6592 Register IdentityVGPR =
MRI.createVirtualRegister(SrcRegClass);
6593 Register IdentitySGPR =
MRI.createVirtualRegister(DstRegClass);
6594 Register DPPRowShr1 =
MRI.createVirtualRegister(SrcRegClass);
6595 Register DPPRowShr2 =
MRI.createVirtualRegister(SrcRegClass);
6596 Register DPPRowShr4 =
MRI.createVirtualRegister(SrcRegClass);
6597 Register DPPRowShr8 =
MRI.createVirtualRegister(SrcRegClass);
6598 Register RowBcast15 =
MRI.createVirtualRegister(SrcRegClass);
6599 Register ReducedValSGPR =
MRI.createVirtualRegister(DstRegClass);
6600 Register NegatedReducedVal =
MRI.createVirtualRegister(DstRegClass);
6601 Register RowBcast31 =
MRI.createVirtualRegister(SrcRegClass);
6602 Register UndefExec =
MRI.createVirtualRegister(WaveMaskRegClass);
6606 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::IMPLICIT_DEF), UndefExec);
6610 TII->get(is32BitOpc ? AMDGPU::S_MOV_B32
6611 : AMDGPU::S_MOV_B64_IMM_PSEUDO),
6614 auto IdentityCopyInstr =
6617 unsigned DPPOpc, ClampOpc;
6633 if (isFPOp && !NeedsMovDPP)
6636 if (isFPOp && !NeedsMovDPP)
6640 if (AMDGPU::getNamedOperandIdx(DPPOpc, AMDGPU::OpName::clamp) >= 0)
6649 bool isAddSub =
false,
6650 bool needsCarryIn =
false,
6652 unsigned InstrOpc = ClampOpc;
6653 Register CarryOutReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6655 InstrOpc = AMDGPU::V_ADDC_U32_e64;
6656 auto ClampInstr =
BuildMI(*CurrBB,
MI,
DL,
TII->get(InstrOpc), Dst);
6661 ClampInstr.addReg(CarryOutReg,
6667 ClampInstr.addReg(Src0);
6670 ClampInstr.addReg(Src1);
6672 ClampInstr.addReg(CarryIn);
6673 if (AMDGPU::getNamedOperandIdx(InstrOpc, AMDGPU::OpName::clamp) >= 0)
6674 ClampInstr.addImm(0);
6676 ClampInstr.addImm(0);
6677 LastBcastInstr = ClampInstr;
6682 Opc == AMDGPU::S_ADD_U64_PSEUDO ||
Opc == AMDGPU::S_SUB_U64_PSEUDO;
6683 bool isBitWiseOpc =
Opc == AMDGPU::S_AND_B64 ||
6684 Opc == AMDGPU::S_OR_B64 ||
Opc == AMDGPU::S_XOR_B64;
6685 Register ReturnReg =
MRI.createVirtualRegister(SrcRegClass);
6686 if (isAddSubOpc || isBitWiseOpc) {
6687 Register ResLo =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6688 Register ResHi =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6693 auto [Src0Lo, Src0Hi] =
6695 auto [Src1Lo, Src1Hi] =
6697 Register CarryReg = BuildClampInstr(
6698 ResLo, Src0Lo, Src1Lo, isAddSubOpc,
false);
6699 BuildClampInstr(ResHi, Src0Hi, Src1Hi, isAddSubOpc,
6700 isAddSubOpc, CarryReg);
6701 BuildRegSequence(*CurrBB,
MI, ReturnReg, ResLo, ResHi);
6712 Register CmpMaskReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6730 SrcWithIdentityInstr =
6731 BuildSetInactiveInstr(SrcWithIdentity, SrcReg, IdentityVGPR);
6734 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6736 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6738 MI, IdentityCopyInstr->getOperand(0), SrcRegClass, ST,
MRI);
6739 auto [SrcReg0Sub0, SrcReg0Sub1] =
6742 BuildSetInactiveInstr(SrcWithIdentitylo, SrcReg0Sub0, Reg0Sub0);
6744 BuildSetInactiveInstr(SrcWithIdentityhi, SrcReg0Sub1, Reg0Sub1);
6745 SrcWithIdentityInstr =
6746 BuildRegSequence(*CurrBB,
MI, SrcWithIdentity,
6753 BuildDPPMachineInstr(DPPRowShr1, SrcWithIdentityReg,
6756 DPPRowShr1 = BuildPostDPPInstr(SrcWithIdentityReg, DPPRowShr1);
6758 BuildDPPMachineInstr(DPPRowShr2, DPPRowShr1,
6761 DPPRowShr2 = BuildPostDPPInstr(DPPRowShr1, DPPRowShr2);
6763 BuildDPPMachineInstr(DPPRowShr4, DPPRowShr2,
6766 DPPRowShr4 = BuildPostDPPInstr(DPPRowShr2, DPPRowShr4);
6768 BuildDPPMachineInstr(DPPRowShr8, DPPRowShr4,
6771 DPPRowShr8 = BuildPostDPPInstr(DPPRowShr4, DPPRowShr8);
6773 if (ST.hasDPPBroadcasts()) {
6776 RowBcast15 = BuildPostDPPInstr(DPPRowShr8, RowBcast15);
6785 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6791 BuildClampInstr(RowBcast15, DPPRowShr8, SwizzledValue);
6794 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6796 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6797 Register SwizzledValue64 =
MRI.createVirtualRegister(SrcRegClass);
6812 BuildRegSequence(*CurrBB,
MI, SwizzledValue64, SwizzledValuelo,
6815 RowBcast15 = BuildPostDPPInstr(DPPRowShr8, SwizzledValue64);
6817 BuildClampInstr(RowBcast15, DPPRowShr8, SwizzledValue64);
6820 FinalDPPResult = RowBcast15;
6822 if (ST.hasDPPBroadcasts()) {
6825 RowBcast31 = BuildPostDPPInstr(RowBcast15, RowBcast31);
6828 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6830 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6831 Register PermutedValue =
MRI.createVirtualRegister(SrcRegClass);
6833 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6835 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6837 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6839 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6841 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::V_MBCNT_LO_U32_B32_e64),
6845 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::V_MBCNT_HI_U32_B32_e64),
6851 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::S_MOV_B32), Lane32Offset)
6859 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::S_MOV_B32), WordSizeConst)
6864 .
addReg(ShiftedThreadID);
6869 .
addReg(PermuteByteOffset)
6874 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6876 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6879 auto [RowBcast15Lo, RowBcast15Hi] =
6883 .
addReg(PermuteByteOffset)
6888 .
addReg(PermuteByteOffset)
6891 BuildRegSequence(*CurrBB,
MI, PermutedValue, PermutedValuelo,
6895 RowBcast31 = BuildPostDPPInstr(RowBcast15, PermutedValue);
6897 BuildClampInstr(RowBcast31, RowBcast15, PermutedValue);
6899 FinalDPPResult = RowBcast31;
6901 if (MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F32 ||
6902 MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64) {
6903 Register NegatedValVGPR =
MRI.createVirtualRegister(SrcRegClass);
6912 .
addReg(IsWave32 ? RowBcast15 : RowBcast31)
6915 FinalDPPResult = NegatedValVGPR;
6922 .
addImm(ST.getWavefrontSize() - 1);
6925 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6927 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6937 .
addImm(ST.getWavefrontSize() - 1);
6941 .
addImm(ST.getWavefrontSize() - 1);
6942 BuildRegSequence(*CurrBB,
MI, ReducedValSGPR, LaneValueLoReg,
6945 if (
Opc == AMDGPU::S_SUB_I32) {
6946 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::S_SUB_I32), NegatedReducedVal)
6950 }
else if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
6951 auto NegatedValInstr =
6960 .
addReg(
Opc == AMDGPU::S_SUB_I32 ||
Opc == AMDGPU::S_SUB_U64_PSEUDO
6966 MI.eraseFromParent();
6981 switch (
MI.getOpcode()) {
6982 case AMDGPU::WAVE_REDUCE_UMIN_PSEUDO_U32:
6984 case AMDGPU::WAVE_REDUCE_UMIN_PSEUDO_U64:
6986 case AMDGPU::WAVE_REDUCE_MIN_PSEUDO_I32:
6988 case AMDGPU::WAVE_REDUCE_MIN_PSEUDO_I64:
6990 case AMDGPU::WAVE_REDUCE_FMIN_PSEUDO_F32:
6992 case AMDGPU::WAVE_REDUCE_FMIN_PSEUDO_F64:
6995 ? AMDGPU::V_MIN_NUM_F64_e64
6996 : AMDGPU::V_MIN_F64_e64);
6997 case AMDGPU::WAVE_REDUCE_UMAX_PSEUDO_U32:
6999 case AMDGPU::WAVE_REDUCE_UMAX_PSEUDO_U64:
7001 case AMDGPU::WAVE_REDUCE_MAX_PSEUDO_I32:
7003 case AMDGPU::WAVE_REDUCE_MAX_PSEUDO_I64:
7005 case AMDGPU::WAVE_REDUCE_FMAX_PSEUDO_F32:
7007 case AMDGPU::WAVE_REDUCE_FMAX_PSEUDO_F64:
7010 ? AMDGPU::V_MAX_NUM_F64_e64
7011 : AMDGPU::V_MAX_F64_e64);
7012 case AMDGPU::WAVE_REDUCE_ADD_PSEUDO_I32:
7014 case AMDGPU::WAVE_REDUCE_ADD_PSEUDO_U64:
7016 case AMDGPU::WAVE_REDUCE_FADD_PSEUDO_F32:
7018 case AMDGPU::WAVE_REDUCE_FADD_PSEUDO_F64:
7021 ? AMDGPU::V_ADD_F64_pseudo_e64
7022 : AMDGPU::V_ADD_F64_e64);
7023 case AMDGPU::WAVE_REDUCE_SUB_PSEUDO_I32:
7025 case AMDGPU::WAVE_REDUCE_SUB_PSEUDO_U64:
7027 case AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F32:
7029 case AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64:
7034 ? AMDGPU::V_ADD_F64_pseudo_e64
7035 : AMDGPU::V_ADD_F64_e64);
7036 case AMDGPU::WAVE_REDUCE_AND_PSEUDO_B32:
7038 case AMDGPU::WAVE_REDUCE_AND_PSEUDO_B64:
7040 case AMDGPU::WAVE_REDUCE_OR_PSEUDO_B32:
7042 case AMDGPU::WAVE_REDUCE_OR_PSEUDO_B64:
7044 case AMDGPU::WAVE_REDUCE_XOR_PSEUDO_B32:
7046 case AMDGPU::WAVE_REDUCE_XOR_PSEUDO_B64:
7048 case AMDGPU::S_UADDO_PSEUDO:
7049 case AMDGPU::S_USUBO_PSEUDO: {
7055 unsigned Opc = (
MI.getOpcode() == AMDGPU::S_UADDO_PSEUDO)
7057 : AMDGPU::S_SUB_U32;
7065 Subtarget->isWave64() ? AMDGPU::S_CSELECT_B64 : AMDGPU::S_CSELECT_B32;
7068 MI.eraseFromParent();
7071 case AMDGPU::S_ADD_U64_PSEUDO:
7072 case AMDGPU::S_SUB_U64_PSEUDO: {
7075 case AMDGPU::V_ADD_U64_PSEUDO:
7076 case AMDGPU::V_SUB_U64_PSEUDO: {
7077 bool IsAdd = (
MI.getOpcode() == AMDGPU::V_ADD_U64_PSEUDO);
7083 if (ST.hasAddSubU64Insts()) {
7085 TII->get(IsAdd ? AMDGPU::V_ADD_U64_e64
7086 : AMDGPU::V_SUB_U64_e64),
7091 TII->legalizeOperands(*
I);
7092 MI.eraseFromParent();
7096 if (IsAdd && ST.hasLshlAddU64Inst()) {
7102 TII->legalizeOperands(*
Add);
7103 MI.eraseFromParent();
7107 const auto *CarryRC =
TRI->getWaveMaskRegClass();
7109 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
7110 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
7112 Register CarryReg =
MRI.createVirtualRegister(CarryRC);
7113 Register DeadCarryReg =
MRI.createVirtualRegister(CarryRC);
7116 ?
MRI.getRegClass(Src0.getReg())
7117 : &AMDGPU::VReg_64RegClass;
7119 ?
MRI.getRegClass(Src1.getReg())
7120 : &AMDGPU::VReg_64RegClass;
7123 TRI->getSubRegisterClass(Src0RC, AMDGPU::sub0);
7125 TRI->getSubRegisterClass(Src1RC, AMDGPU::sub1);
7128 MI,
MRI, Src0, Src0RC, AMDGPU::sub0, Src0SubRC);
7130 MI,
MRI, Src1, Src1RC, AMDGPU::sub0, Src1SubRC);
7133 MI,
MRI, Src0, Src0RC, AMDGPU::sub1, Src0SubRC);
7135 MI,
MRI, Src1, Src1RC, AMDGPU::sub1, Src1SubRC);
7138 IsAdd ? AMDGPU::V_ADD_CO_U32_e64 : AMDGPU::V_SUB_CO_U32_e64;
7145 unsigned HiOpc = IsAdd ? AMDGPU::V_ADDC_U32_e64 : AMDGPU::V_SUBB_U32_e64;
7159 TII->legalizeOperands(*LoHalf);
7160 TII->legalizeOperands(*HiHalf);
7161 MI.eraseFromParent();
7164 case AMDGPU::S_ADD_CO_PSEUDO:
7165 case AMDGPU::S_SUB_CO_PSEUDO: {
7175 if (Src0.isReg() &&
TRI->isVectorRegister(
MRI, Src0.getReg())) {
7176 Register RegOp0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
7177 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp0)
7179 Src0.setReg(RegOp0);
7181 if (Src1.isReg() &&
TRI->isVectorRegister(
MRI, Src1.getReg())) {
7182 Register RegOp1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
7183 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp1)
7185 Src1.setReg(RegOp1);
7187 Register RegOp2 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
7188 if (
TRI->isVectorRegister(
MRI, Src2.getReg())) {
7189 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp2)
7191 Src2.setReg(RegOp2);
7194 if (ST.isWave64()) {
7195 if (ST.hasScalarCompareEq64()) {
7202 TRI->getSubRegisterClass(Src2RC, AMDGPU::sub0);
7204 MII,
MRI, Src2, Src2RC, AMDGPU::sub0, SubRC);
7206 MII,
MRI, Src2, Src2RC, AMDGPU::sub1, SubRC);
7207 Register Src2_32 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7209 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::S_OR_B32), Src2_32)
7223 unsigned Opc =
MI.getOpcode() == AMDGPU::S_ADD_CO_PSEUDO
7224 ? AMDGPU::S_ADDC_U32
7225 : AMDGPU::S_SUBB_U32;
7230 ST.isWave64() ? AMDGPU::S_CSELECT_B64 : AMDGPU::S_CSELECT_B32;
7236 MI.eraseFromParent();
7239 case AMDGPU::SI_INIT_M0: {
7242 TII->get(M0Init.
isReg() ? AMDGPU::COPY : AMDGPU::S_MOV_B32),
7245 MI.eraseFromParent();
7248 case AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM: {
7251 TII->get(AMDGPU::S_CMP_EQ_U32))
7256 case AMDGPU::GET_GROUPSTATICSIZE: {
7260 .
add(
MI.getOperand(0))
7262 MI.eraseFromParent();
7265 case AMDGPU::GET_SHADERCYCLESHILO: {
7278 Register RegHi1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7280 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES_HI, 0, 32));
7281 Register RegLo1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7283 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES, 0, 32));
7284 Register RegHi2 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7286 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES_HI, 0, 32));
7290 Register RegLo =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7295 .
add(
MI.getOperand(0))
7300 MI.eraseFromParent();
7303 case AMDGPU::SI_INDIRECT_SRC_V1:
7304 case AMDGPU::SI_INDIRECT_SRC_V2:
7305 case AMDGPU::SI_INDIRECT_SRC_V3:
7306 case AMDGPU::SI_INDIRECT_SRC_V4:
7307 case AMDGPU::SI_INDIRECT_SRC_V5:
7308 case AMDGPU::SI_INDIRECT_SRC_V6:
7309 case AMDGPU::SI_INDIRECT_SRC_V7:
7310 case AMDGPU::SI_INDIRECT_SRC_V8:
7311 case AMDGPU::SI_INDIRECT_SRC_V9:
7312 case AMDGPU::SI_INDIRECT_SRC_V10:
7313 case AMDGPU::SI_INDIRECT_SRC_V11:
7314 case AMDGPU::SI_INDIRECT_SRC_V12:
7315 case AMDGPU::SI_INDIRECT_SRC_V16:
7316 case AMDGPU::SI_INDIRECT_SRC_V32:
7318 case AMDGPU::SI_INDIRECT_DST_V1:
7319 case AMDGPU::SI_INDIRECT_DST_V2:
7320 case AMDGPU::SI_INDIRECT_DST_V3:
7321 case AMDGPU::SI_INDIRECT_DST_V4:
7322 case AMDGPU::SI_INDIRECT_DST_V5:
7323 case AMDGPU::SI_INDIRECT_DST_V6:
7324 case AMDGPU::SI_INDIRECT_DST_V7:
7325 case AMDGPU::SI_INDIRECT_DST_V8:
7326 case AMDGPU::SI_INDIRECT_DST_V9:
7327 case AMDGPU::SI_INDIRECT_DST_V10:
7328 case AMDGPU::SI_INDIRECT_DST_V11:
7329 case AMDGPU::SI_INDIRECT_DST_V12:
7330 case AMDGPU::SI_INDIRECT_DST_V16:
7331 case AMDGPU::SI_INDIRECT_DST_V32:
7333 case AMDGPU::SI_KILL_F32_COND_IMM_PSEUDO:
7334 case AMDGPU::SI_KILL_I1_PSEUDO:
7336 case AMDGPU::V_CNDMASK_B64_PSEUDO: {
7340 case AMDGPU::SI_BR_UNDEF: {
7342 .
add(
MI.getOperand(0));
7344 MI.eraseFromParent();
7347 case AMDGPU::ADJCALLSTACKUP:
7348 case AMDGPU::ADJCALLSTACKDOWN: {
7355 case AMDGPU::SI_CALL_ISEL: {
7356 unsigned ReturnAddrReg =
TII->getRegisterInfo().getReturnAddressReg(*MF);
7367 MI.eraseFromParent();
7370 case AMDGPU::V_ADDC_U32_e32:
7371 case AMDGPU::V_SUBB_U32_e32:
7372 case AMDGPU::V_SUBBREV_U32_e32:
7375 TII->legalizeOperands(
MI);
7377 case AMDGPU::DS_GWS_INIT:
7378 case AMDGPU::DS_GWS_SEMA_BR:
7379 case AMDGPU::DS_GWS_BARRIER:
7380 case AMDGPU::DS_GWS_SEMA_V:
7381 case AMDGPU::DS_GWS_SEMA_P:
7382 case AMDGPU::DS_GWS_SEMA_RELEASE_ALL:
7390 case AMDGPU::S_SETREG_B32: {
7400 auto [ID,
Offset, Width] =
7406 const unsigned SetMask = WidthMask <<
Offset;
7409 unsigned SetDenormOp = 0;
7410 unsigned SetRoundOp = 0;
7418 SetRoundOp = AMDGPU::S_ROUND_MODE;
7419 SetDenormOp = AMDGPU::S_DENORM_MODE;
7421 SetRoundOp = AMDGPU::S_ROUND_MODE;
7423 SetDenormOp = AMDGPU::S_DENORM_MODE;
7426 if (SetRoundOp || SetDenormOp) {
7428 if (Def && Def->isMoveImmediate() && Def->getOperand(1).isImm()) {
7429 unsigned ImmVal = Def->getOperand(1).getImm();
7443 MI.eraseFromParent();
7452 MI.setDesc(
TII->get(AMDGPU::S_SETREG_B32_mode));
7456 case AMDGPU::S_INVERSE_BALLOT_U32:
7457 case AMDGPU::S_INVERSE_BALLOT_U64:
7460 MI.setDesc(
TII->get(AMDGPU::COPY));
7462 case AMDGPU::ENDPGM_TRAP: {
7464 MI.setDesc(
TII->get(AMDGPU::S_ENDPGM));
7484 MI.eraseFromParent();
7487 case AMDGPU::SIMULATED_TRAP: {
7488 assert(Subtarget->hasPrivEnabledTrap2NopBug());
7490 TII->insertSimulatedTrap(
MRI, *BB,
MI,
MI.getDebugLoc());
7491 MI.eraseFromParent();
7494 case AMDGPU::SI_TCRETURN_GFX_WholeWave:
7495 case AMDGPU::SI_WHOLE_WAVE_FUNC_RETURN: {
7501 assert(Setup &&
"Couldn't find SI_SETUP_WHOLE_WAVE_FUNC");
7502 Register OriginalExec = Setup->getOperand(0).getReg();
7503 MI.getOperand(0).setReg(OriginalExec);
7506 case AMDGPU::V_DOT2_F32_F16:
7507 case AMDGPU::V_DOT2_F32_BF16: {
7511 MRI.setSimpleHint(
MI.getOperand(0).getReg(),
MI.getOperand(6).getReg());
7514 case AMDGPU::SCHED_BARRIER:
7515 case AMDGPU::SCHED_GROUP_BARRIER:
7516 MI.getOperand(0).setImm(
MI.getOperand(0).getImm() &
7553 return (VT == MVT::i16) ? MVT::i16 : MVT::i32;
7557 return (Ty.getScalarSizeInBits() <= 16 && Subtarget->has16BitInsts())
7586 if (!Subtarget->hasMadMacF32Insts())
7587 return Subtarget->hasFastFMAF32();
7593 return Subtarget->hasFastFMAF32() || Subtarget->hasDLInsts();
7596 return Subtarget->hasFastFMAF32() && Subtarget->hasDLInsts();
7602 return Subtarget->has16BitInsts() &&
7620 F.getDenormalFPEnv());
7625 switch (Ty.getScalarSizeInBits()) {
7643 return Subtarget->hasMadMacF32Insts() &&
7646 return Subtarget->hasMadF16() &&
7657 if (Ty.getScalarSizeInBits() == 16)
7659 if (Ty.getScalarSizeInBits() == 32)
7674 F.getDenormalFPEnv());
7685 unsigned Opc =
Op.getOpcode();
7686 EVT VT =
Op.getValueType();
7698 LoOps.
append(TrailingOps.begin(), TrailingOps.end());
7699 HiOps.
append(TrailingOps.begin(), TrailingOps.end());
7712 [[maybe_unused]]
EVT VT =
Op.getValueType();
7714 assert((VT == MVT::v2i32 || VT == MVT::v4i32 || VT == MVT::v8i32 ||
7715 VT == MVT::v16i32) &&
7716 "Unexpected ValueType.");
7725 unsigned Opc =
Op.getOpcode();
7726 EVT VT =
Op.getValueType();
7735 DAG.
getNode(
Opc, SL, Lo0.getValueType(), Lo0, Lo1,
Op->getFlags());
7737 DAG.
getNode(
Opc, SL, Hi0.getValueType(), Hi0, Hi1,
Op->getFlags());
7744 unsigned Opc =
Op.getOpcode();
7745 EVT VT =
Op.getValueType();
7762 DAG.
getNode(
Opc, SL, ResVT.first, Lo0, Lo1, Lo2,
Op->getFlags());
7764 DAG.
getNode(
Opc, SL, ResVT.second, Hi0, Hi1, Hi2,
Op->getFlags());
7770 switch (
Op.getOpcode()) {
7774 return LowerBRCOND(
Op, DAG);
7776 return LowerRETURNADDR(
Op, DAG);
7778 return lowerFrameIndex(
Op, DAG);
7780 return LowerSPONENTRY(
Op, DAG);
7783 assert((!Result.getNode() || Result.getNode()->getNumValues() == 2) &&
7784 "Load should return a value and a chain");
7788 EVT VT =
Op.getValueType();
7790 return lowerFSQRTF32(
Op, DAG);
7792 return lowerFSQRTF64(
Op, DAG);
7797 return LowerTrig(
Op, DAG);
7799 return LowerSELECT(
Op, DAG);
7801 return LowerFDIV(
Op, DAG);
7803 return LowerFFREXP(
Op, DAG);
7805 return LowerATOMIC_CMP_SWAP(
Op, DAG);
7807 return LowerSTORE(
Op, DAG);
7811 return LowerGlobalAddress(MFI,
Op, DAG);
7816 return LowerExternalSymbol(
Op, DAG);
7818 return LowerINTRINSIC_WO_CHAIN(
Op, DAG);
7820 return LowerCONVERT_FROM_ARBITRARY_FP(
Op, DAG);
7822 return LowerCONVERT_TO_ARBITRARY_FP(
Op, DAG);
7824 return LowerINTRINSIC_W_CHAIN(
Op, DAG);
7826 return LowerINTRINSIC_VOID(
Op, DAG);
7828 return lowerADDRSPACECAST(
Op, DAG);
7830 return lowerINSERT_SUBVECTOR(
Op, DAG);
7832 return lowerINSERT_VECTOR_ELT(
Op, DAG);
7834 return lowerEXTRACT_VECTOR_ELT(
Op, DAG);
7836 return lowerVECTOR_SHUFFLE(
Op, DAG);
7838 return lowerSCALAR_TO_VECTOR(
Op, DAG);
7840 return lowerBUILD_VECTOR(
Op, DAG);
7843 return lowerFP_ROUND(
Op, DAG);
7845 return lowerTRAP(
Op, DAG);
7847 return lowerDEBUGTRAP(
Op, DAG);
7856 if (
Op.getValueType().isVector() &&
Op.getValueType() != MVT::v2i16 &&
7857 Op.getOperand(0).getValueType().getScalarType() == MVT::f32)
7861 if (
Op.getValueType() == MVT::bf16) {
7891 return lowerFMINNUM_FMAXNUM(
Op, DAG);
7894 return lowerFMINIMUMNUM_FMAXIMUMNUM(
Op, DAG);
7897 return lowerFLDEXP(
Op, DAG);
7902 if (Subtarget->hasVCvtPkIU16F32() &&
Op.getValueType() == MVT::i16 &&
7903 Op.getOperand(0).getValueType() == MVT::f32) {
7929 return lowerFCOPYSIGN(
Op, DAG);
7931 return lowerMUL(
Op, DAG);
7934 return lowerXMULO(
Op, DAG);
7937 return lowerXMUL_LOHI(
Op, DAG);
7958 return LowerINLINEASM(
Op, DAG);
7964static std::pair<SDValue, SDValue>
7994 EVT FittingLoadVT = LoadVT;
8026SDValue SITargetLowering::adjustLoadValueType(
unsigned Opcode,
MemSDNode *M,
8029 bool IsIntrinsic)
const {
8032 bool IsTFE =
M->getNumValues() == 3;
8033 bool Unpacked = Subtarget->hasUnpackedD16VMem();
8034 EVT LoadVT =
M->getValueType(0);
8036 EVT EquivLoadVT = LoadVT;
8053 SDVTList VTList = DAG.
getVTList(LoadDWordsVT, MVT::Other);
8055 Opcode,
DL, VTList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
8063 SDVTList VTList = DAG.
getVTList(EquivLoadVT, MVT::Other);
8067 M->getMemoryVT(),
M->getMemOperand());
8078 EVT LoadVT =
M->getValueType(0);
8087 "unsupported sub-dword format buffer load",
DL.getDebugLoc()));
8091 assert(
M->getNumValues() == 2 ||
M->getNumValues() == 3);
8092 bool IsTFE =
M->getNumValues() == 3;
8094 if (IsD16 && IsTFE && !Subtarget->hasBufferTFEFormatD16()) {
8097 "TFE D16 format buffer load is not supported on this GPU",
8100 M->getOperand(0),
DL);
8103 unsigned Opc = IsD16 ? (IsTFE ? AMDGPUISD::BUFFER_LOAD_FORMAT_D16_TFE
8104 : AMDGPUISD::BUFFER_LOAD_FORMAT_D16)
8105 : IsFormat ? (IsTFE ? AMDGPUISD::BUFFER_LOAD_FORMAT_TFE
8106 : AMDGPUISD::BUFFER_LOAD_FORMAT)
8107 : IsTFE ? AMDGPUISD::BUFFER_LOAD_TFE
8108 : AMDGPUISD::BUFFER_LOAD;
8111 return adjustLoadValueType(
Opc, M, DAG,
Ops);
8115 return handleByteShortBufferLoads(DAG, LoadVT,
DL,
Ops,
M->getMemOperand(),
8119 return getMemIntrinsicNode(
Opc,
DL,
M->getVTList(),
Ops, IntVT,
8120 M->getMemOperand(), DAG);
8124 SDVTList VTList = IsTFE ? DAG.
getVTList(CastVT, MVT::i32, MVT::Other)
8127 M->getMemOperand(), DAG);
8137 EVT VT =
N->getValueType(0);
8161 Exec = AMDGPU::EXEC_LO;
8163 Exec = AMDGPU::EXEC;
8180 bool Signed = IntrinsicID == Intrinsic::amdgcn_sbfe;
8182 EVT VT =
Op.getValueType();
8187 if (VT != MVT::i32) {
8195 return DAG.
getNode(
Signed ? AMDGPUISD::BFE_I32 : AMDGPUISD::BFE_U32,
DL, VT,
8204 EVT VT =
N->getValueType(0);
8206 unsigned IID =
N->getConstantOperandVal(0);
8207 bool IsPermLane16 = IID == Intrinsic::amdgcn_permlane16 ||
8208 IID == Intrinsic::amdgcn_permlanex16;
8209 bool IsSetInactive = IID == Intrinsic::amdgcn_set_inactive ||
8210 IID == Intrinsic::amdgcn_set_inactive_chain_arg;
8211 bool IsPermlaneShuffle = IID == Intrinsic::amdgcn_permlane_bcast ||
8212 IID == Intrinsic::amdgcn_permlane_up ||
8213 IID == Intrinsic::amdgcn_permlane_down ||
8214 IID == Intrinsic::amdgcn_permlane_xor;
8219 unsigned SplitSize = 32;
8220 if (IID == Intrinsic::amdgcn_update_dpp && (ValSize % 64 == 0) &&
8221 ST->hasDPALU_DPP() &&
8229 case Intrinsic::amdgcn_permlane16:
8230 case Intrinsic::amdgcn_permlanex16:
8231 case Intrinsic::amdgcn_update_dpp:
8236 case Intrinsic::amdgcn_writelane:
8237 case Intrinsic::amdgcn_permlane_bcast:
8238 case Intrinsic::amdgcn_permlane_up:
8239 case Intrinsic::amdgcn_permlane_down:
8240 case Intrinsic::amdgcn_permlane_xor:
8243 case Intrinsic::amdgcn_readlane:
8244 case Intrinsic::amdgcn_set_inactive:
8245 case Intrinsic::amdgcn_set_inactive_chain_arg:
8246 case Intrinsic::amdgcn_mov_dpp8:
8249 case Intrinsic::amdgcn_readfirstlane:
8250 case Intrinsic::amdgcn_permlane64:
8260 if (
SDNode *GL =
N->getGluedNode()) {
8262 GL = GL->getOperand(0).getNode();
8272 if (IID == Intrinsic::amdgcn_readlane || IID == Intrinsic::amdgcn_writelane ||
8273 IID == Intrinsic::amdgcn_mov_dpp8 ||
8274 IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16 ||
8275 IsPermlaneShuffle) {
8276 Src1 =
N->getOperand(2);
8277 if (IID == Intrinsic::amdgcn_writelane ||
8278 IID == Intrinsic::amdgcn_update_dpp || IsPermLane16 ||
8280 Src2 =
N->getOperand(3);
8283 if (ValSize == SplitSize) {
8293 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16) {
8298 if (IID == Intrinsic::amdgcn_writelane) {
8303 SDValue LaneOp = createLaneOp(Src0, Src1, Src2, MVT::i32);
8308 if (ValSize % SplitSize != 0)
8312 EVT VT =
N->getValueType(0);
8316 unsigned NumOperands =
N->getNumOperands();
8318 SDNode *GL =
N->getGluedNode();
8323 for (
unsigned i = 0; i != NE; ++i) {
8324 for (
unsigned j = 0, e = GL ? NumOperands - 1 : NumOperands; j != e;
8326 SDValue Operand =
N->getOperand(j);
8356 if (SplitSize == 32) {
8358 return unrollLaneOp(LaneOp.
getNode());
8364 unsigned SubVecNumElt =
8368 SDValue Src0SubVec, Src1SubVec, Src2SubVec;
8369 for (
unsigned i = 0, EltIdx = 0; i < ValSize / SplitSize; i++) {
8373 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive ||
8379 createLaneOp(Src0SubVec, Src1SubVec, Src2, SubVecVT));
8380 }
else if (IID == Intrinsic::amdgcn_writelane) {
8384 createLaneOp(Src0SubVec, Src1, Src2SubVec, SubVecVT));
8386 Pieces.
push_back(createLaneOp(Src0SubVec, Src1, Src2, SubVecVT));
8389 EltIdx += SubVecNumElt;
8403 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16)
8406 if (IID == Intrinsic::amdgcn_writelane)
8409 SDValue LaneOp = createLaneOp(Src0, Src1, Src2, VecVT);
8416 EVT VT =
N->getValueType(0);
8434 auto MakeIntrinsic = [&DAG, &SL](
unsigned IID,
MVT RetVT,
8443 if (
TLI.getSubtarget()->supportsWaveWideBPermute()) {
8444 SDValue BPermute = MakeIntrinsic(Intrinsic::amdgcn_ds_bpermute, MVT::i32,
8445 {ShiftedIndex, ValueI32});
8455 SDValue WWMValue = MakeIntrinsic(Intrinsic::amdgcn_set_inactive, MVT::i32,
8456 {ValueI32, PoisonVal});
8457 SDValue WWMIndex = MakeIntrinsic(Intrinsic::amdgcn_set_inactive, MVT::i32,
8458 {ShiftedIndex, PoisonVal});
8461 MakeIntrinsic(Intrinsic::amdgcn_permlane64, MVT::i32, {WWMValue});
8464 SDValue BPermSameHalf = MakeIntrinsic(Intrinsic::amdgcn_ds_bpermute, MVT::i32,
8465 {WWMIndex, WWMValue});
8466 SDValue BPermOtherHalf = MakeIntrinsic(Intrinsic::amdgcn_ds_bpermute,
8467 MVT::i32, {WWMIndex, Swapped});
8469 MakeIntrinsic(Intrinsic::amdgcn_wwm, MVT::i32, {BPermOtherHalf});
8477 MakeIntrinsic(Intrinsic::amdgcn_mbcnt_lo, MVT::i32,
8485 DAG.
getSetCC(SL, MVT::i1, SameOrOtherHalf,
8495 switch (
N->getOpcode()) {
8512 unsigned IID =
N->getConstantOperandVal(0);
8514 case Intrinsic::amdgcn_wave_reduce_min:
8515 case Intrinsic::amdgcn_wave_reduce_umin:
8516 case Intrinsic::amdgcn_wave_reduce_max:
8517 case Intrinsic::amdgcn_wave_reduce_umax:
8518 case Intrinsic::amdgcn_wave_reduce_add:
8519 case Intrinsic::amdgcn_wave_reduce_sub:
8520 case Intrinsic::amdgcn_wave_reduce_and:
8521 case Intrinsic::amdgcn_wave_reduce_or:
8522 case Intrinsic::amdgcn_wave_reduce_xor: {
8523 EVT VT =
N->getValueType(0);
8527 bool NeedsSignExt = IID == Intrinsic::amdgcn_wave_reduce_min ||
8528 IID == Intrinsic::amdgcn_wave_reduce_max ||
8529 IID == Intrinsic::amdgcn_wave_reduce_add ||
8530 IID == Intrinsic::amdgcn_wave_reduce_sub;
8534 N->getOperand(0), ExtSrc,
N->getOperand(2));
8538 case Intrinsic::amdgcn_make_buffer_rsrc:
8539 Results.push_back(lowerPointerAsRsrcIntrin(
N, DAG));
8541 case Intrinsic::amdgcn_cvt_pkrtz: {
8546 DAG.
getNode(AMDGPUISD::CVT_PKRTZ_F16_F32, SL, MVT::i32, Src0, Src1);
8550 case Intrinsic::amdgcn_cvt_pknorm_i16:
8551 case Intrinsic::amdgcn_cvt_pknorm_u16:
8552 case Intrinsic::amdgcn_cvt_pk_i16:
8553 case Intrinsic::amdgcn_cvt_pk_u16: {
8559 if (IID == Intrinsic::amdgcn_cvt_pknorm_i16)
8560 Opcode = AMDGPUISD::CVT_PKNORM_I16_F32;
8561 else if (IID == Intrinsic::amdgcn_cvt_pknorm_u16)
8562 Opcode = AMDGPUISD::CVT_PKNORM_U16_F32;
8563 else if (IID == Intrinsic::amdgcn_cvt_pk_i16)
8564 Opcode = AMDGPUISD::CVT_PK_I16_I32;
8566 Opcode = AMDGPUISD::CVT_PK_U16_U32;
8568 EVT VT =
N->getValueType(0);
8577 case Intrinsic::amdgcn_s_buffer_load: {
8579 EVT VT =
Op.getValueType();
8581 Op.getOperand(1),
Op.getOperand(2),
8582 Op.getOperand(3), DAG));
8585 case Intrinsic::amdgcn_dead: {
8586 for (
unsigned I = 0, E =
N->getNumValues();
I < E; ++
I)
8594 if (
N->getConstantOperandVal(1) != Intrinsic::amdgcn_ptr_s_buffer_load &&
8595 N->getValueType(0).isSimple() &&
8596 SBufferLoadDiagnosticVTs[
N->getSimpleValueType(0).SimpleTy])
8601 for (
unsigned I = 0;
I < Res.getNumOperands();
I++) {
8602 Results.push_back(Res.getOperand(
I));
8605 for (
unsigned I = 0;
I <
N->getNumValues(); ++
I)
8606 Results.push_back(Res.getValue(
I));
8615 EVT VT =
N->getValueType(0);
8620 EVT SelectVT = NewVT;
8621 if (NewVT.
bitsLT(MVT::i32)) {
8624 SelectVT = MVT::i32;
8630 if (NewVT != SelectVT)
8636 if (
N->getValueType(0) != MVT::v2f16)
8648 if (
N->getValueType(0) != MVT::v2f16)
8660 if (
N->getValueType(0) != MVT::f16)
8675 if (U.get() !=
Value)
8678 if (U.getUser()->getOpcode() == Opcode)
8684unsigned SITargetLowering::isCFIntrinsic(
const SDNode *Intr)
const {
8687 case Intrinsic::amdgcn_if:
8688 return AMDGPUISD::IF;
8689 case Intrinsic::amdgcn_else:
8690 return AMDGPUISD::ELSE;
8691 case Intrinsic::amdgcn_loop:
8692 return AMDGPUISD::LOOP;
8693 case Intrinsic::amdgcn_end_cf:
8713 if (Subtarget->isAmdPalOS() || Subtarget->isMesa3DOS())
8737 assert(GVar->isDeclaration() &&
8738 "AS 3 & 13 GVs should be declaration here "
8739 "when object linking is enabled");
8754 SDNode *Intr = BRCOND.getOperand(1).getNode();
8771 Intr =
LHS.getNode();
8779 assert(BR &&
"brcond missing unconditional branch user");
8784 unsigned CFNode = isCFIntrinsic(Intr);
8802 Ops.push_back(Target);
8825 for (
unsigned i = 1, e = Intr->
getNumValues() - 1; i != e; ++i) {
8844 MVT VT =
Op.getSimpleValueType();
8847 if (
Op.getConstantOperandVal(0) != 0)
8851 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8853 if (
Info->isEntryFunction())
8870 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
8884 return Op.getValueType().bitsLE(VT)
8892 EVT DstVT =
Op.getValueType();
8899 unsigned Opc =
Op.getOpcode();
8910 bool IsStrict =
Op->isStrictFPOpcode();
8911 SDValue Src =
Op.getOperand(IsStrict ? 1 : 0);
8912 EVT SrcVT = Src.getValueType();
8913 EVT DstVT =
Op.getValueType();
8916 assert(Subtarget->hasCvtPkF16F32Inst() &&
"support v_cvt_pk_f16_f32");
8919 return SrcVT == MVT::v2f32 ?
Op : splitFP_ROUNDVectorOp(
Op, DAG);
8926 if (DstVT == MVT::f16) {
8931 if (!Subtarget->has16BitInsts()) {
8936 if (
Op->getFlags().hasApproximateFuncs()) {
8947 "custom lower FP_ROUND for f16 or bf16");
8948 assert(Subtarget->hasBF16ConversionInsts() &&
"f32 -> bf16 is legal");
8965 EVT VT =
Op.getValueType();
8967 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8968 bool IsIEEEMode =
Info->getMode().IEEE;
8974 if (IsIEEEMode && !Subtarget->hasIEEEMinimumMaximumInsts())
8977 if (VT == MVT::v4f16 || VT == MVT::v8f16 || VT == MVT::v16f16 ||
8978 VT == MVT::v32f16 || VT == MVT::v4bf16 || VT == MVT::v8bf16 ||
8979 VT == MVT::v16bf16 || VT == MVT::v32bf16 || VT == MVT::v4f64 ||
8980 VT == MVT::v8f64 || VT == MVT::v16f64 || VT == MVT::v32f64)
8986SITargetLowering::lowerFMINIMUMNUM_FMAXIMUMNUM(
SDValue Op,
8988 EVT VT =
Op.getValueType();
8990 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8991 bool IsIEEEMode =
Info->getMode().IEEE;
8993 if (IsIEEEMode && !Subtarget->hasIEEEMinimumMaximumInsts())
8996 if (VT == MVT::v4f16 || VT == MVT::v8f16 || VT == MVT::v16f16 ||
8997 VT == MVT::v32f16 || VT == MVT::v4bf16 || VT == MVT::v8bf16 ||
8998 VT == MVT::v16bf16 || VT == MVT::v32bf16 || VT == MVT::v4f64 ||
8999 VT == MVT::v8f64 || VT == MVT::v16f64 || VT == MVT::v32f64)
9006 EVT VT =
Op.getValueType();
9010 EVT ExpVT =
Exp.getValueType();
9011 if (ExpVT == MVT::i16)
9032 {
Op.getOperand(0),
Op.getOperand(1), TruncExp});
9039 switch (
Op->getOpcode()) {
9072SITargetLowering::promoteUniformUnaryOpToI32(
SDValue Op,
9073 DAGCombinerInfo &DCI)
const {
9074 EVT OpTy =
Op.getValueType();
9075 SelectionDAG &DAG = DCI.DAG;
9092 DAGCombinerInfo &DCI)
const {
9093 const unsigned Opc =
Op.getOpcode();
9102 :
Op->getOperand(0).getValueType();
9103 auto &DAG = DCI.DAG;
9106 if (DCI.isBeforeLegalizeOps() ||
9114 LHS =
Op->getOperand(1);
9115 RHS =
Op->getOperand(2);
9117 LHS =
Op->getOperand(0);
9118 RHS =
Op->getOperand(1);
9160 EVT SignVT =
Sign.getValueType();
9162 if (MagVT == SignVT)
9183 EVT VT =
Op.getValueType();
9189 assert(VT == MVT::i64 &&
"The following code is a special for s_mul_u64");
9216 if (
Op->isDivergent())
9229 if (Op0LeadingZeros >= 32 && Op1LeadingZeros >= 32)
9231 DAG.
getMachineNode(AMDGPU::S_MUL_U64_U32_PSEUDO, SL, VT, Op0, Op1), 0);
9234 if (Op0SignBits >= 33 && Op1SignBits >= 33)
9236 DAG.
getMachineNode(AMDGPU::S_MUL_I64_I32_PSEUDO, SL, VT, Op0, Op1), 0);
9242 EVT VT =
Op.getValueType();
9249 const APInt &
C = RHSC->getAPIntValue();
9251 if (
C.isPowerOf2()) {
9253 bool UseArithShift =
isSigned && !
C.isMinSignedValue();
9280 if (
Op->isDivergent()) {
9284 if (Subtarget->hasSMulHi()) {
9295 if (!Subtarget->hasTrapHandler() ||
9297 return lowerTrapEndpgm(
Op, DAG);
9299 return Subtarget->supportsGetDoorbellID() ? lowerTrapHsa(
Op, DAG)
9300 : lowerTrapHsaQueuePtr(
Op, DAG);
9306 return DAG.
getNode(AMDGPUISD::ENDPGM_TRAP, SL, MVT::Other, Chain);
9310SITargetLowering::loadImplicitKernelArgument(
SelectionDAG &DAG,
MVT VT,
9312 ImplicitParameter Param)
const {
9316 MachinePointerInfo PtrInfo =
9333 loadImplicitKernelArgument(DAG, MVT::i64, SL,
Align(8),
QUEUE_PTR);
9336 SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
9339 if (UserSGPR == AMDGPU::NoRegister) {
9356 return DAG.
getNode(AMDGPUISD::TRAP, SL, MVT::Other,
Ops);
9365 if (Subtarget->hasPrivEnabledTrap2NopBug())
9366 return DAG.
getNode(AMDGPUISD::SIMULATED_TRAP, SL, MVT::Other, Chain);
9370 return DAG.
getNode(AMDGPUISD::TRAP, SL, MVT::Other,
Ops);
9378 if (!Subtarget->hasTrapHandler() ||
9382 "debugtrap handler not supported",
9390 return DAG.
getNode(AMDGPUISD::TRAP, SL, MVT::Other,
Ops);
9400 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
9401 SmallSet<Register, 8> SGPRInputRegs;
9403 unsigned NumVals = 0;
9406 const InlineAsm::Flag
Flags(
Op.getConstantOperandVal(
I));
9407 NumVals =
Flags.getNumOperandRegisters();
9411 NumVals > 0 &&
Flags.hasRegClassConstraint(RCID) &&
9412 TRI->isSGPRClass(
TRI->getRegClass(RCID));
9414 for (
unsigned J = 0; J < NumVals; ++J) {
9416 if (
const RegisterSDNode *RegNode =
9425 if (SGPRInputRegs.
empty())
9430 SDNode *
N =
Op.getOperand(
NumOps - 1).getNode();
9442 ReadFirstLaneID, SrcVal);
9446 if (
N->getNumOperands() > 3)
9447 Ops.push_back(
N->getOperand(3));
9453 SDNode *
Next =
nullptr;
9454 for (
unsigned I = 0,
E =
N->getNumOperands();
I !=
E; ++
I) {
9455 if (
N->getOperand(
I).getValueType() == MVT::Glue) {
9456 Next =
N->getOperand(
I).getNode();
9466SDValue SITargetLowering::getSegmentAperture(
unsigned AS,
const SDLoc &
DL,
9468 unsigned BaseAS = AS;
9473 SDValue Aperture = getBaseSegmentAperture(BaseAS,
DL, DAG);
9483SDValue SITargetLowering::getBaseSegmentAperture(
unsigned AS,
const SDLoc &
DL,
9487 if (Subtarget->hasApertureRegs()) {
9488 const unsigned ApertureRegNo =
9489 IsLDS ? AMDGPU::SRC_SHARED_BASE : AMDGPU::SRC_PRIVATE_BASE;
9490 assert((ApertureRegNo != AMDGPU::SRC_PRIVATE_BASE ||
9491 !Subtarget->hasGloballyAddressableScratch()) &&
9492 "Cannot use src_private_base with globally addressable scratch!");
9512 return loadImplicitKernelArgument(DAG, MVT::i32,
DL,
Align(4), Param);
9516 SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
9518 if (UserSGPR == AMDGPU::NoRegister) {
9529 uint32_t StructOffset = IsLDS ? 0x40 : 0x44;
9563 const AMDGPUTargetMachine &TM =
9567 unsigned SrcAS = ASC->getSrcAddressSpace();
9568 SDValue Src = ASC->getOperand(0);
9569 unsigned DestAS = ASC->getDestAddressSpace();
9570 bool IsNonNull = ASC->getFlags().hasNonNull();
9582 Subtarget->hasGloballyAddressableScratch()) {
9587 AMDGPU::S_MOV_B32, SL, MVT::i32,
9588 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE_LO, MVT::i32)),
9612 Subtarget->hasGloballyAddressableScratch()) {
9621 if (Subtarget->isWave64())
9627 57 - 32 - Subtarget->getWavefrontSizeLog2(), MVT::i32, SL);
9635 AMDGPU::S_MOV_B64, SL, MVT::i64,
9636 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE, MVT::i64)),
9638 CvtPtr = DAG.
getNode(
ISD::ADD, SL, MVT::i64, CvtPtr, FlatScratchBase);
9640 SDValue Aperture = getSegmentAperture(SrcAS, SL, DAG);
9661 Op.getValueType() == MVT::i64) {
9662 const SIMachineFunctionInfo *
Info =
9664 if (
Info->get32BitAddressHighBits() == 0)
9673 Src.getValueType() == MVT::i64)
9696 unsigned IdxVal =
Idx->getAsZExtVal();
9701 assert(InsNumElts % 2 == 0 &&
"expect legal vector types");
9706 EVT NewInsVT = InsNumElts == 2 ? MVT::i32
9708 MVT::i32, InsNumElts / 2);
9713 for (
unsigned I = 0;
I != InsNumElts / 2; ++
I) {
9715 if (InsNumElts == 2) {
9728 for (
unsigned I = 0;
I != InsNumElts; ++
I) {
9751 if (NumElts == 4 && EltSize == 16 && KIdx) {
9762 unsigned Idx = KIdx->getZExtValue();
9763 bool InsertLo =
Idx < 2;
9767 DAG.
getConstant(InsertLo ? Idx : (Idx - 2), SL, MVT::i32));
9773 : DAG.getBuildVector(MVT::v2i32, SL, {LoHalf, InsHalf});
9787 unsigned PieceSize = std::min(VecSize, 64u);
9788 unsigned NumPieces =
VecSize / PieceSize;
9789 unsigned EltsPerPiece = PieceSize / EltSize;
9824 InsertIntoPiece(DAG.
getBitcast(IntVT, Vec), BFM));
9836 for (
unsigned I = 0;
I != NumPieces; ++
I) {
9842 Pieces.
push_back(InsertIntoPiece(Piece, Mask));
9852 EVT ResultVT =
Op.getValueType();
9865 if (
SDValue Combined = performExtractVectorEltCombine(
Op.getNode(), DCI))
9868 if (VecSize == 128 || VecSize == 256 || VecSize == 512) {
9872 if (VecSize == 128) {
9880 }
else if (VecSize == 256) {
9883 for (
unsigned P = 0;
P < 4; ++
P) {
9889 Parts[0], Parts[1]));
9891 Parts[2], Parts[3]));
9897 for (
unsigned P = 0;
P < 8; ++
P) {
9904 Parts[0], Parts[1], Parts[2], Parts[3]));
9907 Parts[4], Parts[5], Parts[6], Parts[7]));
9910 EVT IdxVT =
Idx.getValueType();
9927 Src = DAG.
getBitcast(Src.getValueType().changeTypeToInteger(), Src);
9942 if (ResultVT == MVT::f16 || ResultVT == MVT::bf16) {
9952 return Mask[Elt + 1] == Mask[Elt] + 1 && (Mask[Elt] % 2 == 0);
9957 return Mask[Elt] >= 0 && Mask[Elt + 1] >= 0 && (Mask[Elt] & 1) &&
9958 !(Mask[Elt + 1] & 1);
9964 EVT ResultVT =
Op.getValueType();
9967 const int NewSrcNumElts = 2;
9969 int SrcNumElts =
Op.getOperand(0).getValueType().getVectorNumElements();
9985 const bool ShouldUseConsecutiveExtract = EltVT.
getSizeInBits() == 16;
10007 if (ShouldUseConsecutiveExtract &&
10010 int VecIdx =
Idx < SrcNumElts ? 0 : 1;
10011 int EltIdx =
Idx < SrcNumElts ?
Idx :
Idx - SrcNumElts;
10023 if (Idx0 >= SrcNumElts) {
10025 Idx0 -= SrcNumElts;
10028 if (Idx1 >= SrcNumElts) {
10030 Idx1 -= SrcNumElts;
10033 int AlignedIdx0 = Idx0 & ~(NewSrcNumElts - 1);
10034 int AlignedIdx1 = Idx1 & ~(NewSrcNumElts - 1);
10042 int NewMaskIdx0 = Idx0 - AlignedIdx0;
10043 int NewMaskIdx1 = Idx1 - AlignedIdx1;
10048 if (SubVec0 != SubVec1) {
10049 NewMaskIdx1 += NewSrcNumElts;
10056 {NewMaskIdx0, NewMaskIdx1});
10061 int VecIdx0 = Idx0 < SrcNumElts ? 0 : 1;
10062 int VecIdx1 = Idx1 < SrcNumElts ? 0 : 1;
10063 int EltIdx0 = Idx0 < SrcNumElts ? Idx0 : Idx0 - SrcNumElts;
10064 int EltIdx1 = Idx1 < SrcNumElts ? Idx1 : Idx1 - SrcNumElts;
10083 EVT ResultVT =
Op.getValueType();
10099 EVT VT =
Op.getValueType();
10101 if (VT == MVT::v2f16 || VT == MVT::v2i16 || VT == MVT::v2bf16) {
10102 assert(!Subtarget->hasVOP3PInsts() &&
"this should be legal");
10108 if (
Hi.isUndef()) {
10138 PartVT, SL, {
Op.getOperand(
P * 2),
Op.getOperand(
P * 2 + 1)});
10164 if (!Subtarget->isAmdHsaOS())
10207 return DAG.
getNode(AMDGPUISD::PC_ADD_REL_OFFSET64,
DL, PtrVT, Ptr);
10216 return DAG.
getNode(AMDGPUISD::PC_ADD_REL_OFFSET,
DL, PtrVT, PtrLo, PtrHi);
10224 EVT PtrVT =
Op.getValueType();
10226 const GlobalValue *GV = GSD->
getGlobal();
10239 assert(PtrVT == MVT::i32 &&
"32-bit pointer is expected.");
10260 return DAG.
getNode(AMDGPUISD::LDS,
DL, MVT::i32, GA);
10263 if (Subtarget->isAmdPalOS() || Subtarget->isMesa3DOS()) {
10264 if (Subtarget->has64BitLiterals()) {
10273 AddrLo = {DAG.
getMachineNode(AMDGPU::S_MOV_B32,
DL, MVT::i32, AddrLo), 0};
10277 AddrHi = {DAG.
getMachineNode(AMDGPU::S_MOV_B32,
DL, MVT::i32, AddrHi), 0};
10295 MachinePointerInfo PtrInfo =
10315 "unsupported alloca in VGPR 'as memory' address space (13)",
10325 Fn,
"unsupported external symbol",
Op.getDebugLoc()));
10347 unsigned Offset)
const {
10349 SDValue Param = lowerKernargMemParameter(
10360 "non-hsa intrinsic with hsa target",
DL.getDebugLoc()));
10368 "intrinsic not supported on subtarget",
DL.getDebugLoc()));
10376 unsigned NumElts = Elts.
size();
10378 if (NumElts <= 12) {
10382 Type = MVT::v16f32;
10387 for (
unsigned i = 0; i < Elts.
size(); ++i) {
10393 for (
unsigned i = Elts.
size(); i < NumElts; ++i)
10402 SDValue Src,
int ExtraElts) {
10403 EVT SrcVT = Src.getValueType();
10413 while (ExtraElts--)
10424 bool Unpacked,
bool IsD16,
int DMaskPop,
10425 int NumVDataDwords,
bool IsAtomicPacked16Bit,
10429 EVT ReqRetVT = ResultTypes[0];
10431 int NumDataDwords = ((IsD16 && !Unpacked) || IsAtomicPacked16Bit)
10432 ? (ReqRetNumElts + 1) / 2
10435 int MaskPopDwords = (!IsD16 || Unpacked) ? DMaskPop : (DMaskPop + 1) / 2;
10438 NumDataDwords == 1 ? MVT::i32 :
MVT::getVectorVT(MVT::i32, NumDataDwords);
10441 MaskPopDwords == 1 ? MVT::i32 :
MVT::getVectorVT(MVT::i32, MaskPopDwords);
10446 if (DMaskPop > 0 &&
Data.getValueType() != MaskPopVT) {
10450 SDValue(Result, 0), ZeroIdx);
10453 SDValue(Result, 0), ZeroIdx);
10457 if (DataDwordVT.
isVector() && !IsAtomicPacked16Bit)
10459 NumDataDwords - MaskPopDwords);
10464 EVT LegalReqRetVT = ReqRetVT;
10466 if (!
Data.getValueType().isInteger())
10468 Data.getValueType().changeTypeToInteger(),
Data);
10489 if (Result->getNumValues() == 1)
10496 SDValue *LWE,
bool &IsTexFail) {
10516 unsigned DimIdx,
unsigned EndIdx,
10517 unsigned NumGradients) {
10519 for (
unsigned I = DimIdx;
I < EndIdx;
I++) {
10527 if (((
I + 1) >= EndIdx) ||
10528 ((NumGradients / 2) % 2 == 1 && (
I == DimIdx + (NumGradients / 2) - 1 ||
10529 I == DimIdx + NumGradients - 1))) {
10561 !
Op.getNode()->hasAnyUseOfValue(0))
10563 const AMDGPU::MIMGBaseOpcodeInfo *BaseOpcode =
10574 ResultTypes.erase(&ResultTypes[0]);
10576 bool IsD16 =
false;
10577 bool IsG16 =
false;
10578 bool IsA16 =
false;
10580 int NumVDataDwords = 0;
10581 bool AdjustRetType =
false;
10582 bool IsAtomicPacked16Bit =
false;
10585 const unsigned ArgOffset = WithChain ? 2 : 1;
10588 unsigned DMaskLanes = 0;
10590 if (BaseOpcode->
Atomic) {
10591 VData =
Op.getOperand(2);
10593 IsAtomicPacked16Bit =
10594 (IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_F16 ||
10595 IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_F16_NORTN ||
10596 IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_BF16 ||
10597 IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_BF16_NORTN);
10602 "unsupported image atomic data type");
10614 ResultTypes[0] = Is64Bit ? MVT::v2i64 : MVT::v2i32;
10616 DMask = Is64Bit ? 0xf : 0x3;
10617 NumVDataDwords = Is64Bit ? 4 : 2;
10619 DMask = Is64Bit ? 0x3 : 0x1;
10620 NumVDataDwords = Is64Bit ? 2 : 1;
10623 DMask =
Op->getConstantOperandVal(ArgOffset + Intr->
DMaskIndex);
10626 if (BaseOpcode->
Store) {
10627 VData =
Op.getOperand(2);
10631 if (StoreScalarVT != MVT::f16 && StoreScalarVT.
getSizeInBits() != 32 &&
10634 "unsupported image store data type");
10636 if (StoreScalarVT == MVT::f16) {
10637 if (!Subtarget->hasD16Images() || !BaseOpcode->
HasD16)
10641 VData = handleD16VData(VData, DAG,
true);
10644 NumVDataDwords = (VData.
getValueType().getSizeInBits() + 31) / 32;
10645 }
else if (!BaseOpcode->
NoReturn) {
10650 if (LoadScalarVT != MVT::f16 && LoadScalarVT.
getSizeInBits() != 32 &&
10653 "unsupported image load data type");
10655 if (LoadScalarVT == MVT::f16) {
10656 if (!Subtarget->hasD16Images() || !BaseOpcode->
HasD16)
10664 (!LoadVT.
isVector() && DMaskLanes > 1))
10670 if (IsD16 && !Subtarget->hasUnpackedD16VMem() &&
10671 !(BaseOpcode->
Gather4 && Subtarget->hasImageGather4D16Bug()))
10672 NumVDataDwords = (DMaskLanes + 1) / 2;
10674 NumVDataDwords = DMaskLanes;
10676 AdjustRetType =
true;
10680 unsigned VAddrEnd = ArgOffset + Intr->
VAddrEnd;
10687 MVT GradPackVectorVT = VAddrScalarVT == MVT::f16 ? MVT::v2f16 : MVT::v2i16;
10688 IsG16 = VAddrScalarVT == MVT::f16 || VAddrScalarVT == MVT::i16;
10690 VAddrVT =
Op.getOperand(ArgOffset + Intr->
CoordStart).getSimpleValueType();
10692 MVT AddrPackVectorVT = VAddrScalarVT == MVT::f16 ? MVT::v2f16 : MVT::v2i16;
10693 IsA16 = VAddrScalarVT == MVT::f16 || VAddrScalarVT == MVT::i16;
10697 if (IsA16 && (
Op.getOperand(ArgOffset +
I).getValueType() == MVT::f16)) {
10703 {
Op.getOperand(ArgOffset +
I), DAG.
getPOISON(MVT::f16)});
10707 "Bias needs to be converted to 16 bit in A16 mode");
10712 if (BaseOpcode->
Gradients && !
ST->hasG16() && (IsA16 != IsG16)) {
10716 dbgs() <<
"Failed to lower image intrinsic: 16 bit addresses "
10717 "require 16 bit args for both gradients and addresses");
10722 if (!
ST->hasA16()) {
10723 LLVM_DEBUG(
dbgs() <<
"Failed to lower image intrinsic: Target does not "
10724 "support 16 bit addresses\n");
10734 if (BaseOpcode->
Gradients && IsG16 &&
ST->hasG16()) {
10736 const AMDGPU::MIMGG16MappingInfo *G16MappingInfo =
10738 IntrOpcode = G16MappingInfo->
G16;
10761 for (
unsigned I = ArgOffset + Intr->
CoordStart;
I < VAddrEnd;
I++)
10779 const unsigned NSAMaxSize =
ST->getNSAMaxSize(BaseOpcode->
Sampler);
10780 const bool HasPartialNSAEncoding =
ST->hasPartialNSAEncoding();
10781 const bool UseNSA =
ST->hasNSAEncoding() &&
10782 VAddrs.
size() >=
ST->getNSAThreshold(MF) &&
10783 (VAddrs.
size() <= NSAMaxSize || HasPartialNSAEncoding);
10784 const bool UsePartialNSA =
10785 UseNSA && HasPartialNSAEncoding && VAddrs.
size() > NSAMaxSize;
10788 if (UsePartialNSA) {
10790 ArrayRef(VAddrs).drop_front(NSAMaxSize - 1));
10791 }
else if (!UseNSA) {
10802 Op.getConstantOperandVal(ArgOffset + Intr->
UnormIndex);
10810 bool IsTexFail =
false;
10811 if (!
parseTexFail(TexFail, DAG, &TFE, &LWE, IsTexFail))
10820 NumVDataDwords = 1;
10822 NumVDataDwords += 1;
10823 AdjustRetType =
true;
10828 if (AdjustRetType) {
10831 if (DMaskLanes == 0 && !BaseOpcode->
Store) {
10840 MVT::i32, NumVDataDwords)
10843 ResultTypes[0] = NewVT;
10844 if (ResultTypes.size() == 3) {
10848 ResultTypes.erase(&ResultTypes[1]);
10862 Ops.push_back(VData);
10863 if (UsePartialNSA) {
10865 Ops.push_back(VAddr);
10869 Ops.push_back(VAddr);
10872 bool IndexedRsrc = IsGFX13 && RsrcVT == MVT::i32;
10873 if (RsrcVT != MVT::v4i32 && RsrcVT != MVT::v8i32 && !IndexedRsrc)
10875 Ops.push_back(Rsrc);
10876 bool IsSampIndexed =
false;
10880 IsSampIndexed = IsGFX13 && SampVT == MVT::i32;
10881 if (SampVT != MVT::v4i32 && !IsSampIndexed)
10883 Ops.push_back(Samp);
10888 if (!IsGFX12Plus || BaseOpcode->
Sampler || BaseOpcode->
MSAA)
10889 Ops.push_back(Unorm);
10891 Ops.push_back(IsA16 &&
10892 ST->hasFeature(AMDGPU::FeatureR128A16)
10898 if (!Subtarget->hasGFX90AInsts())
10899 Ops.push_back(TFE);
10903 "TFE is not supported on this GPU",
DL.getDebugLoc()));
10906 if (!IsGFX12Plus || BaseOpcode->
Sampler || BaseOpcode->
MSAA)
10907 Ops.push_back(LWE);
10913 Ops.push_back(
Op.getOperand(0));
10915 int NumVAddrDwords =
10922 NumVAddrDwords, IndexedRsrc, IsSampIndexed);
10923 }
else if (IsGFX12Plus) {
10925 NumVDataDwords, NumVAddrDwords);
10926 }
else if (IsGFX11Plus) {
10928 UseNSA ? AMDGPU::MIMGEncGfx11NSA
10929 : AMDGPU::MIMGEncGfx11Default,
10930 NumVDataDwords, NumVAddrDwords);
10931 }
else if (IsGFX10Plus) {
10933 UseNSA ? AMDGPU::MIMGEncGfx10NSA
10934 : AMDGPU::MIMGEncGfx10Default,
10935 NumVDataDwords, NumVAddrDwords);
10937 if (Subtarget->hasGFX90AInsts()) {
10939 NumVDataDwords, NumVAddrDwords);
10940 if (Opcode == -1) {
10942 DAG,
Op, OrigResultTypes,
DL,
10943 "requested image instruction is not supported on this GPU");
10946 if (Opcode == -1 &&
10949 NumVDataDwords, NumVAddrDwords);
10952 NumVDataDwords, NumVAddrDwords);
10959 MachineMemOperand *MemRef = MemOp->getMemOperand();
10978 Subtarget->hasUnpackedD16VMem(), IsD16, DMaskLanes,
10979 NumVDataDwords, IsAtomicPacked16Bit,
DL);
10988 bool HasChainResult = MMO !=
nullptr;
10992 bool IsSubwordLoad = (MemVT == MVT::i8 || MemVT == MVT::i16) &&
10993 Subtarget->hasScalarSubwordLoads();
10996 MF.
getFunction(),
"unsupported s_buffer_load result type",
10997 DL.getDebugLoc()));
10998 EVT ResultTypes[] = {VT, MVT::Other};
11000 ArrayRef(ResultTypes, HasChainResult ? 2 : 1), Chain,
DL);
11003 if (!HasChainResult) {
11015 if (!
Offset->isDivergent()) {
11023 auto HandleScalarSubwordLoads = [&](
unsigned Opcode) ->
SDValue {
11025 Opcode,
DL, DAG.
getVTList(MVT::i32, MVT::Other),
Ops, MemVT, MMO);
11028 if (HasChainResult)
11032 if (MemVT == MVT::i8 && Subtarget->hasScalarSubwordLoads())
11033 return HandleScalarSubwordLoads(AMDGPUISD::SBUFFER_LOAD_UBYTE);
11035 if (MemVT == MVT::i16 && Subtarget->hasScalarSubwordLoads())
11036 return HandleScalarSubwordLoads(AMDGPUISD::SBUFFER_LOAD_USHORT);
11041 !Subtarget->hasScalarDwordx3Loads()) {
11045 AMDGPUISD::SBUFFER_LOAD,
DL, DAG.
getVTList(WidenedVT, MVT::Other),
11050 if (HasChainResult)
11072 if ((MemVT == MVT::i8 || MemVT == MVT::i16) &&
11073 Subtarget->hasScalarSubwordLoads()) {
11077 if (HasChainResult)
11083 unsigned NumLoads = 1;
11089 if (NumElts == 8 || NumElts == 16) {
11090 NumLoads = NumElts / 4;
11094 SDVTList VTList = DAG.
getVTList({LoadVT, MVT::Other});
11099 NumLoads > 1 ?
Align(16 * NumLoads) :
Align(4));
11103 for (
unsigned i = 0; i < NumLoads; ++i) {
11106 Loads.
push_back(getMemIntrinsicNode(AMDGPUISD::BUFFER_LOAD,
DL, VTList,
Ops,
11107 LoadVT, LoadMMO, DAG));
11110 if (NumElts == 8 || NumElts == 16) {
11112 if (HasChainResult) {
11127 if (!Subtarget->hasArchitectedSGPRs())
11132 return DAG.
getNode(AMDGPUISD::BFE_U32, SL, VT, TTMP8,
11139 unsigned Width)
const {
11141 using namespace AMDGPU::Hwreg;
11143 AMDGPU::S_GETREG_B32_const, SL, MVT::i32,
11183 EVT DstVT =
Op.getValueType();
11185 assert((!IsF16 || Subtarget->hasFP8F16ConversionInsts()) &&
11186 "fp8/bf8 -> f16 conversion requires FP8F16ConversionInsts");
11190 Opc = IsBF8 ? AMDGPUISD::CVT_PK_F16_BF8 : AMDGPUISD::CVT_PK_F16_FP8;
11192 Opc = IsBF8 ? AMDGPUISD::CVT_PK_F32_BF8 : AMDGPUISD::CVT_PK_F32_FP8;
11205SITargetLowering::LowerCONVERT_FROM_ARBITRARY_FP(
SDValue Op,
11214 const bool HasE5M3ConversionInsts =
11215 Subtarget->hasFP8ConversionInsts() && Subtarget->hasFP8E5M3Insts();
11216 const bool IsSupported = IsFP8 || IsBF8 || (IsE5M3 && HasE5M3ConversionInsts);
11220 EVT DstVT =
Op.getValueType();
11224 !Subtarget->hasFP8F16ConversionInsts())
11234 "only the v2f32 vector result is custom lowered");
11240 auto ConvertByte = [&](
unsigned ByteSel) {
11241 return DAG.
getNode(AMDGPUISD::CVT_F32_FP8_E5M3, SL, MVT::f32, Src,
11246 return ConvertByte(0);
11247 return DAG.
getBuildVector(DstVT, SL, {ConvertByte(0), ConvertByte(1)});
11252 if (Src.getValueType() != MVT::i32) {
11262 if (EltVT == MVT::f16 || EltVT == MVT::f32)
11263 return lowerFromFP8(
Op, IsBF8, DAG);
11271 EVT ResVT =
Op.getValueType();
11272 bool IsF16 = Src.getValueType().getScalarType() == MVT::f16;
11273 assert((!IsF16 || Subtarget->hasF16FP8ConversionInsts()) &&
11274 "f16 -> fp8/bf8 conversion requires F16FP8ConversionInsts");
11276 "only the v2i8 vector result is custom lowered");
11280 IsBF8 ? AMDGPUISD::CVT_PK_BF8_F16 : AMDGPUISD::CVT_PK_FP8_F16;
11285 unsigned Opc = IsBF8 ? AMDGPUISD::CVT_PK_BF8_F32
11286 : IsE5M3 ? AMDGPUISD::CVT_PK_FP8_F32_E5M3
11287 : AMDGPUISD::CVT_PK_FP8_F32;
11295 DAG.
getNode(
Opc, SL, MVT::i32, Src, Src, PoisonI32, WordSel);
11307SITargetLowering::LowerCONVERT_TO_ARBITRARY_FP(
SDValue Op,
11316 const bool HasE5M3ConversionInsts =
11317 Subtarget->hasFP8ConversionInsts() && Subtarget->hasFP8E5M3Insts();
11318 const bool IsSupported = IsFP8 || IsBF8 || (IsE5M3 && HasE5M3ConversionInsts);
11328 if (!IsE5M3 &&
Op.getConstantOperandVal(3) != 0)
11331 EVT SrcEltVT =
Op.getOperand(0).getValueType().getScalarType();
11334 if (SrcEltVT == MVT::f32)
11335 return lowerToFP8(
Op, IsBF8, IsE5M3, DAG);
11336 if (!IsE5M3 && SrcEltVT == MVT::f16 &&
11337 Subtarget->hasF16FP8ConversionInsts()) {
11340 if (!
Op.getValueType().isVector())
11342 return lowerToFP8(
Op, IsBF8,
false, DAG);
11350 auto *MFI = MF.
getInfo<SIMachineFunctionInfo>();
11352 EVT VT =
Op.getValueType();
11354 unsigned IntrinsicID =
Op.getConstantOperandVal(0);
11358 switch (IntrinsicID) {
11359 case Intrinsic::amdgcn_wave_reduce_min:
11360 case Intrinsic::amdgcn_wave_reduce_umin:
11361 case Intrinsic::amdgcn_wave_reduce_fmin:
11362 case Intrinsic::amdgcn_wave_reduce_max:
11363 case Intrinsic::amdgcn_wave_reduce_umax:
11364 case Intrinsic::amdgcn_wave_reduce_fmax:
11365 case Intrinsic::amdgcn_wave_reduce_add:
11366 case Intrinsic::amdgcn_wave_reduce_fadd:
11367 case Intrinsic::amdgcn_wave_reduce_sub:
11368 case Intrinsic::amdgcn_wave_reduce_fsub:
11369 case Intrinsic::amdgcn_wave_reduce_and:
11370 case Intrinsic::amdgcn_wave_reduce_or:
11371 case Intrinsic::amdgcn_wave_reduce_xor: {
11372 EVT SrcVT =
Op.getOperand(1).getValueType();
11375 bool NeedsSignExt = IntrinsicID == Intrinsic::amdgcn_wave_reduce_min ||
11376 IntrinsicID == Intrinsic::amdgcn_wave_reduce_max ||
11377 IntrinsicID == Intrinsic::amdgcn_wave_reduce_add ||
11378 IntrinsicID == Intrinsic::amdgcn_wave_reduce_sub;
11382 auto SrcType = IsFPOp ? MVT::f16 : MVT::i16;
11383 auto ExtType = IsFPOp ? MVT::f32 : MVT::i32;
11387 Op.getOperand(0), ExtendedSrc, Strategy);
11396 case Intrinsic::amdgcn_implicit_buffer_ptr: {
11397 if (!MFI->getUserSGPRInfo().hasImplicitBufferPtr()) {
11398 const char *
Error =
11399 Subtarget->hasArchitectedFlatScratch()
11400 ?
"intrinsic not supported on subtarget"
11401 : !Subtarget->isMesa3DOS()
11402 ?
"intrinsic not supported for OS"
11403 :
"intrinsic not supported for calling convention";
11409 return getPreloadedValue(DAG, *MFI, VT,
11412 case Intrinsic::amdgcn_dispatch_ptr:
11413 case Intrinsic::amdgcn_queue_ptr: {
11414 if (!Subtarget->isAmdHsaOrMesa(MF.
getFunction())) {
11416 MF.
getFunction(),
"unsupported hsa intrinsic without hsa target",
11417 DL.getDebugLoc()));
11421 auto RegID = IntrinsicID == Intrinsic::amdgcn_dispatch_ptr
11424 return getPreloadedValue(DAG, *MFI, VT, RegID);
11426 case Intrinsic::amdgcn_implicitarg_ptr: {
11428 return getImplicitArgPtr(DAG,
DL);
11429 return getPreloadedValue(DAG, *MFI, VT,
11432 case Intrinsic::amdgcn_kernarg_segment_ptr: {
11438 return getPreloadedValue(DAG, *MFI, VT,
11441 case Intrinsic::amdgcn_dispatch_id: {
11444 case Intrinsic::amdgcn_rcp:
11445 return DAG.
getNode(AMDGPUISD::RCP,
DL, VT,
Op.getOperand(1));
11446 case Intrinsic::amdgcn_rsq:
11447 return DAG.
getNode(AMDGPUISD::RSQ,
DL, VT,
Op.getOperand(1));
11448 case Intrinsic::amdgcn_rsq_legacy:
11452 case Intrinsic::amdgcn_rcp_legacy:
11455 return DAG.
getNode(AMDGPUISD::RCP_LEGACY,
DL, VT,
Op.getOperand(1));
11456 case Intrinsic::amdgcn_fma_legacy:
11457 case Intrinsic::amdgcn_sudot4:
11458 case Intrinsic::amdgcn_sudot8:
11459 case Intrinsic::amdgcn_tanh:
11461 case Intrinsic::amdgcn_rsq_clamp: {
11463 return DAG.
getNode(AMDGPUISD::RSQ_CLAMP,
DL, VT,
Op.getOperand(1));
11475 case Intrinsic::r600_read_ngroups_x:
11476 if (Subtarget->isAmdHsaOS())
11479 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
11482 case Intrinsic::r600_read_ngroups_y:
11483 if (Subtarget->isAmdHsaOS())
11486 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
11489 case Intrinsic::r600_read_ngroups_z:
11490 if (Subtarget->isAmdHsaOS())
11493 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
11496 case Intrinsic::r600_read_local_size_x:
11497 if (Subtarget->isAmdHsaOS())
11500 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
11502 case Intrinsic::r600_read_local_size_y:
11503 if (Subtarget->isAmdHsaOS())
11506 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
11508 case Intrinsic::r600_read_local_size_z:
11509 if (Subtarget->isAmdHsaOS())
11512 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
11514 case Intrinsic::amdgcn_workgroup_id_x:
11515 return lowerWorkGroupId(DAG, *MFI, VT,
11519 case Intrinsic::amdgcn_workgroup_id_y:
11520 return lowerWorkGroupId(DAG, *MFI, VT,
11524 case Intrinsic::amdgcn_workgroup_id_z:
11525 return lowerWorkGroupId(DAG, *MFI, VT,
11529 case Intrinsic::amdgcn_cluster_id_x:
11530 return Subtarget->hasClusters()
11531 ? getPreloadedValue(DAG, *MFI, VT,
11533 : DAG.getPOISON(VT);
11534 case Intrinsic::amdgcn_cluster_id_y:
11535 return Subtarget->hasClusters()
11536 ? getPreloadedValue(DAG, *MFI, VT,
11539 case Intrinsic::amdgcn_cluster_id_z:
11540 return Subtarget->hasClusters()
11541 ? getPreloadedValue(DAG, *MFI, VT,
11544 case Intrinsic::amdgcn_cluster_workgroup_id_x:
11545 return lowerClusterWorkGroupValue(
11547 case Intrinsic::amdgcn_cluster_workgroup_id_y:
11548 return lowerClusterWorkGroupValue(
11550 case Intrinsic::amdgcn_cluster_workgroup_id_z:
11551 return lowerClusterWorkGroupValue(
11553 case Intrinsic::amdgcn_cluster_workgroup_flat_id:
11554 return Subtarget->hasClusters()
11557 case Intrinsic::amdgcn_cluster_workgroup_max_id_x:
11558 return lowerClusterWorkGroupValue(
11560 case Intrinsic::amdgcn_cluster_workgroup_max_id_y:
11561 return lowerClusterWorkGroupValue(
11563 case Intrinsic::amdgcn_cluster_workgroup_max_id_z:
11564 return lowerClusterWorkGroupValue(
11566 case Intrinsic::amdgcn_cluster_workgroup_max_flat_id:
11567 return lowerClusterWorkGroupValue(
11569 case Intrinsic::amdgcn_wave_id:
11570 return lowerWaveID(DAG,
Op);
11571 case Intrinsic::amdgcn_lds_kernel_id: {
11573 return getLDSKernelId(DAG,
DL);
11574 return getPreloadedValue(DAG, *MFI, VT,
11577 case Intrinsic::amdgcn_workitem_id_x:
11578 return lowerWorkitemID(DAG,
Op, 0, MFI->getArgInfo().WorkItemIDX);
11579 case Intrinsic::amdgcn_workitem_id_y:
11580 return lowerWorkitemID(DAG,
Op, 1, MFI->getArgInfo().WorkItemIDY);
11581 case Intrinsic::amdgcn_workitem_id_z:
11582 return lowerWorkitemID(DAG,
Op, 2, MFI->getArgInfo().WorkItemIDZ);
11583 case Intrinsic::amdgcn_wavefrontsize:
11585 SDLoc(
Op), MVT::i32);
11586 case Intrinsic::amdgcn_s_buffer_load: {
11587 unsigned CPol =
Op.getConstantOperandVal(3);
11595 Op.getOperand(2),
Op.getOperand(3), DAG);
11597 case Intrinsic::amdgcn_fdiv_fast:
11598 return lowerFDIV_FAST(
Op, DAG);
11599 case Intrinsic::amdgcn_sin:
11600 return DAG.
getNode(AMDGPUISD::SIN_HW,
DL, VT,
Op.getOperand(1));
11602 case Intrinsic::amdgcn_cos:
11603 return DAG.
getNode(AMDGPUISD::COS_HW,
DL, VT,
Op.getOperand(1));
11605 case Intrinsic::amdgcn_mul_u24:
11606 return DAG.
getNode(AMDGPUISD::MUL_U24,
DL, VT,
Op.getOperand(1),
11608 case Intrinsic::amdgcn_mul_i24:
11609 return DAG.
getNode(AMDGPUISD::MUL_I24,
DL, VT,
Op.getOperand(1),
11612 case Intrinsic::amdgcn_log_clamp: {
11618 case Intrinsic::amdgcn_fract:
11619 return DAG.
getNode(AMDGPUISD::FRACT,
DL, VT,
Op.getOperand(1));
11621 case Intrinsic::amdgcn_class: {
11623 EVT SrcVT = Src.getValueType();
11624 bool IsLegal = SrcVT == MVT::f32 || SrcVT == MVT::f64 ||
11625 (SrcVT == MVT::f16 && Subtarget->has16BitInsts());
11629 "llvm.amdgcn.class only supports f16, f32, and f64",
11630 DL.getDebugLoc()));
11633 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, VT, Src,
Op.getOperand(2));
11635 case Intrinsic::amdgcn_div_fmas:
11636 return DAG.
getNode(AMDGPUISD::DIV_FMAS,
DL, VT,
Op.getOperand(1),
11637 Op.getOperand(2),
Op.getOperand(3),
Op.getOperand(4));
11639 case Intrinsic::amdgcn_div_fixup:
11640 return DAG.
getNode(AMDGPUISD::DIV_FIXUP,
DL, VT,
Op.getOperand(1),
11641 Op.getOperand(2),
Op.getOperand(3));
11643 case Intrinsic::amdgcn_div_scale: {
11649 SDValue Denominator =
Op.getOperand(2);
11658 return DAG.
getNode(AMDGPUISD::DIV_SCALE,
DL,
Op->getVTList(), Src0,
11659 Denominator, Numerator);
11661 case Intrinsic::amdgcn_ballot:
11663 case Intrinsic::amdgcn_fmed3:
11664 return DAG.
getNode(AMDGPUISD::FMED3,
DL, VT,
Op.getOperand(1),
11665 Op.getOperand(2),
Op.getOperand(3),
Op->getFlags());
11666 case Intrinsic::amdgcn_fdot2:
11667 return DAG.
getNode(AMDGPUISD::FDOT2,
DL, VT,
Op.getOperand(1),
11668 Op.getOperand(2),
Op.getOperand(3),
Op.getOperand(4));
11669 case Intrinsic::amdgcn_fmul_legacy:
11670 return DAG.
getNode(AMDGPUISD::FMUL_LEGACY,
DL, VT,
Op.getOperand(1),
11672 case Intrinsic::amdgcn_sbfe:
11673 case Intrinsic::amdgcn_ubfe:
11675 case Intrinsic::amdgcn_cvt_pkrtz:
11676 case Intrinsic::amdgcn_cvt_pknorm_i16:
11677 case Intrinsic::amdgcn_cvt_pknorm_u16:
11678 case Intrinsic::amdgcn_cvt_pk_i16:
11679 case Intrinsic::amdgcn_cvt_pk_u16: {
11681 EVT VT =
Op.getValueType();
11684 if (IntrinsicID == Intrinsic::amdgcn_cvt_pkrtz)
11685 Opcode = AMDGPUISD::CVT_PKRTZ_F16_F32;
11686 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pknorm_i16)
11687 Opcode = AMDGPUISD::CVT_PKNORM_I16_F32;
11688 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pknorm_u16)
11689 Opcode = AMDGPUISD::CVT_PKNORM_U16_F32;
11690 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pk_i16)
11691 Opcode = AMDGPUISD::CVT_PK_I16_I32;
11693 Opcode = AMDGPUISD::CVT_PK_U16_U32;
11696 return DAG.
getNode(Opcode,
DL, VT,
Op.getOperand(1),
Op.getOperand(2));
11699 DAG.
getNode(Opcode,
DL, MVT::i32,
Op.getOperand(1),
Op.getOperand(2));
11702 case Intrinsic::amdgcn_fmad_ftz:
11703 return DAG.
getNode(AMDGPUISD::FMAD_FTZ,
DL, VT,
Op.getOperand(1),
11704 Op.getOperand(2),
Op.getOperand(3));
11706 case Intrinsic::amdgcn_if_break:
11708 Op->getOperand(1),
Op->getOperand(2)),
11711 case Intrinsic::amdgcn_groupstaticsize: {
11717 const GlobalValue *GV =
11723 case Intrinsic::amdgcn_is_shared:
11724 case Intrinsic::amdgcn_is_private: {
11731 unsigned AS = (IntrinsicID == Intrinsic::amdgcn_is_shared)
11735 Subtarget->hasGloballyAddressableScratch()) {
11738 AMDGPU::S_MOV_B32,
DL, MVT::i32,
11739 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE_HI, MVT::i32)),
11748 SDValue Aperture = getSegmentAperture(AS, SL, DAG);
11751 case Intrinsic::amdgcn_perm:
11752 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
Op.getOperand(1),
11753 Op.getOperand(2),
Op.getOperand(3));
11754 case Intrinsic::amdgcn_reloc_constant: {
11764 case Intrinsic::amdgcn_swmmac_f16_16x16x32_f16:
11765 case Intrinsic::amdgcn_swmmac_bf16_16x16x32_bf16:
11766 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf16:
11767 case Intrinsic::amdgcn_swmmac_f32_16x16x32_f16:
11768 case Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_fp8:
11769 case Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_bf8:
11770 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_fp8:
11771 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_bf8: {
11772 if (
Op.getOperand(4).getValueType() == MVT::i32)
11778 Op.getOperand(0),
Op.getOperand(1),
Op.getOperand(2),
11779 Op.getOperand(3), IndexKeyi32);
11781 case Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_fp8:
11782 case Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_bf8:
11783 case Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_fp8:
11784 case Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_bf8:
11785 case Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_fp8:
11786 case Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_bf8:
11787 case Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_fp8:
11788 case Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_bf8: {
11789 if (
Op.getOperand(4).getValueType() == MVT::i64)
11794 Op.getOperand(4).getValueType() == MVT::v2i32
11798 {Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
11799 Op.getOperand(3), IndexKeyi64, Op.getOperand(5),
11800 Op.getOperand(6)});
11802 case Intrinsic::amdgcn_swmmac_f16_16x16x64_f16:
11803 case Intrinsic::amdgcn_swmmac_bf16_16x16x64_bf16:
11804 case Intrinsic::amdgcn_swmmac_f32_16x16x64_bf16:
11805 case Intrinsic::amdgcn_swmmac_bf16f32_16x16x64_bf16:
11806 case Intrinsic::amdgcn_swmmac_f32_16x16x64_f16:
11807 case Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8: {
11808 EVT IndexKeyTy = IntrinsicID == Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8
11811 if (
Op.getOperand(6).getValueType() == IndexKeyTy)
11816 Op.getOperand(6).getValueType().isVector()
11820 Op.getOperand(0),
Op.getOperand(1),
Op.getOperand(2),
11821 Op.getOperand(3),
Op.getOperand(4),
Op.getOperand(5),
11822 IndexKey,
Op.getOperand(7),
Op.getOperand(8)};
11823 if (IntrinsicID == Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8)
11824 Args.push_back(
Op.getOperand(9));
11827 case Intrinsic::amdgcn_swmmac_i32_16x16x32_iu4:
11828 case Intrinsic::amdgcn_swmmac_i32_16x16x32_iu8:
11829 case Intrinsic::amdgcn_swmmac_i32_16x16x64_iu4: {
11830 if (
Op.getOperand(6).getValueType() == MVT::i32)
11836 {Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
11837 Op.getOperand(3), Op.getOperand(4), Op.getOperand(5),
11838 IndexKeyi32, Op.getOperand(7)});
11840 case Intrinsic::amdgcn_wmma_scale_f32_16x16x128_f8f6f4:
11841 case Intrinsic::amdgcn_wmma_scale16_f32_16x16x128_f8f6f4: {
11842 unsigned AFmt = (unsigned)
Op.getConstantOperandVal(1);
11843 unsigned BFmt = (unsigned)
Op.getConstantOperandVal(3);
11844 unsigned AScaleFmt = (unsigned)
Op.getConstantOperandVal(8);
11845 unsigned BScaleFmt = (unsigned)
Op.getConstantOperandVal(11);
11849 "invalid matrix and scale format combination in wmma call");
11855 case Intrinsic::amdgcn_readlane:
11856 case Intrinsic::amdgcn_readfirstlane:
11857 case Intrinsic::amdgcn_writelane:
11858 case Intrinsic::amdgcn_permlane16:
11859 case Intrinsic::amdgcn_permlanex16:
11860 case Intrinsic::amdgcn_permlane64:
11861 case Intrinsic::amdgcn_set_inactive:
11862 case Intrinsic::amdgcn_set_inactive_chain_arg:
11863 case Intrinsic::amdgcn_mov_dpp8:
11864 case Intrinsic::amdgcn_update_dpp:
11865 case Intrinsic::amdgcn_permlane_bcast:
11866 case Intrinsic::amdgcn_permlane_up:
11867 case Intrinsic::amdgcn_permlane_down:
11868 case Intrinsic::amdgcn_permlane_xor:
11870 case Intrinsic::amdgcn_dead: {
11872 for (
const EVT ValTy :
Op.getNode()->values())
11876 case Intrinsic::amdgcn_wave_shuffle:
11879 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
11881 return lowerImage(
Op, ImageDimIntr, DAG,
false);
11892 return DAG.
getRegister(AMDGPU::SGPR_NULL, MVT::i32);
11904 auto GetArg = [&](
unsigned Arg) {
11908 SDValue Rsrc = bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG);
11909 auto [VOffset,
Offset] =
11910 splitBufferOffsets(GetArg(*
Info.getVOffsetArg()), DAG);
11916 Ops.push_back(VData);
11917 if (std::optional<unsigned> CmpArg =
Info.getCmpArg())
11918 Ops.push_back(GetArg(*CmpArg));
11919 Ops.push_back(Rsrc);
11920 std::optional<unsigned> VIndexArg =
Info.getVIndexArg();
11921 Ops.push_back(VIndexArg ? GetArg(*VIndexArg)
11923 Ops.push_back(VOffset);
11924 Ops.push_back(SOffset);
11926 if (std::optional<unsigned> FormatArg =
Info.getFormatArg())
11927 Ops.push_back(GetArg(*FormatArg));
11928 Ops.push_back(GetArg(*
Info.getAuxArg()));
11935 unsigned NewOpcode)
const {
11937 const AMDGPU::BufferIntrinsicInfo &
Info =
11944 "unsupported buffer atomic data type");
11952 M->getMemOperand());
11958SDValue SITargetLowering::lowerBufferIntrinsicWithChain(
11963 auto GetArg = [&](
unsigned Arg) {
11967 switch (
Info.Kind) {
11968 case AMDGPU::BufferKindSLoad: {
11976 return lowerSBuffer(
11977 Op.getValueType(),
M->getMemoryVT(),
DL,
Op.getOperand(0),
11978 bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG),
11979 GetArg(*
Info.getSOffsetArg()), CachePolicy, DAG,
M->getMemOperand());
11981 case AMDGPU::BufferKindLoad:
11982 case AMDGPU::BufferKindAtomicLoad: {
11984 if (!
Info.isTyped())
11985 return lowerIntrinsicLoad(M,
Info.isFormatFromRsrc(), DAG,
Ops);
11987 EVT LoadVT =
Op.getValueType();
11989 return adjustLoadValueType(AMDGPUISD::TBUFFER_LOAD_FORMAT_D16, M, DAG,
11991 return getMemIntrinsicNode(AMDGPUISD::TBUFFER_LOAD_FORMAT,
DL,
11992 Op->getVTList(),
Ops, LoadVT,
M->getMemOperand(),
11995 case AMDGPU::BufferKindAtomicCmpSwap: {
11997 if (Src.getValueSizeInBits() != 32 && Src.getValueSizeInBits() != 64) {
12000 "unsupported buffer atomic data type");
12004 Op->getVTList(),
Ops,
Op.getValueType(),
12005 M->getMemOperand());
12017 int64_t
Offset =
N->getConstantOperandAPInt(4).getSExtValue();
12021 for (
unsigned OpIdx : {2, 3}) {
12022 EVT VT =
Ops[OpIdx].getValueType();
12034 unsigned NumOperands =
N->getNumOperands();
12035 if (
N->getOperand(NumOperands - 1) ==
Zero)
12045static std::optional<uint32_t>
12047 std::optional<uint64_t> BarVal;
12049 BarVal =
C->getZExtValue();
12050 }
else if (BarOp->
isUndef()) {
12069 return *BarVal & 0x3F;
12070 return std::nullopt;
12075 unsigned IntrID =
Op.getConstantOperandVal(1);
12078 if (
const AMDGPU::BufferIntrinsicInfo *BufInfo =
12080 BufInfo && BufInfo->
Kind != AMDGPU::BufferKindAtomicRMW)
12081 return lowerBufferIntrinsicWithChain(
Op, *BufInfo, DAG);
12084 case Intrinsic::amdgcn_cluster_load_b32:
12085 case Intrinsic::amdgcn_cluster_load_b64:
12086 case Intrinsic::amdgcn_cluster_load_b128: {
12087 if (Subtarget->hasGFX1250_STRICT())
12091 case Intrinsic::amdgcn_ds_ordered_add:
12092 case Intrinsic::amdgcn_ds_ordered_swap: {
12097 unsigned IndexOperand =
M->getConstantOperandVal(7);
12098 unsigned WaveRelease =
M->getConstantOperandVal(8);
12099 unsigned WaveDone =
M->getConstantOperandVal(9);
12101 unsigned OrderedCountIndex = IndexOperand & 0x3f;
12102 IndexOperand &= ~0x3f;
12103 unsigned CountDw = 0;
12106 CountDw = (IndexOperand >> 24) & 0xf;
12107 IndexOperand &= ~(0xf << 24);
12109 if (CountDw < 1 || CountDw > 4) {
12112 Fn,
"ds_ordered_count: dword count must be between 1 and 4",
12113 DL.getDebugLoc()));
12118 if (IndexOperand) {
12121 Fn,
"ds_ordered_count: bad index operand",
DL.getDebugLoc()));
12124 if (WaveDone && !WaveRelease) {
12128 Fn,
"ds_ordered_count: wave_done requires wave_release",
12129 DL.getDebugLoc()));
12132 unsigned Instruction = IntrID == Intrinsic::amdgcn_ds_ordered_add ? 0 : 1;
12133 unsigned ShaderType =
12135 unsigned Offset0 = OrderedCountIndex << 2;
12136 unsigned Offset1 = WaveRelease | (WaveDone << 1) | (Instruction << 4);
12139 Offset1 |= (CountDw - 1) << 6;
12142 Offset1 |= ShaderType << 2;
12144 unsigned Offset = Offset0 | (Offset1 << 8);
12151 M->getVTList(),
Ops,
M->getMemoryVT(),
12152 M->getMemOperand());
12154 case Intrinsic::amdgcn_raw_buffer_atomic_fadd:
12155 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fadd:
12156 case Intrinsic::amdgcn_struct_buffer_atomic_fadd:
12157 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fadd:
12158 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_FADD);
12159 case Intrinsic::amdgcn_raw_buffer_atomic_fmin:
12160 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fmin:
12161 case Intrinsic::amdgcn_struct_buffer_atomic_fmin:
12162 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fmin:
12163 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_FMIN);
12164 case Intrinsic::amdgcn_raw_buffer_atomic_fmax:
12165 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fmax:
12166 case Intrinsic::amdgcn_struct_buffer_atomic_fmax:
12167 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fmax:
12168 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_FMAX);
12169 case Intrinsic::amdgcn_raw_buffer_atomic_swap:
12170 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_swap:
12171 case Intrinsic::amdgcn_struct_buffer_atomic_swap:
12172 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_swap:
12173 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SWAP);
12174 case Intrinsic::amdgcn_raw_buffer_atomic_add:
12175 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_add:
12176 case Intrinsic::amdgcn_struct_buffer_atomic_add:
12177 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_add:
12178 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_ADD);
12179 case Intrinsic::amdgcn_raw_buffer_atomic_sub:
12180 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_sub:
12181 case Intrinsic::amdgcn_struct_buffer_atomic_sub:
12182 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_sub:
12183 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SUB);
12184 case Intrinsic::amdgcn_raw_buffer_atomic_smin:
12185 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smin:
12186 case Intrinsic::amdgcn_struct_buffer_atomic_smin:
12187 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smin:
12188 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SMIN);
12189 case Intrinsic::amdgcn_raw_buffer_atomic_umin:
12190 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umin:
12191 case Intrinsic::amdgcn_struct_buffer_atomic_umin:
12192 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umin:
12193 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_UMIN);
12194 case Intrinsic::amdgcn_raw_buffer_atomic_smax:
12195 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smax:
12196 case Intrinsic::amdgcn_struct_buffer_atomic_smax:
12197 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smax:
12198 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SMAX);
12199 case Intrinsic::amdgcn_raw_buffer_atomic_umax:
12200 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umax:
12201 case Intrinsic::amdgcn_struct_buffer_atomic_umax:
12202 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umax:
12203 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_UMAX);
12204 case Intrinsic::amdgcn_raw_buffer_atomic_and:
12205 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_and:
12206 case Intrinsic::amdgcn_struct_buffer_atomic_and:
12207 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_and:
12208 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_AND);
12209 case Intrinsic::amdgcn_raw_buffer_atomic_or:
12210 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_or:
12211 case Intrinsic::amdgcn_struct_buffer_atomic_or:
12212 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_or:
12213 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_OR);
12214 case Intrinsic::amdgcn_raw_buffer_atomic_xor:
12215 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_xor:
12216 case Intrinsic::amdgcn_struct_buffer_atomic_xor:
12217 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_xor:
12218 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_XOR);
12219 case Intrinsic::amdgcn_raw_buffer_atomic_inc:
12220 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_inc:
12221 case Intrinsic::amdgcn_struct_buffer_atomic_inc:
12222 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_inc:
12223 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_INC);
12224 case Intrinsic::amdgcn_raw_buffer_atomic_dec:
12225 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_dec:
12226 case Intrinsic::amdgcn_struct_buffer_atomic_dec:
12227 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_dec:
12228 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_DEC);
12229 case Intrinsic::amdgcn_raw_buffer_atomic_sub_clamp_u32:
12230 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_sub_clamp_u32:
12231 case Intrinsic::amdgcn_struct_buffer_atomic_sub_clamp_u32:
12232 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_sub_clamp_u32:
12233 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_CSUB);
12234 case Intrinsic::amdgcn_raw_buffer_atomic_cond_sub_u32:
12235 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_cond_sub_u32:
12236 case Intrinsic::amdgcn_struct_buffer_atomic_cond_sub_u32:
12237 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_cond_sub_u32:
12238 return lowerBufferAtomicIntrin(
Op, DAG,
12239 AMDGPUISD::BUFFER_ATOMIC_COND_SUB_U32);
12240 case Intrinsic::amdgcn_image_bvh_dual_intersect_ray:
12241 case Intrinsic::amdgcn_image_bvh8_intersect_ray: {
12243 SDValue NodePtr =
M->getOperand(2);
12244 SDValue RayExtent =
M->getOperand(3);
12245 SDValue InstanceMask =
M->getOperand(4);
12246 SDValue RayOrigin =
M->getOperand(5);
12247 SDValue RayDir =
M->getOperand(6);
12249 SDValue TDescr =
M->getOperand(8);
12254 bool IsBVH8 = IntrID == Intrinsic::amdgcn_image_bvh8_intersect_ray;
12255 const unsigned NumVDataDwords = 10;
12256 const unsigned NumVAddrDwords = IsBVH8 ? 11 : 12;
12258 IsBVH8 ? AMDGPU::IMAGE_BVH8_INTERSECT_RAY
12259 : AMDGPU::IMAGE_BVH_DUAL_INTERSECT_RAY,
12260 AMDGPU::MIMGEncGfx12, NumVDataDwords, NumVAddrDwords);
12264 Ops.push_back(NodePtr);
12267 {DAG.getBitcast(MVT::i32, RayExtent),
12268 DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, InstanceMask)}));
12269 Ops.push_back(RayOrigin);
12270 Ops.push_back(RayDir);
12271 Ops.push_back(Offsets);
12272 Ops.push_back(TDescr);
12273 Ops.push_back(
M->getChain());
12276 MachineMemOperand *MemRef =
M->getMemOperand();
12280 case Intrinsic::amdgcn_image_bvh_intersect_ray: {
12282 SDValue NodePtr =
M->getOperand(2);
12283 SDValue RayExtent =
M->getOperand(3);
12284 SDValue RayOrigin =
M->getOperand(4);
12285 SDValue RayDir =
M->getOperand(5);
12286 SDValue RayInvDir =
M->getOperand(6);
12287 SDValue TDescr =
M->getOperand(7);
12299 const unsigned NumVDataDwords = 4;
12300 const unsigned NumVAddrDwords = IsA16 ? (Is64 ? 9 : 8) : (Is64 ? 12 : 11);
12301 const unsigned NumVAddrs = IsGFX11Plus ? (IsA16 ? 4 : 5) : NumVAddrDwords;
12302 const bool UseNSA = (Subtarget->hasNSAEncoding() &&
12305 const unsigned BaseOpcodes[2][2] = {
12306 {AMDGPU::IMAGE_BVH_INTERSECT_RAY, AMDGPU::IMAGE_BVH_INTERSECT_RAY_a16},
12307 {AMDGPU::IMAGE_BVH64_INTERSECT_RAY,
12308 AMDGPU::IMAGE_BVH64_INTERSECT_RAY_a16}};
12312 IsGFX12Plus ? AMDGPU::MIMGEncGfx12
12313 : IsGFX11 ? AMDGPU::MIMGEncGfx11NSA
12314 : AMDGPU::MIMGEncGfx10NSA,
12315 NumVDataDwords, NumVAddrDwords);
12319 IsGFX11 ? AMDGPU::MIMGEncGfx11Default
12320 : AMDGPU::MIMGEncGfx10Default,
12321 NumVDataDwords, NumVAddrDwords);
12327 auto packLanes = [&DAG, &
Ops, &
DL](
SDValue Op,
bool IsAligned) {
12330 if (Lanes[0].getValueSizeInBits() == 32) {
12331 for (
unsigned I = 0;
I < 3; ++
I)
12338 Ops.push_back(Lanes[2]);
12350 if (UseNSA && IsGFX11Plus) {
12351 Ops.push_back(NodePtr);
12353 Ops.push_back(RayOrigin);
12358 for (
unsigned I = 0;
I < 3; ++
I) {
12361 {DirLanes[I], InvDirLanes[I]})));
12365 Ops.push_back(RayDir);
12366 Ops.push_back(RayInvDir);
12373 Ops.push_back(NodePtr);
12376 packLanes(RayOrigin,
true);
12377 packLanes(RayDir,
true);
12378 packLanes(RayInvDir,
false);
12383 if (NumVAddrDwords > 12) {
12391 Ops.push_back(MergedOps);
12394 Ops.push_back(TDescr);
12396 Ops.push_back(
M->getChain());
12399 MachineMemOperand *MemRef =
M->getMemOperand();
12403 case Intrinsic::amdgcn_global_atomic_fmin_num:
12404 case Intrinsic::amdgcn_global_atomic_fmax_num:
12405 case Intrinsic::amdgcn_flat_atomic_fmin_num:
12406 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
12413 unsigned Opcode = 0;
12415 case Intrinsic::amdgcn_global_atomic_fmin_num:
12416 case Intrinsic::amdgcn_flat_atomic_fmin_num: {
12420 case Intrinsic::amdgcn_global_atomic_fmax_num:
12421 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
12428 return DAG.
getAtomic(Opcode, SDLoc(
Op),
M->getMemoryVT(),
M->getVTList(),
12429 Ops,
M->getMemOperand());
12431 case Intrinsic::amdgcn_s_alloc_vgpr: {
12439 ReadFirstLaneID, NumVGPRs);
12442 Op.getOperand(0),
Op.getOperand(1), NumVGPRs);
12444 case Intrinsic::amdgcn_s_get_barrier_state:
12445 case Intrinsic::amdgcn_s_get_named_barrier_state: {
12450 std::optional<uint32_t> BarID;
12451 if (IntrID == Intrinsic::amdgcn_s_get_named_barrier_state)
12454 BarID =
C->getZExtValue();
12457 Opc = AMDGPU::S_GET_BARRIER_STATE_IMM;
12460 Ops.push_back(Chain);
12462 Opc = AMDGPU::S_GET_BARRIER_STATE_M0;
12463 if (IntrID == Intrinsic::amdgcn_s_get_named_barrier_state) {
12474 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
12475 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
12476 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B: {
12480 EVT VT =
Op->getValueType(0);
12484 case Intrinsic::amdgcn_av_load_b8:
12485 case Intrinsic::amdgcn_av_load_b16:
12486 case Intrinsic::amdgcn_av_load_b32:
12487 case Intrinsic::amdgcn_av_load_b64:
12488 case Intrinsic::amdgcn_av_load_b128: {
12492 EVT VT =
Op->getValueType(0);
12499 case Intrinsic::amdgcn_flat_load_monitor_b32:
12500 case Intrinsic::amdgcn_flat_load_monitor_b64:
12501 case Intrinsic::amdgcn_flat_load_monitor_b128: {
12506 Op->getVTList(), {Chain, Ptr},
12509 case Intrinsic::amdgcn_global_load_monitor_b32:
12510 case Intrinsic::amdgcn_global_load_monitor_b64:
12511 case Intrinsic::amdgcn_global_load_monitor_b128: {
12516 Op->getVTList(), {Chain, Ptr},
12521 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
12523 return lowerImage(
Op, ImageDimIntr, DAG,
true);
12531SDValue SITargetLowering::getMemIntrinsicNode(
unsigned Opcode,
const SDLoc &
DL,
12538 EVT VT = VTList.
VTs[0];
12541 bool IsTFE = VTList.
NumVTs == 3;
12544 unsigned NumOpDWords = NumValueDWords + 1;
12546 SDVTList OpDWordsVTList = DAG.
getVTList(OpDWordsVT, VTList.
VTs[2]);
12547 MachineMemOperand *OpDWordsMMO =
12549 SDValue Op = getMemIntrinsicNode(Opcode,
DL, OpDWordsVTList,
Ops,
12550 OpDWordsVT, OpDWordsMMO, DAG);
12555 if (!Subtarget->hasDwordx3LoadStores() &&
12556 (VT == MVT::v3i32 || VT == MVT::v3f32)) {
12560 SDVTList WidenedVTList = DAG.
getVTList(WidenedVT, VTList.
VTs[1]);
12562 WidenedMemVT, WidenedMMO);
12572 bool ImageStore)
const {
12582 if (Subtarget->hasUnpackedD16VMem()) {
12596 if (ImageStore && Subtarget->hasImageStoreD16Bug()) {
12607 for (
unsigned I = 0;
I < Elts.
size() / 2;
I += 1) {
12613 if ((NumElements % 2) == 1) {
12615 unsigned I = Elts.
size() / 2;
12631 if (NumElements == 3) {
12651 return BufInfo->IsAsync;
12653 case Intrinsic::amdgcn_load_async_to_lds:
12654 case Intrinsic::amdgcn_global_load_async_lds:
12662SDValue SITargetLowering::lowerBufferIntrinsicVoid(
12668 auto GetArg = [&](
unsigned Arg) {
12672 switch (
Info.Kind) {
12673 case AMDGPU::BufferKindStore: {
12678 if (
Info.isTyped()) {
12681 VData = handleD16VData(VData, DAG);
12683 getBufferIntrinsicOps(
Op, Info, DAG, VData);
12684 unsigned Opc = IsD16 ? AMDGPUISD::TBUFFER_STORE_FORMAT_D16
12685 : AMDGPUISD::TBUFFER_STORE_FORMAT;
12687 M->getMemoryVT(),
M->getMemOperand());
12690 bool IsFormat =
Info.isFormatFromRsrc();
12696 "unsupported sub-dword format buffer store",
DL.getDebugLoc()));
12701 VData = handleD16VData(VData, DAG);
12713 IsFormat ? AMDGPUISD::BUFFER_STORE_FORMAT : AMDGPUISD::BUFFER_STORE;
12714 Opc = IsD16 ? AMDGPUISD::BUFFER_STORE_FORMAT_D16 :
Opc;
12718 return handleByteShortBufferStores(DAG, VDataVT,
DL,
Ops.data(), M);
12721 M->getMemoryVT(),
M->getMemOperand());
12723 case AMDGPU::BufferKindLoadToLDS: {
12725 std::optional<unsigned> VIndexArg =
Info.getVIndexArg();
12726 bool HasVIndex = VIndexArg.has_value();
12729 unsigned Size = GetArg(*
Info.getSizeArg())->getAsZExtVal();
12735 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_UBYTE_LDS_BOTHEN
12736 : AMDGPU::BUFFER_LOAD_UBYTE_LDS_IDXEN
12737 : HasVOffset ? AMDGPU::BUFFER_LOAD_UBYTE_LDS_OFFEN
12738 : AMDGPU::BUFFER_LOAD_UBYTE_LDS_OFFSET;
12741 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_USHORT_LDS_BOTHEN
12742 : AMDGPU::BUFFER_LOAD_USHORT_LDS_IDXEN
12743 : HasVOffset ? AMDGPU::BUFFER_LOAD_USHORT_LDS_OFFEN
12744 : AMDGPU::BUFFER_LOAD_USHORT_LDS_OFFSET;
12747 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORD_LDS_BOTHEN
12748 : AMDGPU::BUFFER_LOAD_DWORD_LDS_IDXEN
12749 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORD_LDS_OFFEN
12750 : AMDGPU::BUFFER_LOAD_DWORD_LDS_OFFSET;
12753 if (!Subtarget->hasLDSLoadB96_B128())
12755 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX3_LDS_BOTHEN
12756 : AMDGPU::BUFFER_LOAD_DWORDX3_LDS_IDXEN
12757 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX3_LDS_OFFEN
12758 : AMDGPU::BUFFER_LOAD_DWORDX3_LDS_OFFSET;
12761 if (!Subtarget->hasLDSLoadB96_B128())
12763 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX4_LDS_BOTHEN
12764 : AMDGPU::BUFFER_LOAD_DWORDX4_LDS_IDXEN
12765 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX4_LDS_OFFEN
12766 : AMDGPU::BUFFER_LOAD_DWORDX4_LDS_OFFSET;
12774 if (HasVIndex && HasVOffset)
12777 else if (HasVIndex)
12778 Ops.push_back(GetArg(*VIndexArg));
12779 else if (HasVOffset)
12780 Ops.push_back(VOffset);
12782 SDValue Rsrc = bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG);
12783 Ops.push_back(Rsrc);
12784 Ops.push_back(GetArg(*
Info.getSOffsetArg()));
12785 Ops.push_back(GetArg(*
Info.getImmOffsetArg()));
12787 unsigned Aux = GetArg(*
Info.getAuxArg())->getAsZExtVal();
12805 case AMDGPU::BufferKindPrefetch: {
12808 bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG),
12809 GetArg(*
Info.getSOffsetArg()),
12810 GetArg(*
Info.getSizeArg()),
12814 Op->getVTList(),
Ops,
M->getMemoryVT(),
12815 M->getMemOperand());
12826 unsigned IntrinsicID =
Op.getConstantOperandVal(1);
12828 if (
const AMDGPU::BufferIntrinsicInfo *BufInfo =
12830 return lowerBufferIntrinsicVoid(
Op, *BufInfo, DAG);
12832 switch (IntrinsicID) {
12833 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
12834 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
12835 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
12836 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128: {
12838 if (Subtarget->hasGFX1250_STRICT())
12842 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
12843 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
12844 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
12845 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
12846 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
12847 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
12848 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
12849 case Intrinsic::amdgcn_global_store_async_from_lds_b128:
12852 case Intrinsic::amdgcn_exp_compr: {
12873 unsigned Opc =
Done->isZero() ? AMDGPU::EXP : AMDGPU::EXP_DONE;
12880 case Intrinsic::amdgcn_load_to_lds:
12881 case Intrinsic::amdgcn_load_async_to_lds:
12882 case Intrinsic::amdgcn_global_load_lds:
12883 case Intrinsic::amdgcn_global_load_async_lds: {
12884 if (!Subtarget->hasVMemToLDSLoad())
12888 unsigned Size =
Op->getConstantOperandVal(4);
12893 Opc = AMDGPU::GLOBAL_LOAD_LDS_UBYTE;
12896 Opc = AMDGPU::GLOBAL_LOAD_LDS_USHORT;
12899 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORD;
12902 if (!Subtarget->hasLDSLoadB96_B128())
12904 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORDX3;
12907 if (!Subtarget->hasLDSLoadB96_B128())
12909 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORDX4;
12925 if (
LHS->isDivergent())
12929 RHS.getOperand(0).getValueType() == MVT::i32) {
12932 VOffset =
RHS.getOperand(0);
12936 Ops.push_back(Addr);
12944 Ops.push_back(VOffset);
12947 Ops.push_back(
Op.getOperand(5));
12949 unsigned Aux =
Op.getConstantOperandVal(6);
12964 case Intrinsic::amdgcn_end_cf:
12966 Op->getOperand(2), Chain),
12968 case Intrinsic::amdgcn_s_barrier_signal_var: {
12975 if (CntC && CntC->isZero()) {
12980 std::array<SDValue, 2>
Ops = {
12983 Op->getVTList(),
Ops);
12989 case Intrinsic::amdgcn_s_barrier_init: {
12996 unsigned Opc = IntrinsicID == Intrinsic::amdgcn_s_barrier_init
12997 ? AMDGPU::S_BARRIER_INIT_M0
12998 : AMDGPU::S_BARRIER_SIGNAL_M0;
13008 constexpr unsigned ShAmt = 16;
13019 case Intrinsic::amdgcn_s_wakeup_barrier: {
13020 if (!Subtarget->hasSWakeupBarrier())
13024 case Intrinsic::amdgcn_s_barrier_join: {
13032 switch (IntrinsicID) {
13035 case Intrinsic::amdgcn_s_barrier_join:
13036 Opc = AMDGPU::S_BARRIER_JOIN_IMM;
13038 case Intrinsic::amdgcn_s_wakeup_barrier:
13039 Opc = AMDGPU::S_WAKEUP_BARRIER_IMM;
13044 Ops.push_back(Chain);
13046 switch (IntrinsicID) {
13049 case Intrinsic::amdgcn_s_barrier_join:
13050 Opc = AMDGPU::S_BARRIER_JOIN_M0;
13052 case Intrinsic::amdgcn_s_wakeup_barrier:
13053 Opc = AMDGPU::S_WAKEUP_BARRIER_M0;
13065 case Intrinsic::amdgcn_s_prefetch_data:
13066 case Intrinsic::amdgcn_s_prefetch_inst: {
13069 return Op.getOperand(0);
13072 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
13073 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
13074 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
13082 case Intrinsic::amdgcn_av_store_b8:
13083 case Intrinsic::amdgcn_av_store_b16:
13084 case Intrinsic::amdgcn_av_store_b32:
13085 case Intrinsic::amdgcn_av_store_b64:
13086 case Intrinsic::amdgcn_av_store_b128: {
13094 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
13096 return lowerImage(
Op, ImageDimIntr, DAG,
true);
13112 return PtrVT == MVT::i64;
13126std::pair<SDValue, SDValue>
13139 bool CheckNUW =
Subtarget->hasGFX1250Insts();
13147 unsigned ImmOffset =
C1->getZExtValue();
13156 unsigned Overflow = ImmOffset & ~MaxImm;
13157 ImmOffset -= Overflow;
13158 if ((int32_t)Overflow < 0) {
13159 Overflow += ImmOffset;
13164 auto OverflowVal = DAG.
getConstant(Overflow,
DL, MVT::i32);
13183void SITargetLowering::setBufferOffsets(
SDValue CombinedOffset,
13185 Align Alignment)
const {
13187 SDLoc
DL(CombinedOffset);
13189 uint32_t
Imm =
C->getZExtValue();
13190 uint32_t SOffset, ImmOffset;
13191 if (
TII->splitMUBUFOffset(
Imm, SOffset, ImmOffset, Alignment)) {
13202 bool CheckNUW = Subtarget->hasGFX1250Insts();
13205 uint32_t SOffset, ImmOffset;
13208 TII->splitMUBUFOffset(
Offset, SOffset, ImmOffset, Alignment)) {
13216 SDValue SOffsetZero = Subtarget->hasRestrictedSOffset()
13225SDValue SITargetLowering::bufferRsrcPtrToVector(
SDValue MaybePointer,
13228 return MaybePointer;
13242 SDValue NumRecords =
Op->getOperand(3);
13248 if (Subtarget->getBufferResourceNumRecordsWidth() == 45) {
13251 DAG.
getConstant((1ULL << 45) - 1, Loc, MVT::i64));
13270 SDValue ExtShiftedStrideVec =
13282 DAG.
getNode(
ISD::OR, Loc, MVT::i64, NumRecordsRHS, ExtShiftedStride);
13284 DAG.
getNode(
ISD::OR, Loc, MVT::i64, CombinedFields, ExtShiftedFlags);
13289 auto [LowHalf, HighHalf] =
13290 DAG.
SplitScalar(Pointer, Loc, MVT::i32, MVT::i32);
13300 NumRecords, Flags);
13312 bool IsTFE)
const {
13317 ? AMDGPUISD::BUFFER_LOAD_UBYTE_TFE
13318 : AMDGPUISD::BUFFER_LOAD_USHORT_TFE;
13321 SDVTList VTs = DAG.
getVTList(MVT::v2i32, MVT::Other);
13333 ? AMDGPUISD::BUFFER_LOAD_UBYTE
13334 : AMDGPUISD::BUFFER_LOAD_USHORT;
13336 SDVTList ResList = DAG.
getVTList(MVT::i32, MVT::Other);
13350 if (VDataType == MVT::f16 || VDataType == MVT::bf16)
13354 Ops[1] = BufferStoreExt;
13355 unsigned Opc = (VDataType == MVT::i8) ? AMDGPUISD::BUFFER_STORE_BYTE
13356 : AMDGPUISD::BUFFER_STORE_SHORT;
13359 M->getMemOperand());
13384 DAGCombinerInfo &DCI)
const {
13385 SelectionDAG &DAG = DCI.DAG;
13386 if (Ld->getAlign() <
Align(4) || Ld->isDivergent())
13390 unsigned AS = Ld->getAddressSpace();
13399 EVT MemVT = Ld->getMemoryVT();
13400 if ((MemVT.
isSimple() && !DCI.isAfterLegalizeDAG()) ||
13407 "unexpected vector extload");
13410 SDValue Ptr = Ld->getBasePtr();
13413 Ld->getOffset(), Ld->getPointerInfo(), MVT::i32, Ld->getAlign(),
13414 Ld->getMemOperand()->getFlags(), Ld->getAAInfo());
13419 "unexpected fp extload");
13434 EVT VT = Ld->getValueType(0);
13437 DCI.AddToWorklist(Cvt.
getNode());
13442 DCI.AddToWorklist(Cvt.
getNode());
13453 if (Info.isEntryFunction())
13454 return Info.getUserSGPRInfo().hasFlatScratchInit();
13464 EVT MemVT = MemOp->getMemoryVT();
13472 "unsupported access of VGPR 'as memory' address space (13); only "
13473 "dword-aligned whole-dword loads and stores are implemented",
13474 DL.getDebugLoc()));
13484 if (MemOp->getAlign() <
Align(4))
13492 if (!Subtarget->getRegisterInfo()->getVGPRClassForBitWidth(
BitWidth) ||
13498 if (MemVT == ViewVT)
13502 Store->getBasePtr(),
Store->getMemOperand());
13507 Load->getMemOperand()->clearRanges();
13509 Load->getBasePtr(),
Load->getMemOperand());
13512 Load->getValueType(0));
13516 SDValue Chain = MemOp->getChain();
13523 unsigned NumDwords =
BitWidth / 32;
13524 RegVT = NumDwords == 1
13526 : EVT::getVectorVT(*DAG.
getContext(), MVT::i32, NumDwords);
13532 AMDGPUISD::REG_STORE,
DL, DAG.
getVTList(MVT::Other),
13533 {Chain, Value, Index}, MemVT,
Store->getMemOperand());
13537 AMDGPUISD::REG_LOAD,
DL, DAG.
getVTList(RegVT, MVT::Other), {Chain, Index},
13538 MemVT,
Load->getMemOperand());
13542 Load->getValueType(0));
13543 if (
Value == NewLoad)
13552 "Unexpected custom extending load!");
13553 EVT MemVT =
Load->getMemoryVT();
13554 MachineMemOperand *MMO =
Load->getMemOperand();
13561 isTypeLegal(MemVT) && Subtarget->hasScalarSubwordLoads() &&
13568 BasePtr, MVT::i16, MMO);
13591 EVT RealMemVT = (MemVT == MVT::i1) ? MVT::i8 : MVT::i16;
13617 Op.getValueType().getVectorElementType() == MVT::i32 &&
13618 "Custom lowering for non-i32 vectors hasn't been implemented.");
13621 unsigned AS =
Load->getAddressSpace();
13622 if (Subtarget->hasLDSMisalignedBugInWGPMode() &&
13629 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
13633 !Subtarget->hasMultiDwordFlatScratchAddressing())
13645 Alignment >=
Align(4) && NumElements < 32) {
13647 (Subtarget->hasScalarDwordx3Loads() && NumElements == 3))
13659 if (NumElements > 4)
13662 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
13672 switch (Subtarget->getMaxPrivateElementSize()) {
13678 if (NumElements > 2)
13683 if (NumElements > 4)
13686 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
13695 auto Flags =
Load->getMemOperand()->getFlags();
13697 Load->getAlign(), Flags, &
Fast) &&
13705 MemVT, *
Load->getMemOperand())) {
13714 EVT VT =
Op.getValueType();
13751 EVT VT =
Op.getValueType();
13752 const SDNodeFlags
Flags =
Op->getFlags();
13754 bool AllowInaccurateRcp =
Flags.hasApproximateFuncs();
13760 if (!AllowInaccurateRcp && VT != MVT::f16 && VT != MVT::bf16)
13763 if (CLHS->isOne()) {
13776 return DAG.
getNode(AMDGPUISD::RCP, SL, VT,
RHS);
13780 if (CLHS->isMinusOne()) {
13789 if (!AllowInaccurateRcp &&
13790 ((VT != MVT::f16 && VT != MVT::bf16) || !
Flags.hasAllowReciprocal()))
13804 EVT VT =
Op.getValueType();
13805 const SDNodeFlags
Flags =
Op->getFlags();
13807 bool AllowInaccurateDiv =
Flags.hasApproximateFuncs();
13808 if (!AllowInaccurateDiv)
13832 if (IsNegRcp || (CLHS && CLHS->
isOne()))
13844 return DAG.
getNode(Opcode, SL, VT,
A,
B, Flags);
13854 Opcode = AMDGPUISD::FMUL_W_CHAIN;
13858 return DAG.
getNode(Opcode, SL, VTList,
13867 return DAG.
getNode(Opcode, SL, VT, {
A,
B,
C}, Flags);
13877 Opcode = AMDGPUISD::FMA_W_CHAIN;
13881 return DAG.
getNode(Opcode, SL, VTList,
13887 if (
SDValue FastLowered = lowerFastUnsafeFDIV(
Op, DAG))
13888 return FastLowered;
13891 EVT VT =
Op.getValueType();
13898 if (VT == MVT::bf16) {
13921 unsigned FMADOpCode =
13925 DAG.
getNode(AMDGPUISD::RCP, SL, MVT::f32, RHSExt,
Op->getFlags());
13928 SDValue Err = DAG.
getNode(FMADOpCode, SL, MVT::f32, NegRHSExt, Quot, LHSExt,
13930 Quot = DAG.
getNode(FMADOpCode, SL, MVT::f32, Err, Rcp, Quot,
Op->getFlags());
13931 Err = DAG.
getNode(FMADOpCode, SL, MVT::f32, NegRHSExt, Quot, LHSExt,
13941 return DAG.
getNode(AMDGPUISD::DIV_FIXUP, SL, MVT::f16, RDst,
RHS,
LHS,
13947 SDNodeFlags
Flags =
Op->getFlags();
13957 const APFloat K0Val(0x1p+96f);
13960 const APFloat K1Val(0x1p-32f);
13987 assert(ST->hasDenormModeInst() &&
"Requires S_DENORM_MODE");
13988 uint32_t DPDenormModeDefault = Info->getMode().fpDenormModeDPValue();
13989 uint32_t Mode = SPDenormMode | (DPDenormModeDefault << 2);
13994 if (
SDValue FastLowered = lowerFastUnsafeFDIV(
Op, DAG))
13995 return FastLowered;
14001 SDNodeFlags
Flags =
Op->getFlags();
14002 Flags.setNoFPExcept(
true);
14010 SDVTList ScaleVT = DAG.
getVTList(MVT::f32, MVT::i1);
14019 DAG.
getNode(AMDGPUISD::RCP, SL, MVT::f32, DenominatorScaled, Flags);
14023 using namespace AMDGPU::Hwreg;
14024 const unsigned Denorm32Reg = HwregEncoding::encode(ID_MODE, 4, 2);
14028 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
14029 const DenormalMode DenormMode =
Info->getMode().FP32Denormals;
14032 const bool HasDynamicDenormals =
14038 if (!PreservesDenormals) {
14043 SDVTList BindParamVTs = DAG.
getVTList(MVT::Other, MVT::Glue);
14046 if (HasDynamicDenormals) {
14050 SavedDenormMode =
SDValue(GetReg, 0);
14056 SDNode *EnableDenorm;
14057 if (Subtarget->hasDenormModeInst()) {
14058 const SDValue EnableDenormValue =
14061 EnableDenorm = DAG.
getNode(AMDGPUISD::DENORM_MODE, SL, BindParamVTs, Glue,
14065 const SDValue EnableDenormValue =
14067 EnableDenorm = DAG.
getMachineNode(AMDGPU::S_SETREG_B32, SL, BindParamVTs,
14068 {EnableDenormValue,
BitField, Glue});
14078 ApproxRcp, One, NegDivScale0, Flags);
14081 ApproxRcp, Fma0, Flags);
14087 NumeratorScaled,
Mul, Flags);
14093 NumeratorScaled, Fma3, Flags);
14095 if (!PreservesDenormals) {
14096 SDNode *DisableDenorm;
14097 if (!HasDynamicDenormals && Subtarget->hasDenormModeInst()) {
14101 SDVTList BindParamVTs = DAG.
getVTList(MVT::Other, MVT::Glue);
14103 DAG.
getNode(AMDGPUISD::DENORM_MODE, SL, BindParamVTs,
14107 assert(HasDynamicDenormals == (
bool)SavedDenormMode);
14108 const SDValue DisableDenormValue =
14109 HasDynamicDenormals
14114 AMDGPU::S_SETREG_B32, SL, MVT::Other,
14125 {Fma4, Fma1, Fma3, Scale},
Flags);
14127 return DAG.
getNode(AMDGPUISD::DIV_FIXUP, SL, MVT::f32, Fmas,
RHS,
LHS, Flags);
14131 if (
SDValue FastLowered = lowerFastUnsafeFDIV64(
Op, DAG))
14132 return FastLowered;
14140 SDVTList ScaleVT = DAG.
getVTList(MVT::f64, MVT::i1);
14146 SDValue Rcp = DAG.
getNode(AMDGPUISD::RCP, SL, MVT::f64, DivScale0);
14164 if (!Subtarget->hasUsableDivScaleConditionOutput()) {
14194 DAG.
getNode(AMDGPUISD::DIV_FMAS, SL, MVT::f64, Fma4, Fma3,
Mul, Scale);
14196 return DAG.
getNode(AMDGPUISD::DIV_FIXUP, SL, MVT::f64, Fmas,
Y,
X);
14200 EVT VT =
Op.getValueType();
14202 if (VT == MVT::f32)
14203 return LowerFDIV32(
Op, DAG);
14205 if (VT == MVT::f64)
14206 return LowerFDIV64(
Op, DAG);
14208 if (VT == MVT::f16 || VT == MVT::bf16)
14209 return LowerFDIV16(
Op, DAG);
14218 EVT ResultExpVT =
Op->getValueType(1);
14219 EVT InstrExpVT = VT == MVT::f16 ? MVT::i16 : MVT::i32;
14229 if (Subtarget->hasFractBug()) {
14247 assert(!
Store->isTruncatingStore() &&
"Unexpected custom truncating store!");
14248 EVT VT =
Store->getMemoryVT();
14250 if (VT == MVT::i1) {
14254 Store->getBasePtr(), MVT::i1,
Store->getMemOperand());
14258 Store->getValue().getValueType().getScalarType() == MVT::i32);
14260 unsigned AS =
Store->getAddressSpace();
14261 if (Subtarget->hasLDSMisalignedBugInWGPMode() &&
14269 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
14273 !Subtarget->hasMultiDwordFlatScratchAddressing())
14280 if (NumElements > 4)
14283 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
14287 VT, *
Store->getMemOperand()))
14293 switch (Subtarget->getMaxPrivateElementSize()) {
14297 if (NumElements > 2)
14301 if (NumElements > 4 ||
14302 (NumElements == 3 && !Subtarget->hasFlatScratchEnabled()))
14310 auto Flags =
Store->getMemOperand()->getFlags();
14326 assert(!Subtarget->has16BitInsts());
14327 SDNodeFlags
Flags =
Op->getFlags();
14341 SDNodeFlags
Flags =
Op->getFlags();
14342 MVT VT =
Op.getValueType().getSimpleVT();
14450 SDNodeFlags
Flags =
Op->getFlags();
14459 if (!
Flags.hasApproximateFuncs()) {
14491 if (!
Flags.hasApproximateFuncs()) {
14500 ScaleDownFactor, ZeroInt);
14507 if (
Flags.hasNoInfs()) {
14523 EVT VT =
Op.getValueType();
14534 if (!
V.getValueType().isVector())
14542 if (Subtarget->hasTrigReducedRange()) {
14544 TrigVal = UnrollIfVec(DAG.
getNode(AMDGPUISD::FRACT,
DL, VT, MulVal, Flags));
14549 switch (
Op.getOpcode()) {
14551 TrigVal = DAG.
getNode(AMDGPUISD::COS_HW, SDLoc(
Op), VT, TrigVal, Flags);
14554 TrigVal = DAG.
getNode(AMDGPUISD::SIN_HW, SDLoc(
Op), VT, TrigVal, Flags);
14560 return UnrollIfVec(TrigVal);
14580 EVT VT =
Op.getValueType();
14588 Op->getVTList(),
Ops, VT,
14597SITargetLowering::performUCharToFloatCombine(
SDNode *
N,
14598 DAGCombinerInfo &DCI)
const {
14599 EVT VT =
N->getValueType(0);
14601 if (ScalarVT != MVT::f32 && ScalarVT != MVT::f16)
14604 SelectionDAG &DAG = DCI.DAG;
14608 EVT SrcVT = Src.getValueType();
14614 if (DCI.isAfterLegalizeDAG() && SrcVT == MVT::i32) {
14617 DCI.AddToWorklist(Cvt.
getNode());
14620 if (ScalarVT != MVT::f32) {
14632 DAGCombinerInfo &DCI)
const {
14643 SelectionDAG &DAG = DCI.DAG;
14662 for (
unsigned I = 0;
I != NumElts; ++
I) {
14686 if (NewElts.
size() == 1)
14708 for (
unsigned I = 0;
I != NumElts; ++
I) {
14743SDValue SITargetLowering::performSHLPtrCombine(
SDNode *
N,
unsigned AddrSpace,
14745 DAGCombinerInfo &DCI)
const {
14762 SelectionDAG &DAG = DCI.DAG;
14775 AM.BaseOffs =
Offset.getSExtValue();
14780 EVT VT =
N->getValueType(0);
14786 Flags.setNoUnsignedWrap(
14787 N->getFlags().hasNoUnsignedWrap() &&
14799 switch (
N->getOpcode()) {
14810 DAGCombinerInfo &DCI)
const {
14811 SelectionDAG &DAG = DCI.DAG;
14818 SDValue NewPtr = performSHLPtrCombine(Ptr.
getNode(),
N->getAddressSpace(),
14819 N->getMemoryVT(), DCI);
14823 NewOps[PtrIdx] = NewPtr;
14832 return (
Opc ==
ISD::AND && (Val == 0 || Val == 0xffffffff)) ||
14833 (
Opc ==
ISD::OR && (Val == 0xffffffff || Val == 0)) ||
14842SDValue SITargetLowering::splitBinaryBitConstantOp(
14846 uint32_t ValLo =
Lo_32(Val);
14847 uint32_t ValHi =
Hi_32(Val);
14854 if (Subtarget->has64BitLiterals() && CRHS->
hasOneUse() &&
14868 if (V.getValueType() != MVT::i1)
14870 switch (V.getOpcode()) {
14875 case AMDGPUISD::FP_CLASS:
14887 return V.getResNo() == 1;
14889 unsigned IntrinsicID = V.getConstantOperandVal(0);
14890 switch (IntrinsicID) {
14891 case Intrinsic::amdgcn_is_shared:
14892 case Intrinsic::amdgcn_is_private:
14915 if (!(
C & 0x000000ff))
14916 ZeroByteMask |= 0x000000ff;
14917 if (!(
C & 0x0000ff00))
14918 ZeroByteMask |= 0x0000ff00;
14919 if (!(
C & 0x00ff0000))
14920 ZeroByteMask |= 0x00ff0000;
14921 if (!(
C & 0xff000000))
14922 ZeroByteMask |= 0xff000000;
14923 uint32_t NonZeroByteMask = ~ZeroByteMask;
14924 if ((NonZeroByteMask &
C) != NonZeroByteMask)
14937 assert(
V.getValueSizeInBits() == 32);
14939 if (
V.getNumOperands() != 2)
14948 switch (
V.getOpcode()) {
14953 return (0x03020100 & ConstMask) | (0x0c0c0c0c & ~ConstMask);
14958 return (0x03020100 & ~ConstMask) | ConstMask;
14965 return uint32_t((0x030201000c0c0c0cull <<
C) >> 32);
14971 return uint32_t(0x0c0c0c0c03020100ull >>
C);
14978 DAGCombinerInfo &DCI)
const {
14979 if (DCI.isBeforeLegalize())
14982 SelectionDAG &DAG = DCI.DAG;
14983 EVT VT =
N->getValueType(0);
14988 if (VT == MVT::i64 && CRHS) {
14990 splitBinaryBitConstantOp(DCI, SDLoc(
N),
ISD::AND,
LHS, CRHS))
14994 if (CRHS && VT == MVT::i32) {
15004 unsigned Shift = CShift->getZExtValue();
15006 unsigned Offset = NB + Shift;
15007 if ((
Offset & (Bits - 1)) == 0) {
15010 DAG.
getNode(AMDGPUISD::BFE_U32, SL, MVT::i32,
LHS->getOperand(0),
15031 Sel = (
LHS.getConstantOperandVal(2) & Sel) | (~Sel & 0x0c0c0c0c);
15033 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15043 if (Shift && Shift->getZExtValue() < 16 &&
15062 if (
Y.getOpcode() !=
ISD::FABS ||
Y.getOperand(0) !=
X ||
15067 if (
X !=
LHS.getOperand(1))
15071 const ConstantFPSDNode *
C1 =
15073 if (!
C1 || !
C1->isInfinity() ||
C1->isNegative())
15088 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, MVT::i1,
X,
15094 if (
RHS.getOpcode() ==
ISD::SETCC &&
LHS.getOpcode() == AMDGPUISD::FP_CLASS)
15097 if (
LHS.getOpcode() ==
ISD::SETCC &&
RHS.getOpcode() == AMDGPUISD::FP_CLASS &&
15105 (
RHS.getOperand(0) ==
LHS.getOperand(0) &&
15106 LHS.getOperand(0) ==
LHS.getOperand(1))) {
15108 unsigned NewMask = LCC ==
ISD::SETO ?
Mask->getZExtValue() & ~OrdMask
15109 :
Mask->getZExtValue() & OrdMask;
15112 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, MVT::i1,
RHS.getOperand(0),
15130 TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
15133 if (LHSMask != ~0u && RHSMask != ~0u) {
15136 if (LHSMask > RHSMask) {
15143 uint32_t LHSUsedLanes = ~(LHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15144 uint32_t RHSUsedLanes = ~(RHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15147 if (!(LHSUsedLanes & RHSUsedLanes) &&
15150 !(LHSUsedLanes == 0x0c0c0000 && RHSUsedLanes == 0x00000c0c)) {
15156 uint32_t
Mask = LHSMask & RHSMask;
15157 for (
unsigned I = 0;
I < 32;
I += 8) {
15158 uint32_t ByteSel = 0xff <<
I;
15159 if ((LHSMask & ByteSel) == 0x0c || (RHSMask & ByteSel) == 0x0c)
15160 Mask &= (0x0c <<
I) & 0xffffffff;
15165 uint32_t Sel =
Mask | (LHSUsedLanes & 0x04040404);
15168 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15218static const std::optional<ByteProvider<SDValue>>
15220 unsigned Depth = 0) {
15223 return std::nullopt;
15225 if (
Op.getValueSizeInBits() < 8)
15226 return std::nullopt;
15228 if (
Op.getValueType().isVector())
15231 switch (
Op->getOpcode()) {
15244 NarrowVT = VTSign->getVT();
15247 return std::nullopt;
15250 if (SrcIndex >= NarrowByteWidth)
15251 return std::nullopt;
15259 return std::nullopt;
15261 uint64_t BitShift = ShiftOp->getZExtValue();
15263 if (BitShift % 8 != 0)
15264 return std::nullopt;
15266 uint64_t NewSrcIndex = SrcIndex + BitShift / 8;
15267 if (NewSrcIndex >=
Op.getScalarValueSizeInBits() / 8)
15268 return std::nullopt;
15287static const std::optional<ByteProvider<SDValue>>
15289 unsigned StartingIndex = 0) {
15293 return std::nullopt;
15295 unsigned BitWidth =
Op.getScalarValueSizeInBits();
15297 return std::nullopt;
15299 return std::nullopt;
15301 bool IsVec =
Op.getValueType().isVector();
15302 switch (
Op.getOpcode()) {
15305 return std::nullopt;
15310 return std::nullopt;
15314 return std::nullopt;
15317 if (!
LHS->isConstantZero() && !
RHS->isConstantZero())
15318 return std::nullopt;
15319 if (!
LHS ||
LHS->isConstantZero())
15321 if (!
RHS ||
RHS->isConstantZero())
15323 return std::nullopt;
15328 return std::nullopt;
15332 return std::nullopt;
15334 uint32_t BitMask = BitMaskOp->getZExtValue();
15336 uint32_t IndexMask = 0xFF << (Index * 8);
15338 if ((IndexMask & BitMask) != IndexMask) {
15341 if (IndexMask & BitMask)
15342 return std::nullopt;
15351 return std::nullopt;
15355 if (!ShiftOp ||
Op.getValueType().isVector())
15356 return std::nullopt;
15358 uint64_t BitsProvided =
Op.getValueSizeInBits();
15359 if (BitsProvided % 8 != 0)
15360 return std::nullopt;
15362 uint64_t BitShift = ShiftOp->getAPIntValue().urem(BitsProvided);
15364 return std::nullopt;
15366 uint64_t ConcatSizeInBytes = BitsProvided / 4;
15367 uint64_t ByteShift = BitShift / 8;
15369 uint64_t NewIndex = (Index + ByteShift) % ConcatSizeInBytes;
15370 uint64_t BytesProvided = BitsProvided / 8;
15371 SDValue NextOp =
Op.getOperand(NewIndex >= BytesProvided ? 0 : 1);
15372 NewIndex %= BytesProvided;
15379 return std::nullopt;
15383 return std::nullopt;
15385 uint64_t BitShift = ShiftOp->getZExtValue();
15387 return std::nullopt;
15389 auto BitsProvided =
Op.getScalarValueSizeInBits();
15390 if (BitsProvided % 8 != 0)
15391 return std::nullopt;
15393 uint64_t BytesProvided = BitsProvided / 8;
15394 uint64_t ByteShift = BitShift / 8;
15395 if (Index + ByteShift < BytesProvided)
15397 Index + ByteShift);
15400 return std::nullopt;
15406 return std::nullopt;
15410 return std::nullopt;
15412 uint64_t BitShift = ShiftOp->getZExtValue();
15413 if (BitShift % 8 != 0)
15414 return std::nullopt;
15415 uint64_t ByteShift = BitShift / 8;
15421 return Index < ByteShift
15424 Depth + 1, StartingIndex);
15433 return std::nullopt;
15441 NarrowBitWidth = VTSign->getVT().getSizeInBits();
15443 if (NarrowBitWidth % 8 != 0)
15444 return std::nullopt;
15445 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
15447 if (Index >= NarrowByteWidth)
15449 ? std::optional<ByteProvider<SDValue>>(
15457 return std::nullopt;
15461 if (NarrowByteWidth >= Index) {
15466 return std::nullopt;
15473 return std::nullopt;
15479 unsigned NarrowBitWidth = L->getMemoryVT().getSizeInBits();
15480 if (NarrowBitWidth % 8 != 0)
15481 return std::nullopt;
15482 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
15487 if (Index >= NarrowByteWidth) {
15489 ? std::optional<ByteProvider<SDValue>>(
15494 if (NarrowByteWidth > Index) {
15498 return std::nullopt;
15503 return std::nullopt;
15506 Depth + 1, StartingIndex);
15512 return std::nullopt;
15513 auto VecIdx = IdxOp->getZExtValue();
15514 auto ScalarSize =
Op.getScalarValueSizeInBits();
15515 if (ScalarSize < 32)
15516 Index = ScalarSize == 8 ? VecIdx : VecIdx * 2 + Index;
15518 StartingIndex, Index);
15521 case AMDGPUISD::PERM: {
15523 return std::nullopt;
15527 return std::nullopt;
15530 (PermMask->getZExtValue() & (0xFF << (Index * 8))) >> (Index * 8);
15531 if (IdxMask > 0x07 && IdxMask != 0x0c)
15532 return std::nullopt;
15534 auto NextOp =
Op.getOperand(IdxMask > 0x03 ? 0 : 1);
15535 auto NextIndex = IdxMask > 0x03 ? IdxMask % 4 : IdxMask;
15537 return IdxMask != 0x0c ?
calculateSrcByte(NextOp, StartingIndex, NextIndex)
15543 return std::nullopt;
15558 return !OpVT.
isVector() && OpVT.getSizeInBits() == 16;
15565 auto MemVT = L->getMemoryVT();
15568 return L->getMemoryVT().getSizeInBits() == 16;
15578 int Low8 = Mask & 0xff;
15579 int Hi8 = (Mask & 0xff00) >> 8;
15581 assert(Low8 < 8 && Hi8 < 8);
15583 bool IsConsecutive = (Hi8 - Low8 == 1);
15588 bool Is16Aligned = !(Low8 % 2);
15590 return IsConsecutive && Is16Aligned;
15598 int Low16 = PermMask & 0xffff;
15599 int Hi16 = (PermMask & 0xffff0000) >> 16;
15609 auto OtherOpIs16Bit = TempOtherOp.getValueSizeInBits() == 16 ||
15611 if (!OtherOpIs16Bit)
15619 unsigned DWordOffset) {
15624 assert(Src.getValueSizeInBits().isKnownMultipleOf(8));
15629 if (Src.getValueType().isVector()) {
15630 auto ScalarTySize = Src.getScalarValueSizeInBits();
15631 auto ScalarTy = Src.getValueType().getScalarType();
15632 if (ScalarTySize == 32) {
15636 if (ScalarTySize > 32) {
15639 DAG.
getConstant(DWordOffset / (ScalarTySize / 32), SL, MVT::i32));
15640 auto ShiftVal = 32 * (DWordOffset % (ScalarTySize / 32));
15647 assert(ScalarTySize < 32);
15656 auto NumElements =
TypeSize / ScalarTySize;
15657 auto Trunc32Elements = (ScalarTySize * NumElements) / 32;
15658 auto NormalizedTrunc = Trunc32Elements * 32 / ScalarTySize;
15659 auto NumElementsIn32 = 32 / ScalarTySize;
15660 auto NumAvailElements = DWordOffset < Trunc32Elements
15662 : NumElements - NormalizedTrunc;
15675 auto ShiftVal = 32 * DWordOffset;
15683 [[maybe_unused]]
EVT VT =
N->getValueType(0);
15688 for (
int i = 0; i < 4; i++) {
15690 std::optional<ByteProvider<SDValue>>
P =
15693 if (!
P ||
P->isConstantZero())
15698 if (PermNodes.
size() != 4)
15701 std::pair<unsigned, unsigned> FirstSrc(0, PermNodes[0].SrcOffset / 4);
15702 std::optional<std::pair<unsigned, unsigned>> SecondSrc;
15704 for (
size_t i = 0; i < PermNodes.
size(); i++) {
15705 auto PermOp = PermNodes[i];
15708 int SrcByteAdjust = 4;
15712 if (!PermOp.hasSameSrc(PermNodes[FirstSrc.first]) ||
15713 ((PermOp.SrcOffset / 4) != FirstSrc.second)) {
15715 if (!PermOp.hasSameSrc(PermNodes[SecondSrc->first]) ||
15716 ((PermOp.SrcOffset / 4) != SecondSrc->second))
15720 SecondSrc = {i, PermNodes[i].SrcOffset / 4};
15721 assert(!(PermNodes[SecondSrc->first].Src->getValueSizeInBits() % 8));
15724 assert((PermOp.SrcOffset % 4) + SrcByteAdjust < 8);
15726 PermMask |= ((PermOp.SrcOffset % 4) + SrcByteAdjust) << (i * 8);
15729 SDValue Op = *PermNodes[FirstSrc.first].Src;
15731 assert(
Op.getValueSizeInBits() == 32);
15735 int Low16 = PermMask & 0xffff;
15736 int Hi16 = (PermMask & 0xffff0000) >> 16;
15738 bool WellFormedLow = (Low16 == 0x0504) || (Low16 == 0x0100);
15739 bool WellFormedHi = (Hi16 == 0x0706) || (Hi16 == 0x0302);
15742 if (WellFormedLow && WellFormedHi)
15746 SDValue OtherOp = SecondSrc ? *PermNodes[SecondSrc->first].Src :
Op;
15755 (
N->getOperand(0) ==
Op ||
N->getOperand(0) == OtherOp) &&
15756 (
N->getOperand(1) ==
Op ||
N->getOperand(1) == OtherOp))
15761 assert(
Op.getValueType().isByteSized() &&
15772 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
Op, OtherOp,
15784 V.getOperand(0).getValueType() == MVT::i16) {
15786 return V.getOperand(0);
15810 DAGCombinerInfo &DCI)
const {
15811 SelectionDAG &DAG = DCI.DAG;
15815 EVT VT =
N->getValueType(0);
15816 if (VT == MVT::i1) {
15818 if (
LHS.getOpcode() == AMDGPUISD::FP_CLASS &&
15819 RHS.getOpcode() == AMDGPUISD::FP_CLASS) {
15821 if (Src !=
RHS.getOperand(0))
15826 if (!CLHS || !CRHS)
15830 static const uint32_t MaxMask = 0x3ff;
15835 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, MVT::i1, Src,
15842 if (VT == MVT::i32 && !DCI.isBeforeLegalize()) {
15843 for (
unsigned I : {1u, 0
u}) {
15852 if (
N->isDivergent() && !
Cond->isDivergent() && !
Cond.hasOneUse())
15866 LHS.getOpcode() == AMDGPUISD::PERM &&
15872 Sel |=
LHS.getConstantOperandVal(2);
15874 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15886 if (VT == MVT::i32 && Subtarget->hasVOP3Literal()) {
15887 bool LHSIsHigh, RHSIsHigh;
15890 if (LHSHalf && RHSHalf && LHSIsHigh != RHSIsHigh) {
15893 LHSIsHigh ? RHSHalf : LHSHalf,
15894 LHSIsHigh ? LHSHalf : RHSHalf);
15902 TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
15906 auto usesCombinedOperand = [](SDNode *OrUse) {
15909 !OrUse->getValueType(0).isVector())
15913 for (
auto *VUser : OrUse->users()) {
15914 if (!VUser->getValueType(0).isVector())
15921 if (VUser->getOpcode() == VectorwiseOp)
15927 if (!
any_of(
N->users(), usesCombinedOperand))
15933 if (LHSMask != ~0u && RHSMask != ~0u) {
15936 if (LHSMask > RHSMask) {
15943 uint32_t LHSUsedLanes = ~(LHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15944 uint32_t RHSUsedLanes = ~(RHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15947 if (!(LHSUsedLanes & RHSUsedLanes) &&
15950 !(LHSUsedLanes == 0x0c0c0000 && RHSUsedLanes == 0x00000c0c)) {
15952 LHSMask &= ~RHSUsedLanes;
15953 RHSMask &= ~LHSUsedLanes;
15955 LHSMask |= LHSUsedLanes & 0x04040404;
15957 uint32_t Sel = LHSMask | RHSMask;
15960 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15965 if (LHSMask == ~0u || RHSMask == ~0u) {
16006 return IdentitySrc;
16012 if (VT != MVT::i64 || DCI.isBeforeLegalizeOps())
16027 if (SrcVT == MVT::i32) {
16032 DCI.AddToWorklist(LowOr.
getNode());
16033 DCI.AddToWorklist(HiBits.getNode());
16044 N->getOperand(0), CRHS))
16052 DAGCombinerInfo &DCI)
const {
16053 if (
SDValue RV = reassociateScalarOps(
N, DCI.DAG))
16060 SelectionDAG &DAG = DCI.DAG;
16062 EVT VT =
N->getValueType(0);
16063 if (CRHS && VT == MVT::i64) {
16065 splitBinaryBitConstantOp(DCI, SDLoc(
N),
ISD::XOR,
LHS, CRHS))
16072 unsigned Opc =
LHS.getOpcode();
16102 LHS->getOperand(0), FNegLHS, FNegRHS);
16111SITargetLowering::performZeroOrAnyExtendCombine(
SDNode *
N,
16112 DAGCombinerInfo &DCI)
const {
16113 if (!Subtarget->has16BitInsts() ||
16117 EVT VT =
N->getValueType(0);
16118 if (VT != MVT::i32)
16122 if (Src.getValueType() != MVT::i16)
16125 if (!Src->hasOneUse())
16128 if (
SDValue Ext = performExtendTruncShiftCombine(
N, DCI))
16135 std::optional<ByteProvider<SDValue>> BP0 =
16137 if (!BP0 || BP0->SrcOffset >= 4 || !BP0->Src)
16141 std::optional<ByteProvider<SDValue>> BP1 =
16143 if (!BP1 || BP1->SrcOffset >= 4 || !BP1->Src)
16151 SelectionDAG &DAG = DCI.DAG;
16153 uint32_t PermMask = 0x0c0c0c0c;
16156 PermMask = (PermMask & ~0xFF) | (BP0->SrcOffset + 4);
16161 PermMask = (PermMask & ~(0xFF << 8)) | (BP1->SrcOffset << 8);
16164 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32, V0,
V1,
16172SITargetLowering::performExtendTruncShiftCombine(
SDNode *
N,
16173 DAGCombinerInfo &DCI)
const {
16177 const unsigned Opc =
N->getOpcode();
16180 if (
N->getValueType(0) != MVT::i32 || Src.getValueType() != MVT::i16 ||
16181 Src.getOpcode() != (IsSigned ?
ISD::SRA :
ISD::SRL) || !Src.hasOneUse() ||
16187 if (!IsSigned && !Src->isDivergent())
16190 SDValue X = Src.getOperand(0).getOperand(0);
16192 if (
X.getValueType() != MVT::i32 || !Shift || Shift->getZExtValue() == 0 ||
16193 Shift->getZExtValue() >= 16 || (IsSigned && Shift->getZExtValue() != 8))
16196 SelectionDAG &DAG = DCI.DAG;
16198 const unsigned Width = 16 - Shift->getZExtValue();
16211SITargetLowering::performSignExtendInRegCombine(
SDNode *
N,
16212 DAGCombinerInfo &DCI)
const {
16218 if (((Src.getOpcode() == AMDGPUISD::SBUFFER_LOAD_UBYTE &&
16219 VTSign->getVT() == MVT::i8) ||
16220 (Src.getOpcode() == AMDGPUISD::SBUFFER_LOAD_USHORT &&
16221 VTSign->getVT() == MVT::i16))) {
16222 assert(Subtarget->hasScalarSubwordLoads() &&
16223 "s_buffer_load_{u8, i8} are supported "
16224 "in GFX12 (or newer) architectures.");
16225 unsigned Opc = (Src.getOpcode() == AMDGPUISD::SBUFFER_LOAD_UBYTE)
16226 ? AMDGPUISD::SBUFFER_LOAD_BYTE
16227 : AMDGPUISD::SBUFFER_LOAD_SHORT;
16230 DCI.DAG.getVTList(MVT::i32, Src.getOperand(0).getValueType());
16238 SDValue BufferLoad = DCI.DAG.getMemIntrinsicNode(
16239 Opc,
DL, ResList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
16240 return DCI.DAG.getMergeValues({BufferLoad, BufferLoad.
getValue(1)},
DL);
16242 if (((Src.getOpcode() == AMDGPUISD::BUFFER_LOAD_UBYTE &&
16243 VTSign->getVT() == MVT::i8) ||
16244 (Src.getOpcode() == AMDGPUISD::BUFFER_LOAD_USHORT &&
16245 VTSign->getVT() == MVT::i16)) &&
16254 Src.getOperand(6), Src.getOperand(7)};
16257 DCI.DAG.getVTList(MVT::i32, Src.getOperand(0).getValueType());
16258 unsigned Opc = (Src.getOpcode() == AMDGPUISD::BUFFER_LOAD_UBYTE)
16259 ? AMDGPUISD::BUFFER_LOAD_BYTE
16260 : AMDGPUISD::BUFFER_LOAD_SHORT;
16261 SDValue BufferLoadSignExt = DCI.DAG.getMemIntrinsicNode(
16262 Opc, SDLoc(
N), ResList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
16263 return DCI.DAG.getMergeValues(
16264 {BufferLoadSignExt, BufferLoadSignExt.
getValue(1)}, SDLoc(
N));
16270 DAGCombinerInfo &DCI)
const {
16271 SelectionDAG &DAG = DCI.DAG;
16278 if (
N->getOperand(0).isUndef())
16285 DAGCombinerInfo &DCI)
const {
16286 EVT VT =
N->getValueType(0);
16297 return DCI.DAG.getNode(AMDGPUISD::RSQ, SDLoc(
N), VT, N0.
getOperand(0),
16306 unsigned MaxDepth)
const {
16307 EVT VT =
Op.getValueType();
16309 "expected a floating-point value to query canonicality of");
16315 unsigned MaxDepth)
const {
16317 "QueryVT must be a floating-point scalar type");
16318 EVT VT =
Op.getValueType();
16322 unsigned Opcode =
Op.getOpcode();
16327 const auto &
F = CFP->getValueAPF();
16328 if (
F.isNaN() &&
F.isSignaling())
16330 if (!
F.isDenormal())
16362 case AMDGPUISD::FMUL_LEGACY:
16363 case AMDGPUISD::FMAD_FTZ:
16364 case AMDGPUISD::RCP:
16365 case AMDGPUISD::RSQ:
16366 case AMDGPUISD::RSQ_CLAMP:
16367 case AMDGPUISD::RCP_LEGACY:
16368 case AMDGPUISD::RCP_IFLAG:
16369 case AMDGPUISD::LOG:
16370 case AMDGPUISD::EXP:
16371 case AMDGPUISD::DIV_SCALE:
16372 case AMDGPUISD::DIV_FMAS:
16373 case AMDGPUISD::DIV_FIXUP:
16374 case AMDGPUISD::FRACT:
16375 case AMDGPUISD::CVT_PKRTZ_F16_F32:
16376 case AMDGPUISD::CVT_F32_UBYTE0:
16377 case AMDGPUISD::CVT_F32_UBYTE1:
16378 case AMDGPUISD::CVT_F32_UBYTE2:
16379 case AMDGPUISD::CVT_F32_UBYTE3:
16380 case AMDGPUISD::FP_TO_FP16:
16381 case AMDGPUISD::SIN_HW:
16382 case AMDGPUISD::COS_HW:
16394 if (
Op.getValueType() == MVT::i32) {
16400 if (RHS->getZExtValue() == 0xffff0000) {
16411 return Op.getValueType().getScalarType() != MVT::f16;
16421 case AMDGPUISD::CLAMP:
16422 case AMDGPUISD::FMED3:
16423 case AMDGPUISD::FMAX3:
16424 case AMDGPUISD::FMIN3:
16425 case AMDGPUISD::FMAXIMUM3:
16426 case AMDGPUISD::FMINIMUM3: {
16432 if (Subtarget->supportsMinMaxDenormModes() ||
16442 for (
unsigned I = 0, E =
Op.getNumOperands();
I != E; ++
I) {
16457 for (
unsigned i = 0, e =
Op.getNumOperands(); i != e; ++i) {
16491 if (
Op.getValueType() == MVT::i16) {
16503 unsigned IntrinsicID =
Op.getConstantOperandVal(0);
16505 switch (IntrinsicID) {
16506 case Intrinsic::amdgcn_update_dpp: {
16507 enum UpdateDPPOperand {
16515 if (QueryVT != MVT::f32 || (VT != MVT::i32 && VT != MVT::f32))
16522 if (
Op.getConstantOperandVal(RowMask) == 0xf &&
16523 Op.getConstantOperandVal(BankMask) == 0xf &&
16524 Op.getConstantOperandVal(BoundCtrl) != 0)
16528 return OldVal == SrcVal ||
16531 case Intrinsic::amdgcn_cvt_pkrtz:
16532 case Intrinsic::amdgcn_cubeid:
16533 case Intrinsic::amdgcn_frexp_mant:
16534 case Intrinsic::amdgcn_fdot2:
16535 case Intrinsic::amdgcn_rcp:
16536 case Intrinsic::amdgcn_rsq:
16537 case Intrinsic::amdgcn_rsq_clamp:
16538 case Intrinsic::amdgcn_rcp_legacy:
16539 case Intrinsic::amdgcn_rsq_legacy:
16540 case Intrinsic::amdgcn_trig_preop:
16541 case Intrinsic::amdgcn_tanh:
16542 case Intrinsic::amdgcn_log:
16543 case Intrinsic::amdgcn_exp2:
16544 case Intrinsic::amdgcn_sqrt:
16562 unsigned MaxDepth)
const {
16565 unsigned Opcode =
MI->getOpcode();
16567 if (Opcode == AMDGPU::G_FCANONICALIZE)
16570 std::optional<FPValueAndVReg> FCR;
16573 if (FCR->Value.isSignaling())
16575 if (!FCR->Value.isDenormal())
16586 case AMDGPU::G_FADD:
16587 case AMDGPU::G_FSUB:
16588 case AMDGPU::G_FMUL:
16589 case AMDGPU::G_FCEIL:
16590 case AMDGPU::G_FFLOOR:
16591 case AMDGPU::G_FRINT:
16592 case AMDGPU::G_FNEARBYINT:
16593 case AMDGPU::G_INTRINSIC_FPTRUNC_ROUND:
16594 case AMDGPU::G_INTRINSIC_TRUNC:
16595 case AMDGPU::G_INTRINSIC_ROUNDEVEN:
16596 case AMDGPU::G_FMA:
16597 case AMDGPU::G_FMAD:
16598 case AMDGPU::G_FSQRT:
16599 case AMDGPU::G_FDIV:
16600 case AMDGPU::G_FREM:
16601 case AMDGPU::G_FPOW:
16602 case AMDGPU::G_FPEXT:
16603 case AMDGPU::G_FLOG:
16604 case AMDGPU::G_FLOG2:
16605 case AMDGPU::G_FLOG10:
16606 case AMDGPU::G_FPTRUNC:
16607 case AMDGPU::G_AMDGPU_RCP_IFLAG:
16608 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE0:
16609 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE1:
16610 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE2:
16611 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE3:
16613 case AMDGPU::G_FNEG:
16614 case AMDGPU::G_FABS:
16615 case AMDGPU::G_FCOPYSIGN:
16617 case AMDGPU::G_FMINNUM:
16618 case AMDGPU::G_FMAXNUM:
16619 case AMDGPU::G_FMINNUM_IEEE:
16620 case AMDGPU::G_FMAXNUM_IEEE:
16621 case AMDGPU::G_FMINIMUM:
16622 case AMDGPU::G_FMAXIMUM:
16623 case AMDGPU::G_FMINIMUMNUM:
16624 case AMDGPU::G_FMAXIMUMNUM: {
16625 if (Subtarget->supportsMinMaxDenormModes() ||
16632 case AMDGPU::G_BUILD_VECTOR:
16637 case AMDGPU::G_INTRINSIC:
16638 case AMDGPU::G_INTRINSIC_CONVERGENT:
16640 case Intrinsic::amdgcn_update_dpp: {
16641 enum OperandIdx { Old = 2, Src, DppCtrl, RowMask, BankMask, BoundCtrl };
16643 LLT Ty =
MRI.getType(Reg);
16644 if (!Ty.isScalar() || Ty.getSizeInBits() != 32)
16647 Register SrcReg =
MI->getOperand(Src).getReg();
16651 if (
MI->getOperand(RowMask).getImm() == 0xf &&
16652 MI->getOperand(BankMask).getImm() == 0xf &&
16653 MI->getOperand(BoundCtrl).getImm() != 0)
16656 Register OldReg =
MI->getOperand(Old).getReg();
16657 return OldReg == SrcReg ||
isCanonicalized(OldReg, MF, MaxDepth - 1);
16659 case Intrinsic::amdgcn_fmul_legacy:
16660 case Intrinsic::amdgcn_fmad_ftz:
16661 case Intrinsic::amdgcn_sqrt:
16662 case Intrinsic::amdgcn_fmed3:
16663 case Intrinsic::amdgcn_sin:
16664 case Intrinsic::amdgcn_cos:
16665 case Intrinsic::amdgcn_log:
16666 case Intrinsic::amdgcn_exp2:
16667 case Intrinsic::amdgcn_log_clamp:
16668 case Intrinsic::amdgcn_rcp:
16669 case Intrinsic::amdgcn_rcp_legacy:
16670 case Intrinsic::amdgcn_rsq:
16671 case Intrinsic::amdgcn_rsq_clamp:
16672 case Intrinsic::amdgcn_rsq_legacy:
16673 case Intrinsic::amdgcn_div_scale:
16674 case Intrinsic::amdgcn_div_fmas:
16675 case Intrinsic::amdgcn_div_fixup:
16676 case Intrinsic::amdgcn_fract:
16677 case Intrinsic::amdgcn_cvt_pkrtz:
16678 case Intrinsic::amdgcn_cubeid:
16679 case Intrinsic::amdgcn_cubema:
16680 case Intrinsic::amdgcn_cubesc:
16681 case Intrinsic::amdgcn_cubetc:
16682 case Intrinsic::amdgcn_frexp_mant:
16683 case Intrinsic::amdgcn_fdot2:
16684 case Intrinsic::amdgcn_trig_preop:
16685 case Intrinsic::amdgcn_tanh:
16704 if (
C.isDenormal()) {
16717 if (
C.isSignaling()) {
16732SITargetLowering::performFCanonicalizeCombine(
SDNode *
N,
16733 DAGCombinerInfo &DCI)
const {
16734 SelectionDAG &DAG = DCI.DAG;
16736 EVT VT =
N->getValueType(0);
16745 return getCanonicalConstantFP(DAG, SDLoc(
N), VT, CFP->getValueAPF());
16760 EVT EltVT =
Lo.getValueType();
16769 for (
unsigned I = 0;
I != 2; ++
I) {
16773 getCanonicalConstantFP(DAG, SL, EltVT, CFP->getValueAPF());
16774 }
else if (
Op.isUndef()) {
16809 return AMDGPUISD::FMAX3;
16811 return AMDGPUISD::FMAXIMUM3;
16813 return AMDGPUISD::SMAX3;
16815 return AMDGPUISD::UMAX3;
16819 return AMDGPUISD::FMIN3;
16821 return AMDGPUISD::FMINIMUM3;
16823 return AMDGPUISD::SMIN3;
16825 return AMDGPUISD::UMIN3;
16846 if (!MinK || !MaxK)
16858 unsigned Med3Opc =
Signed ? AMDGPUISD::SMED3 : AMDGPUISD::UMED3;
16859 if (VT == MVT::i32 || (VT == MVT::i16 && Subtarget->hasMed3_16()))
16860 return DAG.
getNode(Med3Opc, SL, VT, Src, MaxVal, MinVal);
16884 bool IsKnownNoNaNs)
const {
16920 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
16926 if (
Info->getMode().DX10Clamp) {
16935 if (VT == MVT::f32 || (VT == MVT::f16 && Subtarget->hasMed3_16())) {
16967 return (VT == MVT::f32) || (VT == MVT::f16 &&
Subtarget.hasMin3Max3_16()) ||
16968 (VT == MVT::v2f16 &&
Subtarget.hasMin3Max3PKF16());
16971 return (VT == MVT::f32 &&
Subtarget.hasMinimum3Maximum3F32()) ||
16972 (VT == MVT::f16 &&
Subtarget.hasMinimum3Maximum3F16()) ||
16973 (VT == MVT::v2f16 &&
Subtarget.hasMinimum3Maximum3PKF16());
16978 return (VT == MVT::i32) || (VT == MVT::i16 &&
Subtarget.hasMin3Max3_16());
16987 DAGCombinerInfo &DCI)
const {
16988 SelectionDAG &DAG = DCI.DAG;
16991 unsigned Opc =
N->getOpcode();
16999 auto IsTreeWithCombinableChildren = [
Opc](
SDValue Op) {
17000 return (
Op.getOperand(0).getOpcode() ==
Opc &&
17001 Op.getOperand(0).hasOneUse()) ||
17003 Op.getOperand(1).hasOneUse());
17008 bool HasCombinableTreeChild =
17009 CanTreeCombineApply && (IsTreeWithCombinableChildren(Op0) ||
17010 IsTreeWithCombinableChildren(Op1));
17019 if (CanTreeCombineApply && !HasCombinableTreeChild) {
17036 {Op0.getOperand(0), Op0.getOperand(1), Op1},
17047 {Op0, Op1.getOperand(0), Op1.getOperand(1)},
17062 if (
Known.isNonZero() &&
Known.Zero.getBoolValue())
17070 if (
SDValue Med3 = performIntMed3ImmCombine(
17075 if (
SDValue Med3 = performIntMed3ImmCombine(
17081 if (
SDValue Med3 = performIntMed3ImmCombine(
17086 if (
SDValue Med3 = performIntMed3ImmCombine(
17099 (
Opc == AMDGPUISD::FMIN_LEGACY &&
17100 Op0.
getOpcode() == AMDGPUISD::FMAX_LEGACY)) &&
17101 (VT == MVT::f32 || VT == MVT::f64 ||
17102 (VT == MVT::f16 && Subtarget->has16BitInsts()) ||
17103 (VT == MVT::bf16 && Subtarget->hasBF16PackedInsts()) ||
17104 (VT == MVT::v2bf16 && Subtarget->hasBF16PackedInsts()) ||
17105 (VT == MVT::v2f16 && Subtarget->hasVOP3PInsts())) &&
17107 if (
SDValue Res = performFPMed3ImmCombine(DAG, SDLoc(
N), Op0, Op1,
17108 N->getFlags().hasNoNaNs()))
17115 const SDNodeFlags
Flags =
N->getFlags();
17117 !Subtarget->hasIEEEMinimumMaximumInsts() &&
17121 return DAG.
getNode(NewOpc, SDLoc(
N), VT, Op0, Op1, Flags);
17131 return (CA->isPosZero() && CB->isOne()) ||
17132 (CA->isOne() && CB->isPosZero());
17141 DAGCombinerInfo &DCI)
const {
17142 EVT VT =
N->getValueType(0);
17146 SelectionDAG &DAG = DCI.DAG;
17157 return DAG.
getNode(AMDGPUISD::CLAMP, SL, VT, Src2);
17161 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
17165 if (
Info->getMode().DX10Clamp) {
17178 return DAG.
getNode(AMDGPUISD::CLAMP, SL, VT, Src0);
17185 DAGCombinerInfo &DCI)
const {
17188 if (
Src0.isUndef() &&
Src1.isUndef())
17189 return DCI.DAG.getUNDEF(
N->getValueType(0));
17196SITargetLowering::performExponentOnlyScaleCombine(
SDNode *
N,
17197 DAGCombinerInfo &DCI)
const {
17198 std::optional<unsigned> ScaleArgIdx =
17204 unsigned OpIdx = *ScaleArgIdx + 1;
17205 SelectionDAG &DAG = DCI.DAG;
17212 Ops[OpIdx] = DemandedScale;
17226 bool IsDivergentIdx,
17228 if (Subtarget->getCLOpts().use_divergent_register_indexing)
17231 unsigned VecSize = EltSize * NumElem;
17234 if (VecSize <= 64 && EltSize < 32)
17243 if (IsDivergentIdx)
17247 unsigned NumInsts = NumElem +
17248 ((EltSize + 31) / 32) * NumElem ;
17252 if (Subtarget->useVGPRIndexMode())
17253 return NumInsts <= 16;
17257 if (Subtarget->hasMovrel())
17258 return NumInsts <= 15;
17264 SDValue Idx =
N->getOperand(
N->getNumOperands() - 1);
17275 EltSize, NumElem, Idx->isDivergent(),
getSubtarget());
17279SITargetLowering::performExtractVectorEltCombine(
SDNode *
N,
17280 DAGCombinerInfo &DCI)
const {
17286 EVT ResVT =
N->getValueType(0);
17310 if (!
C ||
C->getZExtValue() != 0x1f)
17326 if (Vec.
hasOneUse() && DCI.isBeforeLegalize() && VecEltVT == ResVT) {
17354 DCI.AddToWorklist(Elt0.
getNode());
17355 DCI.AddToWorklist(Elt1.
getNode());
17386 if (KImm && KImm->getValueType(0).getSizeInBits() == 64) {
17387 uint64_t KImmValue = KImm->getZExtValue();
17389 (KImmValue >> (32 *
Idx->getZExtValue())) & 0xffffffff, SL, MVT::i32);
17392 if (KFPImm && KFPImm->getValueType(0).getSizeInBits() == 64) {
17394 KFPImm->getValueAPF().bitcastToAPInt().getZExtValue();
17395 return DAG.
getConstant((KFPImmValue >> (32 *
Idx->getZExtValue())) &
17401 if (!DCI.isBeforeLegalize())
17408 VecSize > 32 && VecSize % 32 == 0 && Idx) {
17411 unsigned BitIndex =
Idx->getZExtValue() * VecEltSize;
17412 unsigned EltIdx = BitIndex / 32;
17413 unsigned LeftoverBitIdx = BitIndex % 32;
17417 DCI.AddToWorklist(Cast.
getNode());
17421 DCI.AddToWorklist(Elt.
getNode());
17424 DCI.AddToWorklist(Srl.
getNode());
17428 DCI.AddToWorklist(
Trunc.getNode());
17430 if (VecEltVT == ResVT) {
17442SITargetLowering::performInsertVectorEltCombine(
SDNode *
N,
17443 DAGCombinerInfo &DCI)
const {
17457 SelectionDAG &DAG = DCI.DAG;
17460 EVT IdxVT =
Idx.getValueType();
17477 Src.getOperand(0).getValueType() == MVT::f16) {
17478 return Src.getOperand(0);
17482 APFloat Val = CFP->getValueAPF();
17483 bool LosesInfo =
true;
17493 DAGCombinerInfo &DCI)
const {
17494 assert(Subtarget->has16BitInsts() && !Subtarget->hasMed3_16() &&
17495 "combine only useful on gfx8");
17497 SDValue TruncSrc =
N->getOperand(0);
17498 EVT VT =
N->getValueType(0);
17499 if (VT != MVT::f16)
17502 if (TruncSrc.
getOpcode() != AMDGPUISD::FMED3 ||
17506 SelectionDAG &DAG = DCI.DAG;
17537unsigned SITargetLowering::getFusedOpcode(
const SelectionDAG &DAG,
17539 const SDNode *N1)
const {
17544 if (((VT == MVT::f32 &&
17546 (VT == MVT::f16 && Subtarget->hasMadF16() &&
17563 EVT VT =
N->getValueType(0);
17564 if (VT != MVT::i32 && VT != MVT::i64)
17570 unsigned Opc =
N->getOpcode();
17625 if (!Const ||
Hi_32(Const->getZExtValue()) !=
uint32_t(-1))
17644 DAGCombinerInfo &DCI)
const {
17647 SelectionDAG &DAG = DCI.DAG;
17648 EVT VT =
N->getValueType(0);
17658 if (!
N->isDivergent() && Subtarget->hasSMulHi())
17662 if (NumBits <= 32 || NumBits > 64)
17673 if (!Subtarget->hasFullRate64Ops()) {
17674 unsigned NumUsers = 0;
17675 for (SDNode *User :
LHS->
users()) {
17678 if (!
User->isAnyAdd())
17702 bool MulSignedLo =
false;
17703 if (!MulLHSUnsigned32 || !MulRHSUnsigned32) {
17712 if (VT != MVT::i64) {
17735 getMad64_32(DAG, SL, MVT::i64, MulLHSLo, MulRHSLo, AddRHS, MulSignedLo);
17737 if (!MulSignedLo && (!MulLHSUnsigned32 || !MulRHSUnsigned32)) {
17738 auto [AccumLo, AccumHi] = DAG.
SplitScalar(Accum, SL, MVT::i32, MVT::i32);
17740 if (!MulLHSUnsigned32) {
17747 if (!MulRHSUnsigned32) {
17758 if (VT != MVT::i64)
17764SITargetLowering::foldAddSub64WithZeroLowBitsTo32(
SDNode *
N,
17765 DAGCombinerInfo &DCI)
const {
17775 SelectionDAG &DAG = DCI.DAG;
17790 unsigned Opcode =
N->getOpcode();
17794 DAG.
getNode(Opcode, SL, MVT::i32,
Hi, ConstHi32,
N->getFlags());
17805static std::optional<ByteProvider<SDValue>>
17808 if (!Byte0 || Byte0->isConstantZero()) {
17809 return std::nullopt;
17812 if (Byte1 && !Byte1->isConstantZero()) {
17813 return std::nullopt;
17819 unsigned FirstCs =
First & 0x0c0c0c0c;
17820 unsigned SecondCs = Second & 0x0c0c0c0c;
17821 unsigned FirstNoCs =
First & ~0x0c0c0c0c;
17822 unsigned SecondNoCs = Second & ~0x0c0c0c0c;
17824 assert((FirstCs & 0xFF) | (SecondCs & 0xFF));
17825 assert((FirstCs & 0xFF00) | (SecondCs & 0xFF00));
17826 assert((FirstCs & 0xFF0000) | (SecondCs & 0xFF0000));
17827 assert((FirstCs & 0xFF000000) | (SecondCs & 0xFF000000));
17829 return (FirstNoCs | SecondNoCs) | (FirstCs & SecondCs);
17843 assert(Src0.Src.has_value() && Src1.Src.has_value());
17846 Src0s.
push_back({*Src0.Src, ((Src0.SrcOffset % 4) << 24) + 0x0c0c0c,
17847 Src0.SrcOffset / 4});
17848 Src1s.
push_back({*Src1.Src, ((Src1.SrcOffset % 4) << 24) + 0x0c0c0c,
17849 Src1.SrcOffset / 4});
17853 for (
int BPI = 0; BPI < 2; BPI++) {
17856 BPP = {Src1, Src0};
17858 unsigned ZeroMask = 0x0c0c0c0c;
17859 unsigned FMask = 0xFF << (8 * (3 - Step));
17861 unsigned FirstMask =
17862 (BPP.first.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask);
17863 unsigned SecondMask =
17864 (BPP.second.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask);
17868 int FirstGroup = -1;
17869 for (
int I = 0;
I < 2;
I++) {
17871 auto MatchesFirst = [&BPP](
DotSrc &IterElt) {
17872 return IterElt.SrcOp == *BPP.first.Src &&
17873 (IterElt.DWordOffset == (BPP.first.SrcOffset / 4));
17877 if (Match != Srcs.
end()) {
17878 Match->PermMask =
addPermMasks(FirstMask, Match->PermMask);
17883 if (FirstGroup != -1) {
17885 auto MatchesSecond = [&BPP](
DotSrc &IterElt) {
17886 return IterElt.SrcOp == *BPP.second.Src &&
17887 (IterElt.DWordOffset == (BPP.second.SrcOffset / 4));
17890 if (Match != Srcs.
end()) {
17891 Match->PermMask =
addPermMasks(SecondMask, Match->PermMask);
17893 Srcs.
push_back({*BPP.second.Src, SecondMask, BPP.second.SrcOffset / 4});
17901 unsigned ZeroMask = 0x0c0c0c0c;
17902 unsigned FMask = 0xFF << (8 * (3 - Step));
17906 ((Src0.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask)),
17907 Src0.SrcOffset / 4});
17910 ((Src1.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask)),
17911 Src1.SrcOffset / 4});
17919 if (Srcs.
size() == 1) {
17920 auto *Elt = Srcs.
begin();
17924 if (Elt->PermMask == 0x3020100)
17927 return DAG.
getNode(AMDGPUISD::PERM, SL, MVT::i32, EltOp, EltOp,
17931 auto *FirstElt = Srcs.
begin();
17932 auto *SecondElt = std::next(FirstElt);
17939 auto FirstMask = FirstElt->PermMask;
17940 auto SecondMask = SecondElt->PermMask;
17942 unsigned FirstCs = FirstMask & 0x0c0c0c0c;
17943 unsigned FirstPlusFour = FirstMask | 0x04040404;
17946 FirstMask = (FirstPlusFour & 0x0F0F0F0F) | FirstCs;
17958 FirstElt = std::next(SecondElt);
17959 if (FirstElt == Srcs.
end())
17962 SecondElt = std::next(FirstElt);
17965 if (SecondElt == Srcs.
end()) {
17970 DAG.
getNode(AMDGPUISD::PERM, SL, MVT::i32, EltOp, EltOp,
17971 DAG.
getConstant(FirstElt->PermMask, SL, MVT::i32)));
17977 return Perms.
size() == 2
17983 for (
auto &[EntryVal, EntryMask, EntryOffset] : Srcs) {
17984 EntryMask = EntryMask >> ((4 - ChainLength) * 8);
17985 auto ZeroMask = ChainLength == 2 ? 0x0c0c0000 : 0x0c000000;
17986 EntryMask += ZeroMask;
17991 auto Opcode =
Op.getOpcode();
17993 return (Opcode ==
ISD::MUL || Opcode == AMDGPUISD::MUL_U24 ||
17994 Opcode == AMDGPUISD::MUL_I24);
17997static std::optional<bool>
18008 bool S0IsSigned = Known0.countMinLeadingOnes() > 0;
18011 bool S1IsSigned = Known1.countMinLeadingOnes() > 0;
18013 assert(!(S0IsUnsigned && S0IsSigned));
18014 assert(!(S1IsUnsigned && S1IsSigned));
18022 if ((S0IsUnsigned && S1IsUnsigned) || (S0IsSigned && S1IsSigned))
18028 if ((S0IsUnsigned && S1IsSigned) || (S0IsSigned && S1IsUnsigned))
18029 return std::nullopt;
18041 if ((S0IsSigned && !(S1IsSigned || S1IsUnsigned)) ||
18042 ((S1IsSigned && !(S0IsSigned || S0IsUnsigned))))
18047 if ((!(S1IsSigned || S1IsUnsigned) && !(S0IsSigned || S0IsUnsigned)))
18053 if ((S0IsUnsigned && !(S1IsSigned || S1IsUnsigned)) ||
18054 ((S1IsUnsigned && !(S0IsSigned || S0IsUnsigned))))
18055 return std::nullopt;
18061 DAGCombinerInfo &DCI)
const {
18062 SelectionDAG &DAG = DCI.DAG;
18063 EVT VT =
N->getValueType(0);
18069 if (Subtarget->hasMad64_32()) {
18075 if (
SDValue V = reassociateScalarOps(
N, DAG)) {
18079 if (VT == MVT::i64) {
18087 (Subtarget->hasDot1Insts() || Subtarget->hasDot8Insts())) {
18089 std::optional<bool> IsSigned;
18095 int ChainLength = 0;
18096 for (
int I = 0;
I < 4;
I++) {
18108 TempNode->getOperand(MulIdx), *Src0, *Src1,
18109 TempNode->getOperand(MulIdx)->getOperand(0),
18110 TempNode->getOperand(MulIdx)->getOperand(1), DAG);
18114 IsSigned = *IterIsSigned;
18115 if (*IterIsSigned != *IsSigned)
18118 auto AddIdx = 1 - MulIdx;
18121 if (
I == 2 &&
isMul(TempNode->getOperand(AddIdx))) {
18122 Src2s.
push_back(TempNode->getOperand(AddIdx));
18132 TempNode->getOperand(AddIdx), *Src0, *Src1,
18133 TempNode->getOperand(AddIdx)->getOperand(0),
18134 TempNode->getOperand(AddIdx)->getOperand(1), DAG);
18138 if (*IterIsSigned != *IsSigned)
18142 ChainLength =
I + 2;
18146 TempNode = TempNode->getOperand(AddIdx);
18148 ChainLength =
I + 1;
18150 if (TempNode.getOpcode() !=
ISD::ADD)
18152 LHS = TempNode->getOperand(0);
18153 RHS = TempNode->getOperand(1);
18156 if (ChainLength < 2)
18162 if (ChainLength < 4) {
18172 bool UseOriginalSrc =
false;
18173 if (ChainLength == 4 && Src0s.
size() == 1 && Src1s.
size() == 1 &&
18174 Src0s.
begin()->PermMask == Src1s.
begin()->PermMask &&
18175 Src0s.
begin()->SrcOp.getValueSizeInBits() >= 32 &&
18176 Src1s.
begin()->SrcOp.getValueSizeInBits() >= 32) {
18177 SmallVector<unsigned, 4> SrcBytes;
18178 auto Src0Mask = Src0s.
begin()->PermMask;
18179 SrcBytes.
push_back((Src0Mask >> 24) & 0xFF);
18180 bool UniqueEntries =
true;
18181 for (
auto I = 1;
I < 4;
I++) {
18182 auto NextByte = (Src0Mask >> ((3 -
I) * 8)) & 0xFF;
18185 UniqueEntries =
false;
18191 if (UniqueEntries) {
18192 UseOriginalSrc =
true;
18194 auto *FirstElt = Src0s.
begin();
18198 auto *SecondElt = Src1s.
begin();
18200 SecondElt->DWordOffset);
18209 if (!UseOriginalSrc) {
18216 DAG.
getExtOrTrunc(*IsSigned, Src2s[ChainLength - 1], SL, MVT::i32);
18219 : Intrinsic::amdgcn_udot4,
18229 if (VT != MVT::i32 || !DCI.isAfterLegalizeDAG())
18234 unsigned Opc =
LHS.getOpcode();
18246 auto Cond =
RHS.getOperand(0);
18251 SDVTList VTList = DAG.
getVTList(MVT::i32, MVT::i1);
18268 DAGCombinerInfo &DCI)
const {
18269 SelectionDAG &DAG = DCI.DAG;
18271 EVT VT =
N->getValueType(0);
18284 SDNodeFlags ShlFlags = N1->
getFlags();
18288 SDNodeFlags NewShlFlags =
18293 DCI.AddToWorklist(Inner.
getNode());
18300 if (Subtarget->hasMad64_32()) {
18310 if (VT == MVT::i64) {
18324 if (!YIsConstant && !ZIsConstant && !
X->isDivergent() &&
18325 Y->isDivergent() !=
Z->isDivergent()) {
18334 if (
Y->isDivergent())
18337 SDNodeFlags ReassocFlags =
18340 DCI.AddToWorklist(UniformInner.
getNode());
18352 DAGCombinerInfo &DCI)
const {
18353 SelectionDAG &DAG = DCI.DAG;
18354 EVT VT =
N->getValueType(0);
18356 if (VT == MVT::i64) {
18361 if (VT != MVT::i32)
18370 unsigned Opc =
RHS.getOpcode();
18377 auto Cond =
RHS.getOperand(0);
18382 SDVTList VTList = DAG.
getVTList(MVT::i32, MVT::i1);
18408 ConstantSDNode *ShiftAmt =
18410 unsigned BitWidth =
X.getValueType().getScalarSizeInBits();
18421 unsigned NumLiveUses = 0;
18422 for (
SDUse &U :
Op->uses()) {
18423 if (U.getResNo() !=
Op.getResNo() || U.getUser()->use_empty())
18425 if (++NumLiveUses > 1)
18428 return NumLiveUses == 1;
18436 Op =
Op.getOperand(0);
18451 Op =
Op.getOperand(0);
18463SITargetLowering::splitPackedMathWithFAbsSource(
SDNode *
N,
18464 DAGCombinerInfo &DCI)
const {
18465 EVT VT =
N->getValueType(0);
18475 return DCI.DAG.UnrollVectorOp(
N);
18479 DAGCombinerInfo &DCI)
const {
18483 SelectionDAG &DAG = DCI.DAG;
18484 EVT VT =
N->getValueType(0);
18496 if (
A ==
LHS.getOperand(1)) {
18497 unsigned FusedOp = getFusedOpcode(DAG,
N,
LHS.getNode());
18498 if (FusedOp != 0) {
18500 return DAG.
getNode(FusedOp, SL, VT,
A, Two,
RHS);
18508 if (
A ==
RHS.getOperand(1)) {
18509 unsigned FusedOp = getFusedOpcode(DAG,
N,
RHS.getNode());
18510 if (FusedOp != 0) {
18512 return DAG.
getNode(FusedOp, SL, VT,
A, Two,
LHS);
18521 DAGCombinerInfo &DCI)
const {
18525 SelectionDAG &DAG = DCI.DAG;
18527 EVT VT =
N->getValueType(0);
18540 if (
A ==
LHS.getOperand(1)) {
18541 unsigned FusedOp = getFusedOpcode(DAG,
N,
LHS.getNode());
18542 if (FusedOp != 0) {
18546 return DAG.
getNode(FusedOp, SL, VT,
A, Two, NegRHS);
18555 if (
A ==
RHS.getOperand(1)) {
18556 unsigned FusedOp = getFusedOpcode(DAG,
N,
RHS.getNode());
18557 if (FusedOp != 0) {
18559 return DAG.
getNode(FusedOp, SL, VT,
A, NegTwo,
LHS);
18568 DAGCombinerInfo &DCI)
const {
18569 SelectionDAG &DAG = DCI.DAG;
18571 EVT VT =
N->getValueType(0);
18573 if (VT != MVT::f16 && VT != MVT::bf16)
18579 SDNodeFlags
Flags =
N->getFlags();
18580 SDNodeFlags RHSFlags =
RHS->getFlags();
18586 bool IsNegative =
false;
18587 if (CLHS->
isOne() || (IsNegative = CLHS->isMinusOne())) {
18596 Rsq = DAG.
getNode(AMDGPUISD::RSQ, SL, VT, SqrtOp, Flags);
18597 }
else if (VT == MVT::f16) {
18606 DAG.
getNode(AMDGPUISD::RSQ, SL, MVT::f32, Ext, Flags);
18623 DAGCombinerInfo &DCI)
const {
18624 SelectionDAG &DAG = DCI.DAG;
18625 EVT VT =
N->getValueType(0);
18629 if (
SDValue V = performFMulExpCombine(
N, DCI))
18632 if (!
N->isDivergent() &&
getSubtarget()->hasSALUFloatInsts() &&
18633 (ScalarVT == MVT::f32 || ScalarVT == MVT::f16)) {
18648 if ((ScalarVT == MVT::f64 || ScalarVT == MVT::f32 || ScalarVT == MVT::f16) &&
18653 const ConstantFPSDNode *FalseNode =
18663 if (ScalarVT == MVT::f32 &&
18669 if (TrueNodeExpVal == INT_MIN)
18672 if (FalseNodeExpVal == INT_MIN)
18700 DAGCombinerInfo &DCI)
const {
18701 SelectionDAG &DAG = DCI.DAG;
18705 if (DCI.isAfterLegalizeDAG() ||
N->getValueType(0) != MVT::f32)
18713 SDNodeFlags
Flags =
N->getFlags();
18714 if (!
Flags.hasAllowReassociation() || !
Flags.hasApproximateFuncs())
18720 if (!
C || !
Exp.hasOneUse() || !
Exp->getFlags().hasApproximateFuncs())
18727 const APFloat &CVal =
C->getValueAPF();
18735 bool UseFmaLegacy =
false;
18749 if (!
N->getFlags().hasAllowContract())
18751 A =
Exp.getOperand(0);
18756 if (!
Exp->getFlags().hasAllowContract())
18762 UseFmaLegacy = !
Y || !
Y->getValueAPF().isNormal();
18763 if (UseFmaLegacy && !
getSubtarget()->hasFmaLegacy32Insts())
18767 Flags.setNoInfs(
false);
18768 A = DAG.
getNode(AMDGPUISD::LOG, SL, MVT::f32,
Exp.getOperand(0), Flags);
18769 B =
Exp.getOperand(1);
18770 ExpOpc = AMDGPUISD::EXP;
18785 return DAG.
getNode(ExpOpc, SL, MVT::f32, Fma, Flags);
18789 DAGCombinerInfo &DCI)
const {
18790 SelectionDAG &DAG = DCI.DAG;
18791 EVT VT =
N->getValueType(0);
18794 if (!Subtarget->hasDot10Insts() || VT != MVT::f32)
18822 bool AllowInaccuracy =
N->getFlags().hasApproximateFuncs() &&
18823 FMA->getFlags().hasApproximateFuncs();
18824 if (!AllowInaccuracy) {
18827 if (Subtarget->dot2UnconditionalFlush()) {
18839 if (
N->getFlags().hasAllowContract() &&
FMA->getFlags().hasAllowContract()) {
18875 if (Vec1 == Vec2 || Vec3 == Vec4)
18881 if ((Vec1 == Vec3 && Vec2 == Vec4) || (Vec1 == Vec4 && Vec2 == Vec3)) {
18882 return DAG.
getNode(AMDGPUISD::FDOT2, SL, MVT::f32, Vec1, Vec2, FMAAcc,
18925 EVT VT =
LHS.getValueType();
18926 assert(VT == MVT::f64 &&
"Incorrect operand type!");
18973 const std::optional<bool> KnownEq =
19014 const std::optional<bool> KnownUge =
19056 const std::optional<bool> KnownUle =
19079 DAGCombinerInfo &DCI)
const {
19080 SelectionDAG &DAG = DCI.DAG;
19085 EVT VT =
LHS.getValueType();
19114 return LHS.getOperand(0);
19128 const APInt &CT =
LHS.getConstantOperandAPInt(1);
19129 const APInt &CF =
LHS.getConstantOperandAPInt(2);
19134 return DAG.
getNOT(SL,
LHS.getOperand(0), MVT::i1);
19137 return LHS.getOperand(0);
19143 if (VT == MVT::i64) {
19146 const KnownBits LHSKnownLo32 = LHSKnown.
trunc(32);
19147 const KnownBits RHSKnownLo32 = RHSKnown.
trunc(32);
19174 const std::optional<bool> KnownEq =
19182 const std::optional<bool> KnownEq =
19193 const std::optional<bool> KnownUge =
19213 const std::optional<bool> KnownUle =
19237 const KnownBits LHSKnownHi32 = LHSKnown.
extractBits(32, 32);
19238 const KnownBits RHSKnownHi32 = RHSKnown.
extractBits(32, 32);
19239 const std::optional<bool> KnownEq =
19242 if (KnownEq ==
true) {
19248 return DAG.
getSetCC(SL,
N->getValueType(0), LHSLo, RHSLo, NewCC);
19280 DAG.
getVTList(MVT::i32, MVT::i1), {Op0Lo, Op1Lo});
19285 {Op0Hi, Op1Hi, CarryInHi});
19295 DCI.CombineTo(
LHS.getNode(), Result);
19299 if (VT != MVT::f32 && VT != MVT::f64 &&
19300 (!Subtarget->has16BitInsts() || VT != MVT::f16))
19315 const unsigned IsInfMask =
19317 const unsigned IsFiniteMask =
19322 return DAG.
getNode(AMDGPUISD::FP_CLASS, SL, MVT::i1,
LHS.getOperand(0),
19327 if (VT == MVT::f64) {
19338SITargetLowering::performCvtF32UByteNCombine(
SDNode *
N,
19339 DAGCombinerInfo &DCI)
const {
19340 SelectionDAG &DAG = DCI.DAG;
19342 unsigned Offset =
N->getOpcode() - AMDGPUISD::CVT_F32_UBYTE0;
19361 unsigned ShiftOffset = 8 *
Offset;
19363 ShiftOffset -=
C->getZExtValue();
19365 ShiftOffset +=
C->getZExtValue();
19367 if (ShiftOffset < 32 && (ShiftOffset % 8) == 0) {
19368 return DAG.
getNode(AMDGPUISD::CVT_F32_UBYTE0 + ShiftOffset / 8, SL,
19369 MVT::f32, Shifted);
19380 DCI.AddToWorklist(
N);
19387 return DAG.
getNode(
N->getOpcode(), SL, MVT::f32, DemandedSrc);
19393 DAGCombinerInfo &DCI)
const {
19402 (
F.isNaN() && MF.
getInfo<SIMachineFunctionInfo>()->getMode().DX10Clamp)) {
19403 return DCI.DAG.getConstantFP(
Zero, SDLoc(
N),
N->getValueType(0));
19408 return DCI.DAG.getConstantFP(One, SDLoc(
N),
N->getValueType(0));
19410 return getCanonicalConstantFP(DCI.DAG, SDLoc(
N),
N->getValueType(0),
F);
19420 FrexpInput =
V.getOperand(0);
19430SITargetLowering::performFrexpSelectCombine(
SDNode *
N,
19431 DAGCombinerInfo &DCI)
const {
19433 if (Subtarget->hasFractBug())
19445 bool CondSelectsZero;
19453 CondSelectsZero =
true;
19454 }
else if (
isFrexpExp(TrueVal, FrexpInput)) {
19457 CondSelectsZero =
false;
19469 bool IsNonFiniteTest =
false;
19481 bool LHSMatchesFrexp =
19482 (CondLHS == FrexpInput) ||
19483 (LHSIsFabs &&
peekFPSignOps(FAbsInput) == FrexpInputStripped) ||
19485 bool RHSMatchesFrexp = (CondRHS == FrexpInput) ||
19493 SelectionDAG &DAG = DCI.DAG;
19494 if (LHSMatchesFrexp &&
19496 IsNonFiniteTest = CondSelectsZero;
19498 IsNonFiniteTest = CondSelectsZero;
19505 IsNonFiniteTest = CondSelectsZero;
19512 IsNonFiniteTest = !CondSelectsZero;
19518 SelectionDAG &DAG = DCI.DAG;
19519 if (LHSMatchesFrexp &&
19521 IsNonFiniteTest = !CondSelectsZero;
19523 IsNonFiniteTest = !CondSelectsZero;
19525 }
else if (
Cond.getOpcode() == AMDGPUISD::FP_CLASS &&
19531 const unsigned FiniteMask =
19535 unsigned Mask = CMask->getZExtValue();
19536 unsigned ZeroMask = CondSelectsZero ?
Mask : ~Mask;
19537 IsNonFiniteTest = (ZeroMask & FiniteMask) == 0;
19541 if (!IsNonFiniteTest)
19549 DAGCombinerInfo &DCI)
const {
19570 bool isFloatingPoint =
LHS.getValueType().isFloatingPoint();
19571 bool isInteger =
LHS.getValueType().isInteger();
19574 if (!isFloatingPoint && !isInteger)
19579 bool isNonEquality =
19581 if (!isEquality && !isNonEquality)
19598 if (isFloatingPoint) {
19600 if (!Val.
isNormal() || Subtarget->getInstrInfo()->isInlineConstant(Val))
19603 const std::optional<int64_t> Val =
19612 if (!(isEquality && TrueVal == ConstVal) &&
19613 !(isNonEquality && FalseVal == ConstVal))
19617 if (isFloatingPoint && isNonEquality && FalseVal == ConstVal &&
19618 !
Cond->getFlags().hasNoNaNs() && !DCI.DAG.isKnownNeverNaN(ArgVal))
19625 SelectLHS, SelectRHS);
19630 switch (
N->getOpcode()) {
19652 if (
auto Res = promoteUniformOpToI32(
SDValue(
N, 0), DCI))
19673 switch (
N->getOpcode()) {
19675 return performAddCombine(
N, DCI);
19677 return performPtrAddCombine(
N, DCI);
19679 return performSubCombine(
N, DCI);
19681 if (
SDValue Res = splitPackedMathWithFAbsSource(
N, DCI))
19683 return performFAddCombine(
N, DCI);
19685 return performFSubCombine(
N, DCI);
19687 return performFDivCombine(
N, DCI);
19689 if (
SDValue Res = splitPackedMathWithFAbsSource(
N, DCI))
19691 return performFMulCombine(
N, DCI);
19693 return performSetCCCombine(
N, DCI);
19695 if (
auto Res = performFrexpSelectCombine(
N, DCI))
19697 if (
auto Res = performSelectCombine(
N, DCI))
19712 case AMDGPUISD::FMIN_LEGACY:
19713 case AMDGPUISD::FMAX_LEGACY:
19714 if (
SDValue Res = splitPackedMathWithFAbsSource(
N, DCI))
19716 return performMinMaxCombine(
N, DCI);
19718 if (
SDValue Res = splitPackedMathWithFAbsSource(
N, DCI))
19720 return performFMACombine(
N, DCI);
19722 return performAndCombine(
N, DCI);
19724 return performOrCombine(
N, DCI);
19727 if (
N->getValueType(0) == MVT::i32 &&
N->isDivergent() &&
19728 TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
19734 return performXorCombine(
N, DCI);
19737 return performZeroOrAnyExtendCombine(
N, DCI);
19739 return performExtendTruncShiftCombine(
N, DCI);
19741 return performSignExtendInRegCombine(
N, DCI);
19742 case AMDGPUISD::FP_CLASS:
19743 return performClassCombine(
N, DCI);
19745 return performFCanonicalizeCombine(
N, DCI);
19746 case AMDGPUISD::RCP:
19747 return performRcpCombine(
N, DCI);
19749 case AMDGPUISD::FRACT:
19750 case AMDGPUISD::RSQ:
19751 case AMDGPUISD::RCP_LEGACY:
19752 case AMDGPUISD::RCP_IFLAG:
19753 case AMDGPUISD::RSQ_CLAMP: {
19762 return performUCharToFloatCombine(
N, DCI);
19764 return performFCopySignCombine(
N, DCI);
19765 case AMDGPUISD::CVT_F32_UBYTE0:
19766 case AMDGPUISD::CVT_F32_UBYTE1:
19767 case AMDGPUISD::CVT_F32_UBYTE2:
19768 case AMDGPUISD::CVT_F32_UBYTE3:
19769 return performCvtF32UByteNCombine(
N, DCI);
19770 case AMDGPUISD::FMED3:
19771 return performFMed3Combine(
N, DCI);
19772 case AMDGPUISD::CVT_PKRTZ_F16_F32:
19773 return performCvtPkRTZCombine(
N, DCI);
19775 if (
SDValue Res = performExponentOnlyScaleCombine(
N, DCI))
19778 case AMDGPUISD::CLAMP:
19779 return performClampCombine(
N, DCI);
19782 EVT VT =
N->getValueType(0);
19785 if (VT == MVT::v2i16 || VT == MVT::v2f16 || VT == MVT::v2bf16) {
19788 EVT EltVT = Src.getValueType();
19789 if (EltVT != MVT::i16)
19799 return performExtractVectorEltCombine(
N, DCI);
19801 return performInsertVectorEltCombine(
N, DCI);
19803 return performFPRoundCombine(
N, DCI);
19812 return performMemSDNodeCombine(MemNode, DCI);
19843 unsigned Opcode =
Node->getMachineOpcode();
19846 int D16Idx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::d16) - 1;
19847 if (D16Idx >= 0 &&
Node->getConstantOperandVal(D16Idx))
19850 SDNode *
Users[5] = {
nullptr};
19852 unsigned DmaskIdx =
19853 AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::dmask) - 1;
19854 unsigned OldDmask =
Node->getConstantOperandVal(DmaskIdx);
19855 unsigned NewDmask = 0;
19856 unsigned TFEIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::tfe) - 1;
19857 unsigned LWEIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::lwe) - 1;
19858 bool UsesTFC = (int(TFEIdx) >= 0 &&
Node->getConstantOperandVal(TFEIdx)) ||
19859 (
int(LWEIdx) >= 0 &&
Node->getConstantOperandVal(LWEIdx));
19860 unsigned TFCLane = 0;
19861 bool HasChain =
Node->getNumValues() > 1;
19863 if (OldDmask == 0) {
19871 TFCLane = OldBitsSet;
19875 for (SDUse &Use :
Node->uses()) {
19878 if (
Use.getResNo() != 0)
19881 SDNode *
User =
Use.getUser();
19884 if (!
User->isMachineOpcode() ||
19885 User->getMachineOpcode() != TargetOpcode::EXTRACT_SUBREG)
19897 if (UsesTFC && Lane == TFCLane) {
19902 for (
unsigned i = 0, Dmask = OldDmask; (i <= Lane) && (Dmask != 0); i++) {
19904 Dmask &= ~(1 << Comp);
19912 NewDmask |= 1 << Comp;
19917 bool NoChannels = !NewDmask;
19924 if (OldBitsSet == 1)
19930 if (NewDmask == OldDmask)
19939 unsigned NewChannels = BitsSet + UsesTFC;
19943 assert(NewOpcode != -1 &&
19944 NewOpcode !=
static_cast<int>(
Node->getMachineOpcode()) &&
19945 "failed to find equivalent MIMG op");
19953 MVT SVT =
Node->getValueType(0).getVectorElementType().getSimpleVT();
19955 MVT ResultVT = NewChannels == 1
19958 : NewChannels == 5 ? 8
19960 SDVTList NewVTList =
19963 MachineSDNode *NewNode =
19972 if (NewChannels == 1) {
19982 for (
unsigned i = 0, Idx = AMDGPU::sub0; i < 5; ++i) {
19987 if (i || !NoChannels)
19992 if (NewUser != User) {
20002 Idx = AMDGPU::sub1;
20005 Idx = AMDGPU::sub2;
20008 Idx = AMDGPU::sub3;
20011 Idx = AMDGPU::sub4;
20022 Op =
Op.getOperand(0);
20043 MRI.createVirtualRegister(&AMDGPU::VReg_1RegClass), MVT::i1);
20047 Node->getOperand(0), SL, VReg, SrcVal,
20053 return ToResultReg.
getNode();
20058 for (
unsigned i = 0; i <
Node->getNumOperands(); ++i) {
20060 Ops.push_back(
Node->getOperand(i));
20066 Node->getOperand(i).getValueType(),
20067 Node->getOperand(i)),
20079 unsigned Opcode =
Node->getMachineOpcode();
20081 if (
TII->isImage(Opcode) && !
TII->get(Opcode).mayStore() &&
20082 !
TII->isGather4(Opcode) &&
20084 return adjustWritemask(
Node, DAG);
20087 if (Opcode == AMDGPU::INSERT_SUBREG || Opcode == AMDGPU::REG_SEQUENCE) {
20093 case AMDGPU::V_DIV_SCALE_F32_e64:
20094 case AMDGPU::V_DIV_SCALE_F64_e64: {
20102 if ((Src0.isMachineOpcode() &&
20103 Src0.getMachineOpcode() != AMDGPU::IMPLICIT_DEF) &&
20104 (Src0 == Src1 || Src0 == Src2))
20107 MVT VT = Src0.getValueType().getSimpleVT();
20119 if (Src0.isMachineOpcode() &&
20120 Src0.getMachineOpcode() == AMDGPU::IMPLICIT_DEF) {
20121 if (Src1.isMachineOpcode() &&
20122 Src1.getMachineOpcode() != AMDGPU::IMPLICIT_DEF)
20124 else if (Src2.isMachineOpcode() &&
20125 Src2.getMachineOpcode() != AMDGPU::IMPLICIT_DEF)
20128 assert(Src1.getMachineOpcode() == AMDGPU::IMPLICIT_DEF);
20160 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::vdata);
20161 unsigned InitIdx = 0;
20163 if (
TII->isImage(
MI)) {
20171 unsigned TFEVal = TFE ? TFE->
getImm() : 0;
20172 unsigned LWEVal = LWE ? LWE->
getImm() : 0;
20173 unsigned D16Val = D16 ? D16->getImm() : 0;
20175 if (!TFEVal && !LWEVal)
20186 assert(MO_Dmask &&
"Expected dmask operand in instruction");
20188 unsigned dmask = MO_Dmask->
getImm();
20193 bool Packed = !Subtarget->hasUnpackedD16VMem();
20195 InitIdx = D16Val && Packed ? ((ActiveLanes + 1) >> 1) + 1 : ActiveLanes + 1;
20202 uint32_t DstSize =
TRI.getRegSizeInBits(*DstRC) / 32;
20203 if (DstSize < InitIdx)
20207 InitIdx =
TRI.getRegSizeInBits(*DstRC) / 32;
20215 Register PrevDst =
MRI.cloneVirtualRegister(
MI.getOperand(DstIdx).getReg());
20216 unsigned NewDst = 0;
20221 unsigned SizeLeft = Subtarget->usePRTStrictNull() ? InitIdx : 1;
20222 unsigned CurrIdx = Subtarget->usePRTStrictNull() ? 0 : (InitIdx - 1);
20225 for (; SizeLeft; SizeLeft--, CurrIdx++) {
20226 NewDst =
MRI.createVirtualRegister(
TII->getOpRegClass(
MI, DstIdx));
20228 Register SubReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
20246 MI.tieOperands(DstIdx,
MI.getNumOperands() - 1);
20258 if (
TII->isVOP3(
MI.getOpcode())) {
20260 TII->legalizeOperandsVOP3(
MRI,
MI);
20262 if (
TII->isMAI(
MI)) {
20267 int Src0Idx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(),
20268 AMDGPU::OpName::scale_src0);
20269 if (Src0Idx != -1) {
20270 int Src1Idx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(),
20271 AMDGPU::OpName::scale_src1);
20272 if (
TII->usesConstantBus(
MRI,
MI, Src0Idx) &&
20273 TII->usesConstantBus(
MRI,
MI, Src1Idx))
20274 TII->legalizeOpWithMove(
MI, Src1Idx);
20281 if (
TII->isImage(
MI))
20282 TII->enforceOperandRCAlignment(
MI, AMDGPU::OpName::vaddr);
20324 uint64_t RsrcDword2And3)
const {
20354std::pair<unsigned, const TargetRegisterClass *>
20361 if (Constraint.
size() == 1) {
20365 if (VT == MVT::Other)
20368 switch (Constraint[0]) {
20375 RC = &AMDGPU::SReg_32RegClass;
20378 RC = &AMDGPU::SGPR_64RegClass;
20383 return std::pair(0U,
nullptr);
20390 return std::pair(0U,
nullptr);
20392 RC = Subtarget->useRealTrue16Insts() ? &AMDGPU::VGPR_16RegClass
20393 : &AMDGPU::VGPR_32_Lo256RegClass;
20396 RC = Subtarget->hasVGPRMSBs()
20397 ?
TRI->getAlignedLo256VGPRClassForBitWidth(
BitWidth)
20400 return std::pair(0U,
nullptr);
20405 if (!Subtarget->hasMAIInsts())
20409 return std::pair(0U,
nullptr);
20411 RC = &AMDGPU::AGPR_32RegClass;
20416 return std::pair(0U,
nullptr);
20421 }
else if (Constraint ==
"VA" && Subtarget->hasGFX90AInsts()) {
20425 RC = &AMDGPU::AV_32RegClass;
20428 RC =
TRI->getVectorSuperClassForBitWidth(
BitWidth);
20430 return std::pair(0U,
nullptr);
20439 return std::pair(0U, RC);
20442 if (Kind !=
'\0') {
20444 RC = &AMDGPU::VGPR_32_Lo256RegClass;
20445 }
else if (Kind ==
's') {
20446 RC = &AMDGPU::SGPR_32RegClass;
20447 }
else if (Kind ==
'a') {
20448 RC = &AMDGPU::AGPR_32RegClass;
20454 return std::pair(0U,
nullptr);
20460 return std::pair(0U,
nullptr);
20464 RC =
TRI->getVGPRClassForBitWidth(Width);
20466 RC =
TRI->getSGPRClassForBitWidth(Width);
20468 RC =
TRI->getAGPRClassForBitWidth(Width);
20470 Reg =
TRI->getMatchingSuperReg(Reg, AMDGPU::sub0, RC);
20475 return std::pair(0U,
nullptr);
20477 return std::pair(Reg, RC);
20486 return std::pair(0U,
nullptr);
20487 if (RC && Idx < RC->getNumRegs())
20489 return std::pair(0U,
nullptr);
20495 Ret.second =
TRI->getPhysRegBaseClass(Ret.first);
20496 if (!Subtarget->useRealTrue16Insts() &&
20497 TRI->getRegSizeInBits(*Ret.second) == 16)
20498 return std::pair(0U,
nullptr);
20505 if (Constraint.
size() == 1) {
20506 switch (Constraint[0]) {
20516 }
else if (Constraint ==
"DA" || Constraint ==
"DB") {
20524 if (Constraint.
size() == 1) {
20525 switch (Constraint[0]) {
20535 }
else if (Constraint.
size() == 2) {
20536 if (Constraint ==
"VA")
20538 if (Constraint ==
"RF")
20549 if (ConstraintCode ==
"RF")
20564 std::vector<SDValue> &
Ops,
20579 unsigned Size =
Op.getScalarValueSizeInBits();
20583 if (
Size == 16 && !Subtarget->has16BitInsts())
20587 Val =
C->getSExtValue();
20591 Val =
C->getValueAPF().bitcastToAPInt().getSExtValue();
20595 if (
Size != 16 ||
Op.getNumOperands() != 2)
20597 if (
Op.getOperand(0).isUndef() ||
Op.getOperand(1).isUndef())
20600 Val =
C->getSExtValue();
20604 Val =
C->getValueAPF().bitcastToAPInt().getSExtValue();
20613 uint64_t Val)
const {
20614 if (Constraint.
size() == 1) {
20615 switch (Constraint[0]) {
20630 }
else if (Constraint.
size() == 2) {
20631 if (Constraint ==
"DA") {
20632 int64_t HiBits =
static_cast<int32_t
>(Val >> 32);
20633 int64_t LoBits =
static_cast<int32_t
>(Val);
20637 if (Constraint ==
"DB") {
20645 unsigned MaxSize)
const {
20646 unsigned Size = std::min<unsigned>(
Op.getScalarValueSizeInBits(), MaxSize);
20647 bool HasInv2Pi = Subtarget->hasInv2PiInlineImm();
20649 MVT VT =
Op.getSimpleValueType();
20674 switch (UnalignedClassID) {
20675 case AMDGPU::VReg_64RegClassID:
20676 return AMDGPU::VReg_64_Align2RegClassID;
20677 case AMDGPU::VReg_96RegClassID:
20678 return AMDGPU::VReg_96_Align2RegClassID;
20679 case AMDGPU::VReg_128RegClassID:
20680 return AMDGPU::VReg_128_Align2RegClassID;
20681 case AMDGPU::VReg_160RegClassID:
20682 return AMDGPU::VReg_160_Align2RegClassID;
20683 case AMDGPU::VReg_192RegClassID:
20684 return AMDGPU::VReg_192_Align2RegClassID;
20685 case AMDGPU::VReg_224RegClassID:
20686 return AMDGPU::VReg_224_Align2RegClassID;
20687 case AMDGPU::VReg_256RegClassID:
20688 return AMDGPU::VReg_256_Align2RegClassID;
20689 case AMDGPU::VReg_288RegClassID:
20690 return AMDGPU::VReg_288_Align2RegClassID;
20691 case AMDGPU::VReg_320RegClassID:
20692 return AMDGPU::VReg_320_Align2RegClassID;
20693 case AMDGPU::VReg_352RegClassID:
20694 return AMDGPU::VReg_352_Align2RegClassID;
20695 case AMDGPU::VReg_384RegClassID:
20696 return AMDGPU::VReg_384_Align2RegClassID;
20697 case AMDGPU::VReg_512RegClassID:
20698 return AMDGPU::VReg_512_Align2RegClassID;
20699 case AMDGPU::VReg_1024RegClassID:
20700 return AMDGPU::VReg_1024_Align2RegClassID;
20701 case AMDGPU::AReg_64RegClassID:
20702 return AMDGPU::AReg_64_Align2RegClassID;
20703 case AMDGPU::AReg_96RegClassID:
20704 return AMDGPU::AReg_96_Align2RegClassID;
20705 case AMDGPU::AReg_128RegClassID:
20706 return AMDGPU::AReg_128_Align2RegClassID;
20707 case AMDGPU::AReg_160RegClassID:
20708 return AMDGPU::AReg_160_Align2RegClassID;
20709 case AMDGPU::AReg_192RegClassID:
20710 return AMDGPU::AReg_192_Align2RegClassID;
20711 case AMDGPU::AReg_256RegClassID:
20712 return AMDGPU::AReg_256_Align2RegClassID;
20713 case AMDGPU::AReg_512RegClassID:
20714 return AMDGPU::AReg_512_Align2RegClassID;
20715 case AMDGPU::AReg_1024RegClassID:
20716 return AMDGPU::AReg_1024_Align2RegClassID;
20732 if (Info->isEntryFunction()) {
20739 unsigned MaxNumSGPRs = ST.getMaxNumSGPRs(MF);
20741 ? AMDGPU::SGPR_32RegClass.getRegister(MaxNumSGPRs - 1)
20742 :
TRI->getAlignedHighSGPRForRC(MF, 2,
20743 &AMDGPU::SGPR_64RegClass);
20744 Info->setSGPRForEXECCopy(SReg);
20746 assert(!
TRI->isSubRegister(Info->getScratchRSrcReg(),
20747 Info->getStackPtrOffsetReg()));
20748 if (Info->getStackPtrOffsetReg() != AMDGPU::SP_REG)
20749 MRI.replaceRegWith(AMDGPU::SP_REG, Info->getStackPtrOffsetReg());
20753 if (Info->getScratchRSrcReg() != AMDGPU::PRIVATE_RSRC_REG)
20754 MRI.replaceRegWith(AMDGPU::PRIVATE_RSRC_REG, Info->getScratchRSrcReg());
20756 if (Info->getFrameOffsetReg() != AMDGPU::FP_REG)
20757 MRI.replaceRegWith(AMDGPU::FP_REG, Info->getFrameOffsetReg());
20759 Info->limitOccupancy(MF);
20761 if (ST.isWave32() && !MF.
empty()) {
20762 for (
auto &
MBB : MF) {
20763 for (
auto &
MI :
MBB) {
20764 TII->fixImplicitOperands(
MI);
20774 if (ST.needsAlignedVGPRs()) {
20775 for (
unsigned I = 0, E =
MRI.getNumVirtRegs();
I != E; ++
I) {
20781 if (NewClassID != -1)
20782 MRI.setRegClass(Reg,
TRI->getRegClass(NewClassID));
20791 const APInt &DemandedElts,
20793 unsigned Depth)
const {
20795 unsigned Opc =
Op.getOpcode();
20798 unsigned IID =
Op.getConstantOperandVal(0);
20800 case Intrinsic::amdgcn_mbcnt_lo:
20801 case Intrinsic::amdgcn_mbcnt_hi: {
20806 Known.Zero.setBitsFrom(
20807 IID == Intrinsic::amdgcn_mbcnt_lo ? ST.getWavefrontSizeLog2() : 5);
20833 unsigned MaxValue =
20840 unsigned BFEWidth,
bool SExt,
unsigned Depth) {
20844 unsigned Src1Cst = 0;
20845 if (Src1.isImm()) {
20846 Src1Cst = Src1.getImm();
20847 }
else if (Src1.isReg()) {
20851 Src1Cst = Cst->Value.getZExtValue();
20862 if (Width >= BFEWidth)
20879 unsigned Depth)
const {
20882 switch (
MI->getOpcode()) {
20883 case AMDGPU::S_BFE_I32:
20886 case AMDGPU::S_BFE_U32:
20889 case AMDGPU::S_BFE_I64:
20892 case AMDGPU::S_BFE_U64:
20895 case AMDGPU::G_INTRINSIC:
20896 case AMDGPU::G_INTRINSIC_CONVERGENT: {
20899 case Intrinsic::amdgcn_workitem_id_x:
20902 case Intrinsic::amdgcn_workitem_id_y:
20905 case Intrinsic::amdgcn_workitem_id_z:
20908 case Intrinsic::amdgcn_mbcnt_lo:
20909 case Intrinsic::amdgcn_mbcnt_hi: {
20912 Known.Zero.setBitsFrom(IID == Intrinsic::amdgcn_mbcnt_lo
20921 case Intrinsic::amdgcn_groupstaticsize: {
20925 Known.Zero.setHighBits(
20929 case Intrinsic::amdgcn_readfirstlane:
20930 case Intrinsic::amdgcn_readlane: {
20936 case Intrinsic::amdgcn_mul_u24:
20937 case Intrinsic::amdgcn_mul_i24: {
20944 bool SelfMultiply = LHS == RHS;
20950 LHSKnown = RHSKnown;
20958 IID == Intrinsic::amdgcn_mul_i24,
20965 case AMDGPU::G_AMDGPU_BUFFER_LOAD_UBYTE:
20966 Known.Zero.setHighBits(24);
20968 case AMDGPU::G_AMDGPU_BUFFER_LOAD_USHORT:
20969 Known.Zero.setHighBits(16);
20971 case AMDGPU::G_AMDGPU_COPY_SCC_VCC:
20974 Known.Zero.setHighBits(
Known.getBitWidth() - 1);
20976 case AMDGPU::G_AMDGPU_SMED3:
20977 case AMDGPU::G_AMDGPU_UMED3: {
20978 auto [Dst, Src0, Src1, Src2] =
MI->getFirst4Regs();
21005 unsigned Depth)
const {
21014 if (
MaybeAlign RetAlign = Attrs.getRetAlignment())
21035 BlockToAlign =
ML->getHeader();
21039 if (needsFetchWindowAlignment(*BlockToAlign))
21061 if (Header->getAlignment() != PrefAlign)
21062 return Header->getAlignment();
21064 unsigned LoopSize = 0;
21069 LoopSize +=
MBB->getAlignment().value() / 2;
21072 LoopSize +=
TII->getInstSizeInBytes(
MI);
21073 if (LoopSize > 192)
21078 if (LoopSize <= 64)
21081 if (LoopSize <= 128)
21082 return CacheLineAlign;
21088 auto I = Exit->getFirstNonDebugInstr();
21089 if (
I != Exit->end() &&
I->getOpcode() == AMDGPU::S_INST_PREFETCH)
21090 return CacheLineAlign;
21099 if (PreTerm == Pre->
begin() ||
21100 std::prev(PreTerm)->getOpcode() != AMDGPU::S_INST_PREFETCH)
21104 auto ExitHead = Exit->getFirstNonDebugInstr();
21105 if (ExitHead == Exit->end() ||
21106 ExitHead->getOpcode() != AMDGPU::S_INST_PREFETCH)
21111 return CacheLineAlign;
21119 if (needsFetchWindowAlignment(*
MBB))
21124bool SITargetLowering::needsFetchWindowAlignment(
21126 if (!
getSubtarget()->hasLoopHeadInstSplitSensitivity())
21130 if (
MI.isMetaInstruction())
21133 return TII->getInstSizeInBytes(
MI) > 4;
21143 N =
N->getOperand(0).getNode();
21153 switch (
N->getOpcode()) {
21161 if (Reg.isPhysical() ||
MRI.isLiveIn(Reg))
21162 return !
TRI->isSGPRReg(
MRI, Reg);
21168 return !
TRI->isSGPRReg(
MRI, Reg);
21172 unsigned AS = L->getAddressSpace();
21179 case AMDGPUISD::REG_LOAD:
21187 case AMDGPUISD::ATOMIC_CMP_SWAP:
21188 case AMDGPUISD::BUFFER_ATOMIC_SWAP:
21189 case AMDGPUISD::BUFFER_ATOMIC_ADD:
21190 case AMDGPUISD::BUFFER_ATOMIC_SUB:
21191 case AMDGPUISD::BUFFER_ATOMIC_SMIN:
21192 case AMDGPUISD::BUFFER_ATOMIC_UMIN:
21193 case AMDGPUISD::BUFFER_ATOMIC_SMAX:
21194 case AMDGPUISD::BUFFER_ATOMIC_UMAX:
21195 case AMDGPUISD::BUFFER_ATOMIC_AND:
21196 case AMDGPUISD::BUFFER_ATOMIC_OR:
21197 case AMDGPUISD::BUFFER_ATOMIC_XOR:
21198 case AMDGPUISD::BUFFER_ATOMIC_INC:
21199 case AMDGPUISD::BUFFER_ATOMIC_DEC:
21200 case AMDGPUISD::BUFFER_ATOMIC_CMPSWAP:
21201 case AMDGPUISD::BUFFER_ATOMIC_FADD:
21202 case AMDGPUISD::BUFFER_ATOMIC_FMIN:
21203 case AMDGPUISD::BUFFER_ATOMIC_FMAX:
21209 return A->readMem() &&
A->writeMem();
21230 switch (Ty.getScalarSizeInBits()) {
21242 const APInt &DemandedElts,
21245 unsigned Depth)
const {
21246 if (
Op.getOpcode() == AMDGPUISD::CLAMP) {
21250 if (Info->getMode().DX10Clamp)
21263enum class AtomicFlushDenormalReason {
21266 IgnoreDenormalMode,
21267 FunctionFlushesDenormals
21272enum class GlobalFPAtomicLegality {
21274 AgentScopeFineGrainedRemoteMemory,
21275 EmulatedSystemScope,
21277 NoFineGrainedMemory
21284static AtomicFlushDenormalReason
21286 if (RMW->
hasMetadata(LLVMContext::MD_atomic_ignore_denormal_mode))
21287 return AtomicFlushDenormalReason::IgnoreDenormalMode;
21292 ? AtomicFlushDenormalReason::FunctionFlushesDenormals
21293 : AtomicFlushDenormalReason::IEEE;
21298 GlobalFPAtomicLegality MemLegality,
21299 AtomicFlushDenormalReason DenormReason) {
21302 if (MemScope.empty())
21303 MemScope =
"system";
21306 R <<
"hardware instruction generated for atomic "
21308 <<
" at " <<
ore::NV(
"SyncScope", MemScope) <<
" scope since ";
21310 switch (MemLegality) {
21311 case GlobalFPAtomicLegality::AgentScopeFineGrainedRemoteMemory:
21312 R <<
"fine-grained remote memory atomics work below system scope";
21314 case GlobalFPAtomicLegality::EmulatedSystemScope:
21315 R <<
"system scope atomics are emulated in hardware";
21317 case GlobalFPAtomicLegality::NoRemoteMemory:
21318 R <<
"memory is not remote (!amdgpu.no.remote.memory)";
21320 case GlobalFPAtomicLegality::NoFineGrainedMemory:
21321 R <<
"memory is not fine-grained (!amdgpu.no.fine.grained.memory)";
21323 case GlobalFPAtomicLegality::Illegal:
21327 switch (DenormReason) {
21328 case AtomicFlushDenormalReason::Native:
21330 case AtomicFlushDenormalReason::IgnoreDenormalMode:
21331 R <<
", and denormals may be flushed (!atomic.ignore.denormal.mode)";
21333 case AtomicFlushDenormalReason::FunctionFlushesDenormals:
21334 R <<
", and the floating-point environment flushes denormals";
21336 case AtomicFlushDenormalReason::IEEE:
21345 Type *EltTy = VT->getElementType();
21346 return VT->getNumElements() == 2 &&
21366 unsigned BW = IT->getBitWidth();
21367 return BW == 32 || BW == 64;
21381 unsigned BW =
DL.getPointerSizeInBits(PT->getAddressSpace());
21382 return BW == 32 || BW == 64;
21385 if (Ty->isFloatTy() || Ty->isDoubleTy())
21389 return VT->getNumElements() == 2 &&
21390 VT->getElementType()->getPrimitiveSizeInBits() == 16;
21398static GlobalFPAtomicLegality
21407 if (HasSystemScope) {
21408 if (
Subtarget.hasAgentScopeFineGrainedRemoteMemoryAtomics() &&
21410 return GlobalFPAtomicLegality::NoRemoteMemory;
21411 if (
Subtarget.hasEmulatedSystemScopeAtomics())
21412 return GlobalFPAtomicLegality::EmulatedSystemScope;
21413 }
else if (
Subtarget.hasAgentScopeFineGrainedRemoteMemoryAtomics())
21414 return GlobalFPAtomicLegality::AgentScopeFineGrainedRemoteMemory;
21416 return RMW->
hasMetadata(
"amdgpu.no.fine.grained.memory")
21417 ? GlobalFPAtomicLegality::NoFineGrainedMemory
21418 : GlobalFPAtomicLegality::Illegal;
21431 const MDNode *MD =
I->getMetadata(LLVMContext::MD_noalias_addrspace);
21439 return STI.hasGloballyAddressableScratch()
21462 DL.getTypeSizeInBits(RMW->
getType()) == 64 &&
21466 GlobalFPAtomicLegality MemLegality = GlobalFPAtomicLegality::Illegal;
21467 AtomicFlushDenormalReason DenormReason = AtomicFlushDenormalReason::Native;
21477 bool HasSystemScope =
21509 if (!Subtarget->hasSubClampInsts() ||
21511 !Subtarget->hasAtomicDsCondSubClampInsts()) ||
21513 !Subtarget->hasAtomicCondSubClampFlatInsts()))
21518 if (!IT || IT->getBitWidth() != 32)
21524 if (Subtarget->hasEmulatedSystemScopeAtomics())
21540 if (!HasSystemScope &&
21541 Subtarget->hasAgentScopeFineGrainedRemoteMemoryAtomics())
21553 if (RMW->
hasMetadata(
"amdgpu.no.fine.grained.memory"))
21562 ConstVal && ConstVal->isNullValue() &&
21601 if (Ty->isFloatTy()) {
21606 if (Ty->isDoubleTy()) {
21627 if (Ty->isFloatTy() &&
21628 !Subtarget->hasMemoryAtomicFaddF32DenormalSupport()) {
21630 if (DenormReason == AtomicFlushDenormalReason::IEEE)
21636 if (MemLegality != GlobalFPAtomicLegality::Illegal) {
21643 if (Subtarget->hasAtomicBufferGlobalPkAddF16Insts() &&
isV2F16(Ty))
21647 if (Subtarget->hasAtomicGlobalPkAddBF16Inst() &&
isV2BF16(Ty))
21651 if (Subtarget->hasAtomicBufferGlobalPkAddF16Insts() &&
isV2F16(Ty))
21656 if (Subtarget->hasAtomicBufferPkAddBF16Inst() &&
isV2BF16(Ty))
21661 if (Subtarget->hasFlatBufferGlobalAtomicFaddF64Inst() && Ty->isDoubleTy())
21665 if (Ty->isFloatTy()) {
21668 if (RMW->
use_empty() && Subtarget->hasAtomicFaddNoRtnInsts())
21671 if (!RMW->
use_empty() && Subtarget->hasAtomicFaddRtnInsts())
21676 Subtarget->hasAtomicBufferGlobalPkAddF16NoRtnInsts() &&
21684 if (Subtarget->hasFlatAtomicFaddF32Inst())
21693 if (Subtarget->hasLDSFPAtomicAddF32()) {
21694 if (RMW->
use_empty() && Subtarget->hasAtomicFaddNoRtnInsts())
21696 if (!RMW->
use_empty() && Subtarget->hasAtomicFaddRtnInsts())
21716 if (MemLegality != GlobalFPAtomicLegality::Illegal) {
21726 if (Subtarget->hasAtomicFMinFMaxF32FlatInsts() && Ty->isFloatTy())
21728 if (Subtarget->hasAtomicFMinFMaxF64FlatInsts() && Ty->isDoubleTy())
21732 if (Subtarget->hasAtomicFMinFMaxF32GlobalInsts() && Ty->isFloatTy())
21734 if (Subtarget->hasAtomicFMinFMaxF64GlobalInsts() && Ty->isDoubleTy())
21795 if (RC == &AMDGPU::VReg_1RegClass && !isDivergent)
21796 return Subtarget->isWave64() ? &AMDGPU::SReg_64RegClass
21797 : &AMDGPU::SReg_32RegClass;
21798 if (!
TRI->isSGPRClass(RC) && !isDivergent)
21799 return TRI->getEquivalentSGPRClass(RC);
21800 if (
TRI->isSGPRClass(RC) && isDivergent) {
21801 if (Subtarget->hasGFX90AInsts())
21802 return TRI->getEquivalentAVClass(RC);
21803 return TRI->getEquivalentVGPRClass(RC);
21816 unsigned WaveSize) {
21826 if (!Visited.
insert(
V).second)
21828 bool Result =
false;
21829 for (
const auto *U :
V->users()) {
21831 if (
V == U->getOperand(1)) {
21836 case Intrinsic::amdgcn_if_break:
21837 case Intrinsic::amdgcn_if:
21838 case Intrinsic::amdgcn_else:
21843 if (
V == U->getOperand(0)) {
21848 case Intrinsic::amdgcn_end_cf:
21849 case Intrinsic::amdgcn_loop:
21855 Result =
hasCFUser(U, Visited, WaveSize);
21864 const Value *V)
const {
21866 if (CI->isInlineAsm()) {
21875 for (
auto &TC : TargetConstraints) {
21889 return hasCFUser(V, Visited, Subtarget->getWavefrontSize());
21917 return MRI.hasOneNonDBGUse(N0);
21924 if (
I.getMetadata(
"amdgpu.noclobber"))
21926 if (
I.getMetadata(
"amdgpu.last.use"))
21928 if (
MDNode *
N =
I.getMetadata(
"amdgpu.cfs")) {
21933 "MOCFSB0 and MOCFSB1 are not adjacent bits");
21998 Alignment = RMW->getAlign();
22011 bool FullFlatEmulation =
22013 ((Subtarget->hasAtomicFaddInsts() && RMW->getType()->isFloatTy()) ||
22014 (Subtarget->hasFlatBufferGlobalAtomicFaddF64Inst() &&
22015 RMW->getType()->isDoubleTy()));
22018 bool ReturnValueIsUsed = !AI->
use_empty();
22027 if (FullFlatEmulation) {
22038 std::prev(BB->
end())->eraseFromParent();
22039 Builder.SetInsertPoint(BB);
22041 Value *LoadedShared =
nullptr;
22042 if (FullFlatEmulation) {
22043 Value *IsShared = Builder.CreateIntrinsic(Intrinsic::amdgcn_is_shared,
22044 {Addr},
nullptr,
"is.shared");
22045 Builder.CreateCondBr(IsShared, SharedBB, CheckPrivateBB);
22046 Builder.SetInsertPoint(SharedBB);
22047 Value *CastToLocal = Builder.CreateAddrSpaceCast(
22053 LoadedShared = Clone;
22055 Builder.CreateBr(PhiBB);
22056 Builder.SetInsertPoint(CheckPrivateBB);
22059 Value *IsPrivate = Builder.CreateIntrinsic(Intrinsic::amdgcn_is_private,
22060 {Addr},
nullptr,
"is.private");
22061 Builder.CreateCondBr(IsPrivate, PrivateBB, GlobalBB);
22063 Builder.SetInsertPoint(PrivateBB);
22065 Value *CastToPrivate = Builder.CreateAddrSpaceCast(
22068 Value *LoadedPrivate;
22070 LoadedPrivate = Builder.CreateAlignedLoad(
22071 RMW->getType(), CastToPrivate, RMW->getAlign(), RMW->isVolatile(),
22075 LoadedPrivate, RMW->getValOperand());
22077 Builder.CreateAlignedStore(NewVal, CastToPrivate, RMW->getAlign(),
22078 RMW->isVolatile());
22086 LoadedPrivate = Builder.CreateInsertValue(Insert, Equal, 1);
22089 Builder.CreateBr(PhiBB);
22091 Builder.SetInsertPoint(GlobalBB);
22095 if (FullFlatEmulation) {
22096 Value *CastToGlobal = Builder.CreateAddrSpaceCast(
22105 if (!FullFlatEmulation) {
22110 MDNode *RangeNotPrivate =
22113 LoadedGlobal->
setMetadata(LLVMContext::MD_noalias_addrspace,
22117 Builder.CreateBr(PhiBB);
22119 Builder.SetInsertPoint(PhiBB);
22121 if (ReturnValueIsUsed) {
22124 if (FullFlatEmulation)
22125 Loaded->addIncoming(LoadedShared, SharedBB);
22126 Loaded->addIncoming(LoadedPrivate, PrivateBB);
22127 Loaded->addIncoming(LoadedGlobal, GlobalBB);
22128 Loaded->takeName(AI);
22131 Builder.CreateBr(ExitBB);
22135 unsigned PtrOpIdx) {
22136 Value *PtrOp =
I->getOperand(PtrOpIdx);
22143 I->setOperand(PtrOpIdx, ASCast);
22155 ConstVal && ConstVal->isNullValue() &&
22186 "Expand Atomic Load only handles SCRATCH -> FLAT conversion");
22194 "Expand Atomic Store only handles SCRATCH -> FLAT conversion");
static bool isMul(MachineInstr *MI)
static unsigned getIntrinsicID(const SDNode *N)
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo MachineBasicBlock::iterator InsertPt
const AArch64InstrInfo & TII
AMDGPU address space definition.
static constexpr std::pair< ImplicitArgumentMask, StringLiteral > ImplicitAttrs[]
static bool allUsesHaveSourceMods(MachineInstr &MI, MachineRegisterInfo &MRI, unsigned CostThreshold=4)
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
static bool isCtlzOpc(unsigned Opc)
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 bool isAsyncLDSDMA(Intrinsic::ID Intr)
static std::optional< uint32_t > getConstantNamedBarrierNumber(const MachineOperand &BarOp, const MachineRegisterInfo &MRI)
Return the barrier ID for BarOp if it's statically known, mapping poison to 0 and masking off the hig...
static void packImage16bitOpsToDwords(MachineIRBuilder &B, MachineInstr &MI, SmallVectorImpl< Register > &PackedAddrs, unsigned ArgOffset, const AMDGPU::ImageDimIntrinsicInfo *Intr, bool IsA16, bool IsG16)
Turn a set of f16 typed registers in AddrRegs into a dword sized vector with f16 typed elements.
static Register readClusterIdField(MachineIRBuilder &B)
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 declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
Function Alias Analysis Results
static DenormalFPEnv getDenormalFPEnv(AttributeSet FnAttrs)
@ DEFAULT
Default weight is used in cases when there is no dedicated execution weight set.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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")
static std::optional< SDByteProvider > calculateByteProvider(SDValue Op, unsigned Index, unsigned Depth, std::optional< uint64_t > VectorIndex, unsigned StartingIndex=0, MutableArrayRef< uint8_t > ByteMask={})
static bool isSigned(unsigned 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...
iv Induction Variable Users
static constexpr Value * getValue(Ty &ValueOrUse)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
MachineBasicBlock * Folded
SmallVector< MachineOperand, 4 > Cond
if(!TBB||Cond.size()< 1) return false
Contains matchers for matching SSA Machine Instructions.
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
MachineRegisterInfo & MRI
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 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 isBuiltFromFAbs(SDValue Op)
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 MachineBasicBlock * expand64BitScalarArithmetic(MachineInstr &MI, MachineBasicBlock *BB)
static bool isClampZeroToOne(SDValue A, SDValue B)
static bool isBoolSGPRExt(SDValue V)
static bool supportsMin3Max3(const GCNSubtarget &Subtarget, unsigned Opc, EVT VT)
static AtomicFlushDenormalReason getAtomicFlushDenormalReason(const AtomicRMWInst *RMW)
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 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 std::tuple< unsigned, unsigned > getDPPOpcForWaveReduction(unsigned Opc, const GCNSubtarget &ST)
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 isCopyFromRegOfInlineAsm(const SDNode *N)
static bool elementPairIsOddToEven(ArrayRef< int > Mask, int Elt)
static SDValue lowerBFEIntrinsic(SDValue Op, SelectionDAG &DAG, Intrinsic::ID IntrinsicID)
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 isFloatingPointWaveReduceOperation(unsigned Opc)
static bool isImmConstraint(StringRef Constraint)
static SDValue padEltsToUndef(SelectionDAG &DAG, const SDLoc &DL, EVT CastVT, SDValue Src, int ExtraElts)
static bool hasCFUser(const Value *V, SmallPtrSet< const Value *, 16 > &Visited, unsigned WaveSize)
static std::pair< Register, Register > ExtractSubRegs(MachineInstr &MI, MachineOperand &Op, const TargetRegisterClass *SrcRC, const GCNSubtarget &ST, MachineRegisterInfo &MRI)
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 hasOneLiveUse(SDValue Op)
static bool isV2BF16(Type *Ty)
static bool isFrexpExp(SDValue V, SDValue &FrexpInput)
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 SDValue lowerWaveShuffle(const SITargetLowering &TLI, SDNode *N, SelectionDAG &DAG)
static SDValue diagnoseUnsupportedImage(SelectionDAG &DAG, SDValue Op, ArrayRef< EVT > ResultTypes, const SDLoc &DL, const Twine &Msg)
Emit a DiagnosticInfoUnsupported for an unsupported image intrinsic and return poison values of Resul...
static void placeSources(ByteProvider< SDValue > &Src0, ByteProvider< SDValue > &Src1, SmallVectorImpl< DotSrc > &Src0s, SmallVectorImpl< DotSrc > &Src1s, int Step)
static unsigned parseSyncscopeMDArg(const CallBase &CI, unsigned ArgIdx)
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 SDValue matchHalfZeroPack(SDValue V, bool &IsHigh)
If V is a 32-bit value whose low or high 16 bits are known zero because it was built as a half-zero p...
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 AtomicOrdering parseAtomicOrderingCABIArg(const CallBase &CI, unsigned ArgIdx)
static MachineBasicBlock * emitIndirectDst(MachineInstr &MI, MachineBasicBlock &MBB, const GCNSubtarget &ST)
static void setM0ToIndexFromSGPR(const SIInstrInfo *TII, MachineRegisterInfo &MRI, MachineInstr &MI, int Offset)
static DenormalFPEnv getDenormalFPEnv(const MachineFunction &MF)
static std::pair< MachineBasicBlock *, MachineBasicBlock * > splitBlockForLoop(MachineInstr &MI, MachineBasicBlock &MBB, bool InstInLoop)
static unsigned getBasePtrIndex(const MemSDNode *N)
MemSDNode::getBasePtr() does not work for intrinsics, which needs to offset by the chain and intrinsi...
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::pair< SDValue, SDValue > splitTFEValueAndStatus(SDValue Op, EVT VT, const SDLoc &DL, SelectionDAG &DAG)
static std::optional< ByteProvider< SDValue > > handleMulOperand(const SDValue &MulOperand)
static ISD::CondCode tryReduceF64CompareToHiHalf(const ISD::CondCode CC, const SDValue LHS, const SDValue RHS, const 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 bool isSingleUseFAbs(SDValue Op)
static EVT memVTFromLoadIntrData(const SITargetLowering &TLI, const DataLayout &DL, Type *Ty, unsigned MaxNumLanes)
static unsigned minMaxOpcToMin3Max3Opc(unsigned Opc)
static unsigned getExtOpcodeForPromotedOp(SDValue Op)
static void expand64BitV_CNDMASK(MachineInstr &MI, MachineBasicBlock *BB)
static GlobalFPAtomicLegality getGlobalMemoryFPAtomicLegality(const GCNSubtarget &Subtarget, const AtomicRMWInst *RMW, bool HasSystemScope)
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 OptimizationRemark emitAtomicRMWLegalRemark(const AtomicRMWInst *RMW, GlobalFPAtomicLegality MemLegality, AtomicFlushDenormalReason DenormReason)
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 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 initializeM0ToZeroForClusterLoad(SDValue Op, SelectionDAG &DAG, SDLoc DL)
static void allocateSGPR64Input(CCState &CCInfo, ArgDescriptor &Arg)
static uint64_t getIdentityValueForWaveReduction(unsigned Opc)
static void foldAsyncLDSOffset(SDValue Op, SelectionDAG &DAG, SDLoc DL)
SI DAG Lowering interface definition.
Interface definition for SIRegisterInfo.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
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 constexpr int Concat[]
static bool isSupportedBitWidth(unsigned Bits)
unsigned allocateBarrierGlobal(const DataLayout &DL, const GlobalVariable &GV)
static std::optional< uint32_t > getLDSKernelIdMetadata(const Function &F)
void setDynLDSAlign(const Function &F, const GlobalVariable &GV)
static std::optional< uint32_t > get32BitAbsoluteAddress(const GlobalValue &GV, unsigned AS)
void setUsesDynamicLDS(bool DynLDS)
bool isBottomOfStack() const
uint32_t getLDSSize() const
bool isEntryFunction() 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
virtual SDValue LowerGlobalAddress(AMDGPUMachineFunctionInfo *MFI, SDValue Op, SelectionDAG &DAG) 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
static KnownBits computeKnownBitsForMul24(const KnownBits &LHSKnown, const KnownBits &RHSKnown, unsigned BitWidth, bool IsSigned, bool SelfMultiply)
SDValue loadInputValue(SelectionDAG &DAG, const TargetRegisterClass *RC, EVT VT, const SDLoc &SL, const ArgDescriptor &Arg) const
AMDGPUTargetLowering(const TargetMachine &TM, const TargetSubtargetInfo &STI, const AMDGPUSubtarget &AMDGPUSTI)
static EVT getEquivalentMemType(LLVMContext &Context, EVT VT)
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
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.
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
SDValue LowerFP_TO_INT_SAT(SDValue Op, SelectionDAG &DAG) const
static bool shouldFoldFNegIntoSrc(SDNode *FNeg, SDValue FNegSrc)
bool isNarrowingProfitable(SDNode *N, EVT SrcVT, EVT DestVT) const override
Return true if it's profitable to narrow operations of type SrcVT to DestVT.
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(const DataLayout &DL, unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
static bool EnableObjectLinking
const std::array< unsigned, 3 > & getDims() const
static const LaneMaskConstants & get(const GCNSubtarget &ST)
const unsigned XorTermOpc
const unsigned AndSaveExecOpc
static constexpr roundingMode rmNearestTiesToEven
static constexpr const fltSemantics & IEEEhalf()
static constexpr const fltSemantics & IEEEsingle()
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
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
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.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
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.
bool isMask(unsigned numBits) const
bool isSignBitSet() const
Determine if sign bit of this APInt is 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.
unsigned getAddressSpace() const
Return the address space for the allocation.
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
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
An instruction that atomically checks whether a specified value is in a memory location,...
Value * getNewValOperand()
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
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,...
static unsigned getPointerOperandIndex()
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ 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.
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)
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 Basic Block Representation.
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
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.
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)
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
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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.
const APFloat & getValueAPF() const
bool isPosZero() const
Return true if the value is positive zero.
bool isOne() const
Returns true if this value is exactly +1.0.
bool isMinusOne() const
Returns true if this value is exactly -1.0.
bool isNegative() const
Return true if the value is negative.
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
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
uint64_t getZExtValue() const
const APInt & getAPIntValue() const
This is an important base class in LLVM.
uint64_t getNumOperands() const
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.
Diagnostic information for unsupported feature in backend.
static constexpr ElementCount getFixed(ScalarTy MinVal)
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 ...
LLVM_ABI 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()
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
const SIInstrInfo * getInstrInfo() const override
unsigned getInstCacheLineSize() const
Instruction cache line size in bytes (64 for pre-GFX11, 128 for GFX11+).
const SIRegisterInfo * getRegisterInfo() const override
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
void computeKnownBitsImpl(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
Evaluate a known-bits query with an explicit worklist instead of recursive descent.
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...
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Type * getValueType() const
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
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.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool hasMetadata() const
Return true if this instruction has any metadata attached to 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 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.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
bool isKnownNeverNaN() const
Return true if it's known this can never be a nan.
static LLVM_ABI KnownFPClass bitcast(const fltSemantics &FltSemantics, const KnownBits &Bits)
Report known values for a bitcast into a float with provided semantics.
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.
static LLT integer(unsigned SizeInBits)
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.
static unsigned getPointerOperandIndex()
This class is used to represent ISD::LOAD nodes.
TypeSize getValue() const
Describe properties that are true of each instruction in the target description file.
unsigned getID() const
getID() - Return the register class ID number.
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
iterator begin() const
begin/end - Return all of the registers in this class.
Wrapper class representing physical registers and target specific virtual registers.
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.
MVT changeTypeToInteger()
Return the type converted to an equivalently sized integer or vector with integer element type.
static LLVM_ABI MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
static auto all_valuetypes()
SimpleValueType Iteration.
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 '...
Align getAlignment() const
Return alignment of the basic block.
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.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
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.
PseudoSourceValueManager & getPSVManager() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
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 & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
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.
Flags getFlags() const
Return the raw flags of the source value,.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register 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,...
An SDNode that represents everything that will be needed to construct a MachineInstr.
This is an abstract virtual class for memory operations.
unsigned getAddressSpace() const
Return the address space for the associated pointer.
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
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 Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
LLVM_ABI const PseudoSourceValue * getConstantPool()
Return a pseudo source value referencing the constant pool.
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
ISD::CondCode getOperandCondCode(unsigned Num) const
Helper method returns the CondCode of a CondCodeSDNode.
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.
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.
bool isUndef() const
Returns true if the node type is UNDEF or POISON.
user_iterator user_begin() const
Provide iteration support to walk over all users of an SDNode.
op_iterator op_end() const
bool isAnyAdd() const
Returns true if the node type is ADD or PTRADD.
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, in exactly one operand.
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned i) const
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
unsigned getOpcode() const
unsigned getNumOperands() 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
SIModeRegisterDefaults getMode() const
std::tuple< const ArgDescriptor *, const TargetRegisterClass *, LLT > getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const
unsigned getBytesInStackArgArea() const
const AMDGPUGWSResourcePseudoSourceValue * getGWSPSV(const AMDGPUTargetMachine &TM)
static LLVM_READONLY const TargetRegisterClass * getSGPRClassForBitWidth(unsigned BitWidth)
static unsigned getSubRegFromChannel(uint64_t Channel, uint64_t NumRegs=1)
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
AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
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.
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
SDValue splitUnaryVectorOp(SDValue Op, SelectionDAG &DAG) const
SDValue lowerGET_FPENV(SDValue Op, SelectionDAG &DAG) const
bool isCanonicalized(SelectionDAG &DAG, SDValue Op, SDNodeFlags UserFlags={}, unsigned MaxDepth=5) const
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
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.
InlineAsm::ConstraintCode getInlineAsmMemConstraint(StringRef ConstraintCode) const override
bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags, unsigned *IsFast) const override
Return true if the target supports a memory access of this type for the given address space and align...
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.
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 computeKnownBitsForStackObjectPointer(KnownBits &Known, const MachineFunction &MF, Align Alignment) const override
Determine known bits of a pointer to a known valid stack object.
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.
ExtractSubvectorCost getExtractSubvectorCost(EVT ResVT, EVT SrcVT, unsigned Index) const override
Return the cost of extracting a subvector of type ResVT from a vector of type SrcVT,...
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...
Align getPrefLoopAlignment(MachineLoop *ML, const MachineBasicBlock *BlockToAlign) const override
Return the preferred loop alignment.
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 getTgtMemIntrinsic(SmallVectorImpl< IntrinsicInfo > &, const CallBase &, MachineFunction &MF, unsigned IntrinsicID) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
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.
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
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 canTransformPtrArithOutOfBounds(const Function &F, EVT PtrVT) const override
True if the target allows transformations of in-bounds pointer arithmetic that cause out-of-bounds in...
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...
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 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.
AtomicExpansionKind shouldExpandAtomicStoreInIR(const StoreInst *SI) const override
Returns how the given (atomic) store should be expanded by the IR-level AtomicExpand pass into.
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
AtomicExpansionKind shouldExpandAtomicLoadInIR(const LoadInst *LI) const override
Returns how the given (atomic) load should be expanded by the IR-level AtomicExpand pass.
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 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(const DataLayout &DL, 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
bool isUniformLoad(const LoadSDNode *Load) const
AtomicExpansionKind shouldExpandAtomicCmpXchgInIR(const AtomicCmpXchgInst *AI) const override
Returns how the given atomic cmpxchg should be expanded by the IR-level AtomicExpand pass.
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
SDValue splitBinaryVectorOp(SDValue Op, SelectionDAG &DAG) const
MachinePointerInfo getKernargSegmentPtrInfo(MachineFunction &MF) 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...
unsigned getMaxPermittedBytesForAlignment(MachineBasicBlock *MBB) const override
Return the maximum amount of bytes allowed to be emitted when padding for alignment.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
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.
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)
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 bool isConstantIntBuildVectorOrConstantInt(SDValue N, bool AllowOpaques=true) const
Test whether the given value is a constant int or similar node.
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 getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS, unsigned DestAS, const SDNodeFlags Flags=SDNodeFlags())
Return an AddrSpaceCastSDNode.
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
LLVM_ABI bool SignBitIsZeroFP(SDValue Op, unsigned Depth=0) const
Return true if the sign bit of Op is known to be zero, for a floating-point value.
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.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false, SDNodeFlags Flags={})
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
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.
void addNoMergeSiteInfo(const SDNode *Node, bool NoMerge)
Set NoMergeSiteInfo to be associated with Node if NoMerge is true.
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).
LLVM_ABI SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align DstAlign, Align SrcAlign, bool isVol, bool AlwaysInline, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), BatchAAResults *BatchAA=nullptr)
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 getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, SDValue Offset, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
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 getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Helper function to build ISD::STORE nodes.
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 void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
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 MMOMetadata &Metadata=MMOMetadata())
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...
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Loads are not normal binary operators: their result type is not determined by their operands,...
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
LLVM_ABI SDValue getFreeze(SDValue V, UndefPoisonKind Kind=UndefPoisonKind::UndefOrPoison)
Return a freeze of V using the SDLoc of the value operand.
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 getErrorMergeValues(ArrayRef< EVT > ResultTypes, SDValue Chain, const SDLoc &dl)
Return poison values for each of ResultTypes, substituting Chain for any result of type MVT::Other,...
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.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
constexpr size_t size() const
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.
virtual Align getPrefLoopAlignment(MachineLoop *ML=nullptr, const MachineBasicBlock *BlockToAlign=nullptr) const
Return the preferred loop alignment.
virtual unsigned getMaxPermittedBytesForAlignment(MachineBasicBlock *MBB) const
Return the maximum amount of bytes allowed to be emitted when padding for alignment.
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...
void setOperationPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
Convenience method to set an operation to Promote and specify the type in a single call.
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 setMinFunctionAlignment(Align Alignment)
Set the target's minimum function alignment.
bool isOperationCustom(unsigned Op, EVT VT) const
Return true if the operation uses custom lowering, regardless of whether the type is legal or not.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of a boolean value from i1 to a wider type.
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.
ExtractSubvectorCost
Enum that specifies how expensive lowering an EXTRACT_SUBVECTOR is.
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...
void setPrefFunctionAlignment(Align Alignment)
Set the target's preferred function alignment.
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 allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const
Return true if the target supports a memory access of this type for the given address space and align...
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.
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
SDValue scalarizeVectorStore(StoreSDNode *ST, SelectionDAG &DAG) const
virtual InlineAsm::ConstraintCode getInlineAsmMemConstraint(StringRef ConstraintCode) 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...
virtual void computeKnownBitsForStackObjectPointer(KnownBits &Known, const MachineFunction &MF, Align Alignment) const
Determine known bits of a pointer to a known valid stack object.
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,...
SDValue annotateStackObjectPointer(SDValue Ptr, SelectionDAG &DAG, const SDLoc &DL, Align Alignment) const
Annotate a stack object pointer with known-bits assertions.
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.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
const Triple & getTargetTriple() const
bool shouldAssumeDSOLocal(const GlobalValue *GV) const
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.
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 unsigned getOperandNo() const
Return the operand # of this use in its User.
LLVM_ABI void set(Value *Val)
User * getUser() const
Returns the User that contains this Use.
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.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< user_iterator > users()
iterator_range< use_iterator > uses()
Type * getElementType() const
constexpr ScalarTy getFixedValue() const
constexpr bool isKnownEven() const
A return value of true indicates we know at compile time that the number of elements (vscale * Min) i...
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
#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.
@ BARRIER
Address space for modeling barrier IDs as addresses.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
@ STREAMOUT_REGISTER
Internal address spaces. Can be freely renumbered.
@ VGPR
Address space for VGPRs.
@ 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.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char NumVGPRs[]
Key for Kernel::CodeProps::Metadata::mNumVGPRs.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
APInt getExponentOnlyScaleDemandedBits()
LLVM_READONLY const MIMGG16MappingInfo * getMIMGG16MappingInfo(unsigned G)
bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi)
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)
std::optional< unsigned > getExponentOnlyScaleArgIdx(unsigned IntrID)
constexpr int64_t getNullPointerValue(unsigned AS)
Get the null pointer value for the given address space.
bool isGFX11(const MCSubtargetInfo &STI)
bool isGFX13(const MCSubtargetInfo &STI)
bool hasValueInRangeLikeMetadata(const MDNode &MD, int64_t Val)
Checks if Val is inside MD, a !range-like metadata.
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
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(uint32_t Opcode, OpName NamedIdx)
int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, unsigned VDataDwords, unsigned VAddrDwords, bool IndexedRsrc, bool IndexedSamp)
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)
const BufferIntrinsicInfo * lookupBufferIntrinsic(unsigned Intr)
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 isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi, bool *IsBF16)
TargetExtType * isNamedBarrier(const GlobalVariable &GV)
LLVM_READONLY int32_t getGlobalSaddrOp(uint32_t Opcode)
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)
bool isValidWMMAScaleFmtCombination(unsigned AFmt, unsigned AScale, unsigned BFmt, unsigned BScale)
@ 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 isExtendedGlobalAddrSpace(unsigned AS)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfo(unsigned DimEnum)
unsigned getBarrierMemberCountBitMask(const IsaVersion &Version)
std::optional< unsigned > getInlineEncodingV2BF16(uint32_t Literal)
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
unsigned getSyntheticApertureNumber(unsigned AS)
LLVM_READNONE constexpr bool isChainCC(CallingConv::ID CC)
constexpr unsigned getSDOperandIdx(unsigned Arg, bool HasChain=true)
Convert IR argument index Arg of an intrinsic into an operand index of the INTRINSIC_* SelectionDAG n...
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.
@ 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...
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
@ PTRADD
PTRADD represents pointer arithmetic semantics, for targets that opt in using shouldPreservePtrArith(...
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
@ POISON
POISON - A poison node.
@ SET_FPENV
Sets the current floating-point environment.
@ 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.
@ ATOMIC_STORE
OUTCHAIN = ATOMIC_STORE(INCHAIN, val, ptr) This corresponds to "store atomic" instruction.
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
@ ADD
Simple integer binary arithmetic operators.
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
@ 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.
@ FP16_TO_FP
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
@ CONVERT_FROM_ARBITRARY_FP
CONVERT_FROM_ARBITRARY_FP - This operator converts from an arbitrary floating-point represented as an...
@ SET_ROUNDING
Set rounding mode.
@ CONVERGENCECTRL_GLUE
This does not correspond to any convergence control intrinsic.
@ SIGN_EXTEND
Conversion operators.
@ SCALAR_TO_VECTOR
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
@ BR
Control flow instructions. These all have token chains.
@ PREFETCH
PREFETCH - This corresponds to a prefetch intrinsic.
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ BR_CC
BR_CC - Conditional branch.
@ 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).
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
@ 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.
@ CTLS
Count leading redundant sign bits.
@ 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...
@ GET_FPMODE
Reads the current dynamic floating-point control modes.
@ GET_FPENV
Gets the current floating-point environment.
@ 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.
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Same as FMINNUM/FMAXNUM, except that a signaling NaN operand deterministi...
@ 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.
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
@ FMINNUM
FMINNUM/FMAXNUM - Same semantics as the llvm.minnum/maxnum intrinsics.
@ SMULO
Same for multiplication.
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
@ 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.
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ 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.
@ INLINEASM_BR
INLINEASM_BR - Branching version of inline asm. Used by asm-goto.
@ BF16_TO_FP
BF16_TO_FP, FP_TO_BF16 - These operators are used to perform promotions and truncation for bfloat16.
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
@ FMINIMUM
FMINIMUM/FMAXIMUM - Same semantics as the llvm.minimum/maximum intrinsics.
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
@ 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.
@ TRAP
TRAP - Trapping instruction.
@ 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.
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
@ CTTZ_ZERO_POISON
Bit counting operators with a poisoned result for zero inputs.
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
@ SPONENTRY
SPONENTRY - Represents the llvm.sponentry intrinsic.
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
@ INLINEASM
INLINEASM - Represents an inline asm block.
@ FP_TO_SINT_SAT
FP_TO_[US]INT_SAT - Convert floating point value in operand 0 to a signed or unsigned scalar integer ...
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
@ BRCOND
BRCOND - Conditional branch.
@ CONVERT_TO_ARBITRARY_FP
CONVERT_TO_ARBITRARY_FP - Converts a native FP value to an arbitrary floating-point format,...
@ 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)...
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - Same semantics as the llvm.minimumnum/maximumnum intrinsics.
@ 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,...
CondCode getUnsignedSetCC(CondCode Code)
Convert a signed integer condition code to unsigned.
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 StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
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 * > OverloadTys={})
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)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
auto m_Value()
Match an arbitrary value and ignore it.
auto m_FAbs(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_IntrinsicWOChain(const OpndPreds &...Opnds)
bool sd_match(SDValue N, Pattern &&P)
ConstantInt_match m_ConstInt()
Match any integer constants or splat of an integer constant.
@ System
Synchronized with respect to all concurrently executing threads.
@ User
could "use" a pointer
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< UseNode * > Use
NodeAddr< NodeBase * > Node
friend class Instruction
Iterator for Instructions in a `BasicBlock.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
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.
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.
@ Known
Known to have no common set bits.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Undef
Value of the register doesn't matter.
@ Define
Register definition.
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.
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
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.
SDValue peekFPSignOps(SDValue Val)
Strip fabs/fneg/fcopysign from a value to get the underlying source.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
static const MachineMemOperand::Flags MOCFSB1
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.
static void reportUnsupported(MachineIRBuilder &MIRBuilder, const Twine &Msg)
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
LLVM_ABI ConstantFPSDNode * isConstOrConstSplatFP(SDValue N, bool AllowUndefs=false)
Returns the SDNode if it is a constant splat BuildVector or constant float.
LLVM_ABI bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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...
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
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)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
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.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
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.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI 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.
AtomicOrdering
Atomic ordering for LLVM's memory model.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ 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...
@ Fast
Assign the register banks as fast as possible (default).
DWARFExpression::Operation Op
RoundingMode
Rounding mode.
@ NearestTiesToEven
roundTiesToEven.
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::pair< Value *, Value * > buildCmpXchgValue(IRBuilderBase &Builder, Value *Ptr, Value *Cmp, Value *Val, Align Alignment, bool IsVolatile=false)
Emit IR to implement the given cmpxchg operation on values in registers, returning the new value.
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.
std::optional< StringRef > getAtomicScopeIRString(const Triple &T, AtomicScope S, bool IsSingleAddressSpace=false)
Returns the LLVM IR syncscope string that T uses to spell S.
LLVM_ABI bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
static const MachineMemOperand::Flags MOLastUse
Mark the MMO of a load as the last use.
static const MachineMemOperand::Flags MOCFSB0
Use two MMO flags to encode the 2-bit cache fill size field for GFX13+.
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
constexpr RegState getUndefRegState(bool B)
@ Custom
The result value requires a custom uniformity check.
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.
MCRegisterClass TargetRegisterClass
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
static MCRegister getPrivateSegmentBufferReg(CallingConv::ID CC)
Returns the register a non-entry function with calling convention CC expects the private segment buff...
ArgDescriptor WorkItemIDX
static const AMDGPUFunctionArgInfo FixedABIFunctionInfo
The argument layout of a buffer intrinsic.
std::optional< unsigned > getSizeArg() const
The access size of loads to LDS and prefetches.
std::optional< unsigned > getImmOffsetArg() const
The immediate offset of loads to LDS.
std::optional< unsigned > getAuxArg() const
The auxiliary (cache policy) argument.
std::optional< unsigned > getLDSPtrArg() const
The LDS destination of loads to LDS.
static constexpr uint64_t encode(Fields... Values)
static std::tuple< typename Fields::ValueType... > decode(uint64_t Encoded)
unsigned AtomicNoRetBaseOpcode
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
Represents the full denormal controls for a function, including the default mode and the f32 specific...
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.
ElementCount getVectorElementCount() const
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.
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.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in 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.
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.
EVT changeElementType(LLVMContext &Context, EVT EltVT) const
Return a VT for a type whose attributes match ourselves with the exception of the element type that i...
bool isVectorOf(EVT EltVT) const
Return true if this is a vector with matching element type.
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
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.
unsigned getPointerAddrSpace() const
unsigned getByValSize() const
Align getNonZeroMemAlign() const
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
static LLVM_ABI std::optional< bool > eq(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_EQ result.
bool isUnknown() const
Returns true if we don't know any bits.
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false, bool SelfAdd=false)
Compute knownbits resulting from addition of LHS and RHS.
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
static LLVM_ABI std::optional< bool > ule(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULE result.
static LLVM_ABI std::optional< bool > uge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGE result.
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.
MachinePointerInfo getWithOffset(int64_t O) const
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.
DenormalMode FP64FP16Denormals
If this is set, neither input or output denormals are flushed for both f64 and f16/v2f16 instructions...
DenormalMode FP32Denormals
If this is set, neither input or output denormals are flushed for most f32 instructions.
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...
std::optional< unsigned > fallbackAddressSpace
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