48#include "llvm/IR/IntrinsicsAMDGPU.h"
49#include "llvm/IR/IntrinsicsR600.h"
61#define DEBUG_TYPE "si-lower"
80 unsigned NumSGPRs = AMDGPU::SGPR_32RegClass.getNumRegs();
81 for (
unsigned Reg = 0;
Reg < NumSGPRs; ++
Reg) {
83 return AMDGPU::SGPR0 +
Reg;
99 TRI->getDefaultVectorSuperClassForBitWidth(32);
105 TRI->getDefaultVectorSuperClassForBitWidth(64);
143 TRI->getDefaultVectorSuperClassForBitWidth(320));
147 TRI->getDefaultVectorSuperClassForBitWidth(352));
151 TRI->getDefaultVectorSuperClassForBitWidth(384));
155 TRI->getDefaultVectorSuperClassForBitWidth(512));
162 TRI->getDefaultVectorSuperClassForBitWidth(1024));
164 if (Subtarget->has16BitInsts()) {
165 if (Subtarget->useRealTrue16Insts()) {
195 TRI->getDefaultVectorSuperClassForBitWidth(1024));
211 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
212 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
213 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32,
214 MVT::i1, MVT::v32i32},
218 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
219 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
220 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32,
221 MVT::i1, MVT::v32i32},
239 if (Subtarget->hasBF16PackedInsts()) {
309 {MVT::f32, MVT::i32, MVT::i64, MVT::f64, MVT::i1},
Expand);
316 {MVT::v2i32, MVT::v3i32, MVT::v4i32, MVT::v5i32,
317 MVT::v6i32, MVT::v7i32, MVT::v8i32, MVT::v9i32,
318 MVT::v10i32, MVT::v11i32, MVT::v12i32, MVT::v16i32},
321 {MVT::v2f32, MVT::v3f32, MVT::v4f32, MVT::v5f32,
322 MVT::v6f32, MVT::v7f32, MVT::v8f32, MVT::v9f32,
323 MVT::v10f32, MVT::v11f32, MVT::v12f32, MVT::v16f32},
327 {MVT::v2i1, MVT::v4i1, MVT::v2i8, MVT::v4i8, MVT::v2i16,
328 MVT::v3i16, MVT::v4i16, MVT::Other},
333 {MVT::i1, MVT::i32, MVT::i64, MVT::f32, MVT::f64},
Expand);
349 {MVT::v8i32, MVT::v8f32, MVT::v9i32, MVT::v9f32, MVT::v10i32,
350 MVT::v10f32, MVT::v11i32, MVT::v11f32, MVT::v12i32, MVT::v12f32,
351 MVT::v16i32, MVT::v16f32, MVT::v2i64, MVT::v2f64, MVT::v4i16,
352 MVT::v4f16, MVT::v4bf16, MVT::v3i64, MVT::v3f64, MVT::v6i32,
353 MVT::v6f32, MVT::v4i64, MVT::v4f64, MVT::v8i64, MVT::v8f64,
354 MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16, MVT::v16f16,
355 MVT::v16bf16, MVT::v16i64, MVT::v16f64, MVT::v32i32, MVT::v32f32,
356 MVT::v32i16, MVT::v32f16, MVT::v32bf16}) {
391 for (
MVT Vec64 : {MVT::v2i64, MVT::v2f64}) {
405 for (
MVT Vec64 : {MVT::v3i64, MVT::v3f64}) {
419 for (
MVT Vec64 : {MVT::v4i64, MVT::v4f64}) {
433 for (
MVT Vec64 : {MVT::v8i64, MVT::v8f64}) {
447 for (
MVT Vec64 : {MVT::v16i64, MVT::v16f64}) {
462 {MVT::v4i32, MVT::v4f32, MVT::v8i32, MVT::v8f32,
463 MVT::v16i32, MVT::v16f32, MVT::v32i32, MVT::v32f32},
466 if (Subtarget->hasPkMovB32()) {
487 {MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::v2i8, MVT::v4i8,
488 MVT::v8i8, MVT::v4i16, MVT::v4f16, MVT::v4bf16},
493 {MVT::v3i32, MVT::v3f32, MVT::v4i32, MVT::v4f32},
Custom);
497 {MVT::v5i32, MVT::v5f32, MVT::v6i32, MVT::v6f32,
498 MVT::v7i32, MVT::v7f32, MVT::v8i32, MVT::v8f32,
499 MVT::v9i32, MVT::v9f32, MVT::v10i32, MVT::v10f32,
500 MVT::v11i32, MVT::v11f32, MVT::v12i32, MVT::v12f32},
524 if (Subtarget->hasSMemRealTime() ||
529 if (Subtarget->has16BitInsts()) {
539 if (Subtarget->hasMadMacF32Insts())
557 if (Subtarget->hasIntClamp())
560 if (Subtarget->hasAddNoCarryInsts())
566 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
569 {MVT::f64, MVT::f32},
Legal);
573 {MVT::f64, MVT::f32},
Custom);
578 {MVT::f64, MVT::f32},
Legal);
581 if (Subtarget->haveRoundOpsF64())
611 if (Subtarget->has16BitInsts()) {
659 if (!Subtarget->useRealTrue16Insts() ||
660 !Subtarget->d16PreservesUnusedBits()) {
661 for (
MVT VT : {MVT::i16, MVT::f16, MVT::bf16}) {
667 if (!Subtarget->useRealTrue16Insts()) {
668 for (
MVT VT : {MVT::i16, MVT::f16, MVT::bf16}) {
680 if (Subtarget->hasBF16TransInsts())
696 {MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::v4i16, MVT::v4f16,
697 MVT::v4bf16, MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16,
698 MVT::v16f16, MVT::v16bf16, MVT::v32i16, MVT::v32f16}) {
733 if (Subtarget->hasVCvtPkIU16F32())
736 {MVT::v2i16, MVT::v4i16, MVT::v8i16, MVT::v16i16, MVT::v32i16},
743 {MVT::v2i16, MVT::v2f16, MVT::v2bf16},
Legal);
843 {MVT::v2f16, MVT::v2bf16, MVT::v4f16, MVT::v4bf16,
844 MVT::v8f16, MVT::v8bf16, MVT::v16f16, MVT::v16bf16,
845 MVT::v32f16, MVT::v32bf16},
847 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
854 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
Custom);
865 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
869 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
874 {MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::v16i16, MVT::v16f16,
875 MVT::v16bf16, MVT::v32i16, MVT::v32f16, MVT::v32bf16}) {
882 if (Subtarget->hasVOP3PInsts()) {
893 {MVT::v2i16, MVT::v2f16, MVT::v2bf16},
Custom);
896 {MVT::v4f16, MVT::v4i16, MVT::v4bf16, MVT::v8f16,
897 MVT::v8i16, MVT::v8bf16, MVT::v16f16, MVT::v16i16,
898 MVT::v16bf16, MVT::v32f16, MVT::v32i16, MVT::v32bf16},
901 for (
MVT VT : {MVT::v4i16, MVT::v8i16, MVT::v16i16, MVT::v32i16})
909 for (
MVT VT : {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16})
915 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
925 {MVT::v2f16, MVT::v4f16},
Custom);
931 if (Subtarget->hasBF16PackedInsts()) {
937 for (
MVT VT : {MVT::v4bf16, MVT::v8bf16, MVT::v16bf16, MVT::v32bf16})
945 if (Subtarget->hasAnyPackedFP32Ops()) {
949 {MVT::v4f32, MVT::v8f32, MVT::v16f32, MVT::v32f32},
952 if (Subtarget->hasAnyPackedFP64Ops()) {
958 {MVT::v4f64, MVT::v8f64, MVT::v16f64, MVT::v32f64},
Custom);
960 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
967 {MVT::v4f64, MVT::v8f64, MVT::v16f64, MVT::v32f64},
Custom);
976 {MVT::v4f64, MVT::v8f64, MVT::v16f64, MVT::v32f64},
981 if (Subtarget->hasAnyPackedU64Ops()) {
985 {MVT::v4i64, MVT::v8i64, MVT::v16i64, MVT::v32i64},
992 if (Subtarget->has16BitInsts()) {
1007 {MVT::v4i16, MVT::v4f16, MVT::v4bf16, MVT::v2i8, MVT::v4i8,
1008 MVT::v8i8, MVT::v8i16, MVT::v8f16, MVT::v8bf16,
1009 MVT::v16i16, MVT::v16f16, MVT::v16bf16, MVT::v32i16,
1010 MVT::v32f16, MVT::v32bf16},
1015 if (Subtarget->useVMulU64Inst())
1017 else if (Subtarget->hasScalarSMulU64())
1020 if (Subtarget->hasMad64_32())
1023 if (Subtarget->hasSafeSmemPrefetch() || Subtarget->hasVmemPrefInsts())
1029 if (Subtarget->hasIEEEMinimumMaximumInsts()) {
1031 {MVT::f16, MVT::f32, MVT::f64, MVT::v2f16},
Legal);
1034 if (Subtarget->hasMinimum3Maximum3F32())
1037 if (Subtarget->hasMinimum3Maximum3PKF16()) {
1041 if (!Subtarget->hasMinimum3Maximum3F16())
1047 if (Subtarget->hasVOP3PInsts()) {
1050 {MVT::v4f16, MVT::v8f16, MVT::v16f16, MVT::v32f16},
1054 if (Subtarget->useMinMaxI64Insts())
1059 {MVT::Other, MVT::f32, MVT::v4f32, MVT::i16, MVT::f16,
1060 MVT::bf16, MVT::v2i16, MVT::v2f16, MVT::v2bf16, MVT::i128,
1065 {MVT::v2f16, MVT::v2i16, MVT::v2bf16, MVT::v3f16,
1066 MVT::v3i16, MVT::v4f16, MVT::v4i16, MVT::v4bf16,
1067 MVT::v8i16, MVT::v8f16, MVT::v8bf16, MVT::Other, MVT::f16,
1068 MVT::i16, MVT::bf16, MVT::i8, MVT::i128},
1083 SBufferLoadDiagnosticVTs.set(VT.SimpleTy);
1088 {MVT::Other, MVT::v2i16, MVT::v2f16, MVT::v2bf16,
1089 MVT::v3i16, MVT::v3f16, MVT::v4f16, MVT::v4i16,
1090 MVT::v4bf16, MVT::v8i16, MVT::v8f16, MVT::v8bf16,
1091 MVT::f16, MVT::i16, MVT::bf16, MVT::i8, MVT::i128},
1106 if (Subtarget->hasBF16ConversionInsts()) {
1108 {MVT::bf16, MVT::v2bf16},
Custom);
1112 if (Subtarget->hasBF16TransInsts()) {
1116 const bool HasE5M3ConversionInsts =
1117 Subtarget->hasFP8ConversionInsts() && Subtarget->hasFP8E5M3Insts();
1118 if (Subtarget->hasOCPFP8ConversionInsts() || HasE5M3ConversionInsts) {
1129 if (Subtarget->hasFP8F16ConversionInsts()) {
1134 if (Subtarget->hasCvtPkF16F32Inst()) {
1136 {MVT::v2f16, MVT::v4f16, MVT::v8f16, MVT::v16f16},
1189 if (Subtarget->has16BitInsts() && !Subtarget->hasMed3_16())
1230 static const MCPhysReg RCRegs[] = {AMDGPU::MODE};
1243 EVT DestVT,
EVT SrcVT)
const {
1245 ((((Opcode ==
ISD::FMAD && Subtarget->hasMadMixInsts()) ||
1246 (Opcode ==
ISD::FMA && Subtarget->hasFmaMixInsts())) &&
1248 (Opcode ==
ISD::FMA && Subtarget->hasFmaMixBF16Insts() &&
1255 LLT DestTy,
LLT SrcTy)
const {
1256 return ((Opcode == TargetOpcode::G_FMAD && Subtarget->hasMadMixInsts()) ||
1257 (Opcode == TargetOpcode::G_FMA && Subtarget->hasFmaMixInsts())) &&
1259 SrcTy.getScalarSizeInBits() == 16 &&
1280 return Subtarget->has16BitInsts()
1286 return Subtarget->has16BitInsts() ? MVT::i16 : MVT::i32;
1290 if (!Subtarget->has16BitInsts() && VT.
getSizeInBits() == 16)
1312 return (NumElts + 1) / 2;
1318 return NumElts * ((
Size + 31) / 32);
1327 unsigned &NumIntermediates,
MVT &RegisterVT)
const {
1336 MVT SimpleIntermediateVT =
1338 IntermediateVT = SimpleIntermediateVT;
1339 RegisterVT = Subtarget->has16BitInsts() ? SimpleIntermediateVT : MVT::i32;
1340 NumIntermediates = (NumElts + 1) / 2;
1341 return (NumElts + 1) / 2;
1346 IntermediateVT = RegisterVT;
1347 NumIntermediates = NumElts;
1348 return NumIntermediates;
1353 RegisterVT = MVT::i16;
1354 IntermediateVT = ScalarVT;
1355 NumIntermediates = NumElts;
1356 return NumIntermediates;
1360 RegisterVT = MVT::i32;
1361 IntermediateVT = ScalarVT;
1362 NumIntermediates = NumElts;
1363 return NumIntermediates;
1367 RegisterVT = MVT::i32;
1368 IntermediateVT = RegisterVT;
1369 NumIntermediates = NumElts * ((
Size + 31) / 32);
1370 return NumIntermediates;
1375 Context,
CC, VT, IntermediateVT, NumIntermediates, RegisterVT);
1380 unsigned MaxNumLanes) {
1381 assert(MaxNumLanes != 0);
1385 unsigned NumElts = std::min(MaxNumLanes, VT->getNumElements());
1390 return TLI.getValueType(
DL, Ty);
1396 unsigned MaxNumLanes) {
1402 assert(ST->getNumContainedTypes() == 2 &&
1403 ST->getContainedType(1)->isIntegerTy(32));
1417 return MVT::amdgpuBufferFatPointer;
1419 DL.getPointerSizeInBits(AS) == 192)
1420 return MVT::amdgpuBufferStridedPointer;
1429 DL.getPointerSizeInBits(AS) == 160) ||
1431 DL.getPointerSizeInBits(AS) == 192))
1438 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
1439 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
1440 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1442 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
1443 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
1444 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1445 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
1446 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
1447 case Intrinsic::amdgcn_flat_load_monitor_b32:
1448 case Intrinsic::amdgcn_global_load_monitor_b32:
1450 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
1451 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
1452 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1453 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
1454 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
1455 case Intrinsic::amdgcn_flat_load_monitor_b64:
1456 case Intrinsic::amdgcn_global_load_monitor_b64:
1458 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
1459 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128:
1460 case Intrinsic::amdgcn_global_store_async_from_lds_b128:
1461 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B:
1462 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B:
1463 case Intrinsic::amdgcn_flat_load_monitor_b128:
1464 case Intrinsic::amdgcn_global_load_monitor_b128:
1500 unsigned IntrID)
const {
1502 if (CI.
hasMetadata(LLVMContext::MD_invariant_load))
1518 bool IsSPrefetch = BufInfo && BufInfo->
Kind == AMDGPU::BufferKindPrefetch;
1519 std::optional<unsigned> AuxArg =
1534 if (RsrcIntr->IsImage) {
1549 Info.ptrVal = RsrcArg;
1553 if (RsrcIntr->IsImage) {
1554 unsigned MaxNumLanes = 4;
1569 std::numeric_limits<unsigned>::max());
1579 if (RsrcIntr->IsImage) {
1593 if (BufInfo && BufInfo->
Kind == AMDGPU::BufferKindLoadToLDS) {
1609 CI.
getContext(), Width * 8 * Subtarget->getWavefrontSize());
1619 if (BufInfo && BufInfo->
Kind == AMDGPU::BufferKindAtomicLoad) {
1622 std::numeric_limits<unsigned>::max());
1632 if ((RsrcIntr->IsImage && BaseOpcode->
NoReturn) || IsSPrefetch) {
1634 Info.memVT = MVT::i32;
1647 case Intrinsic::amdgcn_ds_ordered_add:
1648 case Intrinsic::amdgcn_ds_ordered_swap: {
1662 case Intrinsic::amdgcn_ds_add_gs_reg_rtn:
1663 case Intrinsic::amdgcn_ds_sub_gs_reg_rtn: {
1666 Info.ptrVal =
nullptr;
1672 case Intrinsic::amdgcn_ds_append:
1673 case Intrinsic::amdgcn_ds_consume: {
1687 case Intrinsic::amdgcn_ds_atomic_async_barrier_arrive_b64:
1688 case Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64: {
1689 Info.opc = (IntrID == Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64)
1694 Info.memVT = MVT::i64;
1702 case Intrinsic::amdgcn_image_bvh_dual_intersect_ray:
1703 case Intrinsic::amdgcn_image_bvh_intersect_ray:
1704 case Intrinsic::amdgcn_image_bvh8_intersect_ray: {
1707 MVT::getVT(IntrID == Intrinsic::amdgcn_image_bvh_intersect_ray
1710 ->getElementType(0));
1719 case Intrinsic::amdgcn_global_atomic_fmin_num:
1720 case Intrinsic::amdgcn_global_atomic_fmax_num:
1721 case Intrinsic::amdgcn_global_atomic_ordered_add_b64:
1722 case Intrinsic::amdgcn_flat_atomic_fmin_num:
1723 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
1734 case Intrinsic::amdgcn_cluster_load_b32:
1735 case Intrinsic::amdgcn_cluster_load_b64:
1736 case Intrinsic::amdgcn_cluster_load_b128:
1737 case Intrinsic::amdgcn_ds_load_tr6_b96:
1738 case Intrinsic::amdgcn_ds_load_tr4_b64:
1739 case Intrinsic::amdgcn_ds_load_tr8_b64:
1740 case Intrinsic::amdgcn_ds_load_tr16_b128:
1741 case Intrinsic::amdgcn_global_load_tr6_b96:
1742 case Intrinsic::amdgcn_global_load_tr4_b64:
1743 case Intrinsic::amdgcn_global_load_tr_b64:
1744 case Intrinsic::amdgcn_global_load_tr_b128:
1745 case Intrinsic::amdgcn_ds_read_tr4_b64:
1746 case Intrinsic::amdgcn_ds_read_tr6_b96:
1747 case Intrinsic::amdgcn_ds_read_tr8_b64:
1748 case Intrinsic::amdgcn_ds_read_tr16_b64: {
1757 case Intrinsic::amdgcn_flat_load_monitor_b32:
1758 case Intrinsic::amdgcn_flat_load_monitor_b64:
1759 case Intrinsic::amdgcn_flat_load_monitor_b128:
1760 case Intrinsic::amdgcn_global_load_monitor_b32:
1761 case Intrinsic::amdgcn_global_load_monitor_b64:
1762 case Intrinsic::amdgcn_global_load_monitor_b128: {
1773 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
1774 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
1775 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B: {
1786 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
1787 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
1788 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
1799 case Intrinsic::amdgcn_ds_gws_init:
1800 case Intrinsic::amdgcn_ds_gws_barrier:
1801 case Intrinsic::amdgcn_ds_gws_sema_v:
1802 case Intrinsic::amdgcn_ds_gws_sema_br:
1803 case Intrinsic::amdgcn_ds_gws_sema_p:
1804 case Intrinsic::amdgcn_ds_gws_sema_release_all: {
1814 Info.memVT = MVT::i32;
1816 Info.align =
Align(4);
1818 if (IntrID == Intrinsic::amdgcn_ds_gws_barrier)
1825 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
1826 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
1827 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
1828 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
1829 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
1830 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
1831 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
1832 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128: {
1847 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1848 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1849 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1850 case Intrinsic::amdgcn_global_store_async_from_lds_b128: {
1865 case Intrinsic::amdgcn_av_load_b8:
1866 case Intrinsic::amdgcn_av_load_b16:
1867 case Intrinsic::amdgcn_av_load_b32:
1868 case Intrinsic::amdgcn_av_load_b64:
1869 case Intrinsic::amdgcn_av_load_b128:
1870 case Intrinsic::amdgcn_av_store_b8:
1871 case Intrinsic::amdgcn_av_store_b16:
1872 case Intrinsic::amdgcn_av_store_b32:
1873 case Intrinsic::amdgcn_av_store_b64:
1874 case Intrinsic::amdgcn_av_store_b128: {
1880 Info.align =
Align(Info.memVT.getStoreSize());
1889 unsigned ScopeIdx = CI.
arg_size() - 1;
1893 Info.ssid = Ctx.getOrInsertSyncScopeID(Scope);
1897 case Intrinsic::amdgcn_load_to_lds:
1898 case Intrinsic::amdgcn_load_async_to_lds:
1899 case Intrinsic::amdgcn_global_load_lds:
1900 case Intrinsic::amdgcn_global_load_async_lds: {
1919 Width * 8 * Subtarget->getWavefrontSize());
1925 case Intrinsic::amdgcn_ds_bvh_stack_rtn:
1926 case Intrinsic::amdgcn_ds_bvh_stack_push4_pop1_rtn:
1927 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop1_rtn:
1928 case Intrinsic::amdgcn_ds_bvh_stack_push8_pop2_rtn: {
1938 Info.memVT = MVT::i32;
1940 Info.align =
Align(4);
1946 case Intrinsic::amdgcn_s_prefetch_data:
1947 case Intrinsic::amdgcn_s_prefetch_inst:
1948 case Intrinsic::amdgcn_flat_prefetch:
1949 case Intrinsic::amdgcn_global_prefetch: {
1964 Type *&AccessTy)
const {
1965 Value *Ptr =
nullptr;
1966 switch (
II->getIntrinsicID()) {
1967 case Intrinsic::amdgcn_cluster_load_b128:
1968 case Intrinsic::amdgcn_cluster_load_b64:
1969 case Intrinsic::amdgcn_cluster_load_b32:
1970 case Intrinsic::amdgcn_ds_append:
1971 case Intrinsic::amdgcn_ds_consume:
1972 case Intrinsic::amdgcn_ds_load_tr8_b64:
1973 case Intrinsic::amdgcn_ds_load_tr16_b128:
1974 case Intrinsic::amdgcn_ds_load_tr4_b64:
1975 case Intrinsic::amdgcn_ds_load_tr6_b96:
1976 case Intrinsic::amdgcn_ds_read_tr4_b64:
1977 case Intrinsic::amdgcn_ds_read_tr6_b96:
1978 case Intrinsic::amdgcn_ds_read_tr8_b64:
1979 case Intrinsic::amdgcn_ds_read_tr16_b64:
1980 case Intrinsic::amdgcn_ds_ordered_add:
1981 case Intrinsic::amdgcn_ds_ordered_swap:
1982 case Intrinsic::amdgcn_ds_atomic_async_barrier_arrive_b64:
1983 case Intrinsic::amdgcn_ds_atomic_barrier_arrive_rtn_b64:
1984 case Intrinsic::amdgcn_flat_atomic_fmax_num:
1985 case Intrinsic::amdgcn_flat_atomic_fmin_num:
1986 case Intrinsic::amdgcn_global_atomic_fmax_num:
1987 case Intrinsic::amdgcn_global_atomic_fmin_num:
1988 case Intrinsic::amdgcn_global_atomic_ordered_add_b64:
1989 case Intrinsic::amdgcn_global_load_tr_b64:
1990 case Intrinsic::amdgcn_global_load_tr_b128:
1991 case Intrinsic::amdgcn_global_load_tr4_b64:
1992 case Intrinsic::amdgcn_global_load_tr6_b96:
1993 case Intrinsic::amdgcn_global_store_async_from_lds_b8:
1994 case Intrinsic::amdgcn_global_store_async_from_lds_b32:
1995 case Intrinsic::amdgcn_global_store_async_from_lds_b64:
1996 case Intrinsic::amdgcn_global_store_async_from_lds_b128:
1997 case Intrinsic::amdgcn_av_load_b8:
1998 case Intrinsic::amdgcn_av_load_b16:
1999 case Intrinsic::amdgcn_av_load_b32:
2000 case Intrinsic::amdgcn_av_load_b64:
2001 case Intrinsic::amdgcn_av_load_b128:
2002 case Intrinsic::amdgcn_av_store_b8:
2003 case Intrinsic::amdgcn_av_store_b16:
2004 case Intrinsic::amdgcn_av_store_b32:
2005 case Intrinsic::amdgcn_av_store_b64:
2006 case Intrinsic::amdgcn_av_store_b128:
2007 Ptr =
II->getArgOperand(0);
2009 case Intrinsic::amdgcn_load_to_lds:
2010 case Intrinsic::amdgcn_load_async_to_lds:
2011 case Intrinsic::amdgcn_global_load_lds:
2012 case Intrinsic::amdgcn_global_load_async_lds:
2013 case Intrinsic::amdgcn_global_load_async_to_lds_b8:
2014 case Intrinsic::amdgcn_global_load_async_to_lds_b32:
2015 case Intrinsic::amdgcn_global_load_async_to_lds_b64:
2016 case Intrinsic::amdgcn_global_load_async_to_lds_b128:
2017 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
2018 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
2019 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
2020 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128:
2021 Ptr =
II->getArgOperand(1);
2026 AccessTy =
II->getType();
2032 unsigned AddrSpace)
const {
2033 if (!Subtarget->hasFlatInstOffsets()) {
2040 FlatAddrSpace FlatVariant =
2043 : FlatAddrSpace::FLAT;
2045 return AM.
Scale == 0 &&
2046 (AM.
BaseOffs == 0 || Subtarget->getInstrInfo()->isLegalFLATOffset(
2047 AM.
BaseOffs, AddrSpace, FlatVariant));
2051 if (Subtarget->hasFlatGlobalInsts())
2054 if (!Subtarget->hasAddr64() || Subtarget->useFlatForGlobal()) {
2067 return isLegalMUBUFAddressingMode(AM);
2070bool SITargetLowering::isLegalMUBUFAddressingMode(
const AddrMode &AM)
const {
2081 if (!
TII->isLegalMUBUFImmOffset(AM.BaseOffs))
2093 if (AM.HasBaseReg) {
2125 return isLegalMUBUFAddressingMode(AM);
2127 if (!Subtarget->hasScalarSubwordLoads()) {
2132 if (Ty->isSized() &&
DL.getTypeStoreSize(Ty) < 4)
2180 return Subtarget->hasFlatScratchEnabled()
2182 : isLegalMUBUFAddressingMode(AM);
2229 unsigned Size,
unsigned AddrSpace,
Align Alignment,
2238 if (!Subtarget->hasUnalignedDSAccessEnabled() && Alignment <
Align(4))
2241 Align RequiredAlignment(
2243 if (Subtarget->hasLDSMisalignedBugInWGPMode() &&
Size > 32 &&
2244 Alignment < RequiredAlignment)
2259 if (!Subtarget->hasUsableDSOffset() && Alignment <
Align(8))
2265 RequiredAlignment =
Align(4);
2267 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2283 *IsFast = (Alignment >= RequiredAlignment) ? 64
2284 : (Alignment <
Align(4)) ? 32
2291 if (!Subtarget->hasDS96AndDS128())
2297 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2306 *IsFast = (Alignment >= RequiredAlignment) ? 96
2307 : (Alignment <
Align(4)) ? 32
2314 if (!Subtarget->hasDS96AndDS128() || !Subtarget->useDS128())
2320 RequiredAlignment =
Align(8);
2322 if (Subtarget->hasUnalignedDSAccessEnabled()) {
2331 *IsFast = (Alignment >= RequiredAlignment) ? 128
2332 : (Alignment <
Align(4)) ? 32
2349 *IsFast = (Alignment >= RequiredAlignment) ?
Size : 0;
2351 return Alignment >= RequiredAlignment ||
2352 Subtarget->hasUnalignedDSAccessEnabled();
2360 bool AlignedBy4 = Alignment >=
Align(4);
2361 if (Subtarget->hasUnalignedScratchAccessEnabled()) {
2363 *IsFast = AlignedBy4 ?
Size : 1;
2368 *IsFast = AlignedBy4;
2379 return Alignment >=
Align(4) ||
2380 Subtarget->hasUnalignedBufferAccessEnabled();
2393 if (!Subtarget->hasRelaxedBufferOOBMode() &&
2408 return Size >= 32 && Alignment >=
Align(4);
2413 unsigned *IsFast)
const {
2415 Alignment, Flags, IsFast);
2420 unsigned AddrSpace,
Align Alignment,
2422 unsigned *IsFast)
const {
2428 Alignment, Flags, IsFast);
2439 if (
Op.size() >= 16 &&
2443 if (
Op.size() >= 8 &&
Op.isDstAligned(
Align(4)))
2461 unsigned DestAS)
const {
2464 Subtarget->hasGloballyAddressableScratch()) {
2495 unsigned Index)
const {
2509 unsigned MinAlign = Subtarget->useRealTrue16Insts() ? 16 : 32;
2514 if (Subtarget->has16BitInsts() && VT == MVT::i16) {
2548 if (Subtarget->hasScalarSubwordLoads() &&
N->getOpcode() ==
ISD::LOAD &&
2599 auto [InputPtrReg, RC, ArgTy] =
2609 Chain, SL,
MRI.getLiveInVirtReg(InputPtrReg->getRegister()), PtrVT);
2615 const SDLoc &SL)
const {
2622 const SDLoc &SL)
const {
2625 std::optional<uint32_t> KnownSize =
2627 if (KnownSize.has_value())
2654 Val = getFPExtOrFPRound(DAG, Val, SL, VT);
2669SDValue SITargetLowering::lowerKernargMemParameter(
2674 MachinePointerInfo PtrInfo =
2683 int64_t OffsetDiff =
Offset - AlignDownOffset;
2689 SDValue Ptr = lowerKernArgParameterPtr(DAG, SL, Chain, AlignDownOffset);
2700 ArgVal = convertArgType(DAG, VT, MemVT, SL, ArgVal,
Signed, Arg);
2705 SDValue Ptr = lowerKernArgParameterPtr(DAG, SL, Chain,
Offset);
2719 const SDLoc &SL)
const {
2766 MachinePointerInfo PtrInfo =
2792 SDValue ConvertedVal = convertABITypeToValueType(DAG, ArgValue, VA, SL);
2793 if (ConvertedVal == ArgValue)
2794 return ConvertedVal;
2806 DAG.
getMachineNode(AMDGPU::S_GETREG_B32_const, SL, VT, ClusterIdField);
2810SDValue SITargetLowering::lowerWorkGroupId(
2815 if (!Subtarget->hasClusters())
2816 return getPreloadedValue(DAG, MFI, VT, WorkGroupIdPV);
2824 SDValue ClusterIdXYZ = getPreloadedValue(DAG, MFI, VT, WorkGroupIdPV);
2825 SDLoc SL(ClusterIdXYZ);
2826 SDValue ClusterMaxIdXYZ = getPreloadedValue(DAG, MFI, VT, ClusterMaxIdPV);
2829 SDValue ClusterWorkGroupIdXYZ =
2830 getPreloadedValue(DAG, MFI, VT, ClusterWorkGroupIdPV);
2840 return ClusterIdXYZ;
2852SDValue SITargetLowering::lowerClusterWorkGroupValue(
2855 if (!Subtarget->hasClusters())
2864 return getPreloadedValue(DAG, MFI, VT, PV);
2880SDValue SITargetLowering::getPreloadedValue(
2883 const ArgDescriptor *
Reg =
nullptr;
2888 const ArgDescriptor WorkGroupIDX =
2896 const ArgDescriptor WorkGroupIDZ =
2898 const ArgDescriptor ClusterWorkGroupIDX =
2900 const ArgDescriptor ClusterWorkGroupIDY =
2902 const ArgDescriptor ClusterWorkGroupIDZ =
2904 const ArgDescriptor ClusterWorkGroupMaxIDX =
2906 const ArgDescriptor ClusterWorkGroupMaxIDY =
2908 const ArgDescriptor ClusterWorkGroupMaxIDZ =
2910 const ArgDescriptor ClusterWorkGroupMaxFlatID =
2913 auto LoadConstant = [&](
unsigned N) {
2917 if (Subtarget->hasArchitectedSGPRs() &&
2925 Reg = &WorkGroupIDX;
2926 RC = &AMDGPU::SReg_32RegClass;
2930 Reg = &WorkGroupIDY;
2931 RC = &AMDGPU::SReg_32RegClass;
2935 Reg = &WorkGroupIDZ;
2936 RC = &AMDGPU::SReg_32RegClass;
2940 if (HasFixedDims && ClusterDims.
getDims()[0] == 1)
2941 return LoadConstant(0);
2942 Reg = &ClusterWorkGroupIDX;
2943 RC = &AMDGPU::SReg_32RegClass;
2947 if (HasFixedDims && ClusterDims.
getDims()[1] == 1)
2948 return LoadConstant(0);
2949 Reg = &ClusterWorkGroupIDY;
2950 RC = &AMDGPU::SReg_32RegClass;
2954 if (HasFixedDims && ClusterDims.
getDims()[2] == 1)
2955 return LoadConstant(0);
2956 Reg = &ClusterWorkGroupIDZ;
2957 RC = &AMDGPU::SReg_32RegClass;
2962 return LoadConstant(ClusterDims.
getDims()[0] - 1);
2963 Reg = &ClusterWorkGroupMaxIDX;
2964 RC = &AMDGPU::SReg_32RegClass;
2969 return LoadConstant(ClusterDims.
getDims()[1] - 1);
2970 Reg = &ClusterWorkGroupMaxIDY;
2971 RC = &AMDGPU::SReg_32RegClass;
2976 return LoadConstant(ClusterDims.
getDims()[2] - 1);
2977 Reg = &ClusterWorkGroupMaxIDZ;
2978 RC = &AMDGPU::SReg_32RegClass;
2983 const std::array<unsigned, 3> &Dims = ClusterDims.
getDims();
2984 return LoadConstant(Dims[0] * Dims[1] * Dims[2] - 1);
2986 Reg = &ClusterWorkGroupMaxFlatID;
2987 RC = &AMDGPU::SReg_32RegClass;
3018 for (
unsigned I = 0,
E = Ins.
size(), PSInputNum = 0;
I !=
E; ++
I) {
3022 "vector type argument should have been split");
3027 bool SkipArg = !Arg->
Used && !Info->isPSInputAllocated(PSInputNum);
3035 "unexpected vector split in ps argument type");
3049 Info->markPSInputAllocated(PSInputNum);
3051 Info->markPSInputEnabled(PSInputNum);
3067 if (Info.hasWorkItemIDX()) {
3069 MRI.setType(MF.
addLiveIn(Reg, &AMDGPU::VGPR_32RegClass), I32);
3073 (Subtarget->hasPackedTID() && Info.hasWorkItemIDY()) ? 0x3ff : ~0u;
3077 if (Info.hasWorkItemIDY()) {
3078 assert(Info.hasWorkItemIDX());
3079 if (Subtarget->hasPackedTID()) {
3080 Info.setWorkItemIDY(
3083 unsigned Reg = AMDGPU::VGPR1;
3084 MRI.setType(MF.
addLiveIn(Reg, &AMDGPU::VGPR_32RegClass), I32);
3091 if (Info.hasWorkItemIDZ()) {
3092 assert(Info.hasWorkItemIDX() && Info.hasWorkItemIDY());
3093 if (Subtarget->hasPackedTID()) {
3094 Info.setWorkItemIDZ(
3097 unsigned Reg = AMDGPU::VGPR2;
3098 MRI.setType(MF.
addLiveIn(Reg, &AMDGPU::VGPR_32RegClass), I32);
3108 unsigned NumArgRegs) {
3111 if (RegIdx == ArgSGPRs.
size())
3114 unsigned Reg = ArgSGPRs[RegIdx];
3159 const unsigned Mask = 0x3ff;
3168 auto &
ArgInfo = Info.getArgInfo();
3180 if (Info.hasImplicitArgPtr())
3188 if (Info.hasWorkGroupIDX())
3191 if (Info.hasWorkGroupIDY())
3194 if (Info.hasWorkGroupIDZ())
3197 if (Info.hasLDSKernelId())
3208 Register ImplicitBufferPtrReg = Info.addImplicitBufferPtr(
TRI);
3209 MF.
addLiveIn(ImplicitBufferPtrReg, &AMDGPU::SGPR_64RegClass);
3215 Register PrivateSegmentBufferReg = Info.addPrivateSegmentBuffer(
TRI);
3216 MF.
addLiveIn(PrivateSegmentBufferReg, &AMDGPU::SGPR_128RegClass);
3221 Register DispatchPtrReg = Info.addDispatchPtr(
TRI);
3222 MF.
addLiveIn(DispatchPtrReg, &AMDGPU::SGPR_64RegClass);
3228 MF.
addLiveIn(QueuePtrReg, &AMDGPU::SGPR_64RegClass);
3234 Register InputPtrReg = Info.addKernargSegmentPtr(
TRI);
3243 MF.
addLiveIn(DispatchIDReg, &AMDGPU::SGPR_64RegClass);
3248 Register FlatScratchInitReg = Info.addFlatScratchInit(
TRI);
3249 MF.
addLiveIn(FlatScratchInitReg, &AMDGPU::SGPR_64RegClass);
3254 Register PrivateSegmentSizeReg = Info.addPrivateSegmentSize(
TRI);
3255 MF.
addLiveIn(PrivateSegmentSizeReg, &AMDGPU::SGPR_32RegClass);
3270 unsigned LastExplicitArgOffset = Subtarget->getExplicitKernelArgOffset();
3272 bool InPreloadSequence =
true;
3274 bool AlignedForImplictArgs =
false;
3275 unsigned ImplicitArgOffset = 0;
3276 for (
auto &Arg :
F.args()) {
3277 if (!InPreloadSequence || !Arg.hasInRegAttr())
3280 unsigned ArgIdx = Arg.getArgNo();
3283 if (InIdx < Ins.
size() &&
3284 (!Ins[InIdx].isOrigArg() || Ins[InIdx].getOrigArgIndex() != ArgIdx))
3287 for (; InIdx < Ins.
size() && Ins[InIdx].isOrigArg() &&
3288 Ins[InIdx].getOrigArgIndex() == ArgIdx;
3290 assert(ArgLocs[ArgIdx].isMemLoc());
3291 auto &ArgLoc = ArgLocs[InIdx];
3293 unsigned ArgOffset = ArgLoc.getLocMemOffset();
3295 unsigned NumAllocSGPRs =
3296 alignTo(ArgLoc.getLocVT().getFixedSizeInBits(), 32) / 32;
3299 if (Arg.hasAttribute(
"amdgpu-hidden-argument")) {
3300 if (!AlignedForImplictArgs) {
3302 alignTo(LastExplicitArgOffset,
3303 Subtarget->getAlignmentForImplicitArgPtr()) -
3304 LastExplicitArgOffset;
3305 AlignedForImplictArgs =
true;
3307 ArgOffset += ImplicitArgOffset;
3311 if (ArgLoc.getLocVT().getStoreSize() < 4 && Alignment < 4) {
3312 assert(InIdx >= 1 &&
"No previous SGPR");
3313 Info.getArgInfo().PreloadKernArgs[InIdx].Regs.push_back(
3314 Info.getArgInfo().PreloadKernArgs[InIdx - 1].Regs[0]);
3318 unsigned Padding = ArgOffset - LastExplicitArgOffset;
3319 unsigned PaddingSGPRs =
alignTo(Padding, 4) / 4;
3322 InPreloadSequence =
false;
3328 TRI.getSGPRClassForBitWidth(NumAllocSGPRs * 32);
3330 Info.addPreloadedKernArg(
TRI, RC, NumAllocSGPRs, InIdx, PaddingSGPRs);
3332 if (PreloadRegs->
size() > 1)
3333 RC = &AMDGPU::SGPR_32RegClass;
3334 for (
auto &Reg : *PreloadRegs) {
3340 LastExplicitArgOffset = NumAllocSGPRs * 4 + ArgOffset;
3349 if (Info.hasLDSKernelId()) {
3350 Register Reg = Info.addLDSKernelId();
3351 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3360 bool IsShader)
const {
3361 bool HasArchitectedSGPRs = Subtarget->hasArchitectedSGPRs();
3362 if (Subtarget->hasUserSGPRInit16BugInWave32() && !IsShader) {
3368 assert(!HasArchitectedSGPRs &&
"Unhandled feature for the subtarget");
3370 unsigned CurrentUserSGPRs = Info.getNumUserSGPRs();
3374 unsigned NumRequiredSystemSGPRs =
3375 Info.hasWorkGroupIDX() + Info.hasWorkGroupIDY() +
3376 Info.hasWorkGroupIDZ() + Info.hasWorkGroupInfo();
3377 for (
unsigned i = NumRequiredSystemSGPRs + CurrentUserSGPRs; i < 16; ++i) {
3378 Register Reg = Info.addReservedUserSGPR();
3379 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3384 if (!HasArchitectedSGPRs) {
3385 if (Info.hasWorkGroupIDX()) {
3386 Register Reg = Info.addWorkGroupIDX();
3387 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3391 if (Info.hasWorkGroupIDY()) {
3392 Register Reg = Info.addWorkGroupIDY();
3393 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3397 if (Info.hasWorkGroupIDZ()) {
3398 Register Reg = Info.addWorkGroupIDZ();
3399 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3404 if (Info.hasWorkGroupInfo()) {
3405 Register Reg = Info.addWorkGroupInfo();
3406 MF.
addLiveIn(Reg, &AMDGPU::SGPR_32RegClass);
3410 if (Info.hasPrivateSegmentWaveByteOffset()) {
3412 unsigned PrivateSegmentWaveByteOffsetReg;
3415 PrivateSegmentWaveByteOffsetReg =
3416 Info.getPrivateSegmentWaveByteOffsetSystemSGPR();
3420 if (PrivateSegmentWaveByteOffsetReg == AMDGPU::NoRegister) {
3422 Info.setPrivateSegmentWaveByteOffset(PrivateSegmentWaveByteOffsetReg);
3425 PrivateSegmentWaveByteOffsetReg = Info.addPrivateSegmentWaveByteOffset();
3427 MF.
addLiveIn(PrivateSegmentWaveByteOffsetReg, &AMDGPU::SGPR_32RegClass);
3428 CCInfo.
AllocateReg(PrivateSegmentWaveByteOffsetReg);
3431 assert(!Subtarget->hasUserSGPRInit16BugInWave32() || IsShader ||
3432 Info.getNumPreloadedSGPRs() >= 16);
3447 if (HasStackObjects)
3448 Info.setHasNonSpillStackObjects(
true);
3453 HasStackObjects =
true;
3457 bool RequiresStackAccess = HasStackObjects || MFI.
hasCalls();
3459 if (!ST.hasFlatScratchEnabled()) {
3460 if (RequiresStackAccess && ST.isAmdHsaOrMesa(MF.
getFunction())) {
3467 Info.setScratchRSrcReg(PrivateSegmentBufferReg);
3469 unsigned ReservedBufferReg =
TRI.reservedPrivateSegmentBufferReg(MF);
3479 Info.setScratchRSrcReg(ReservedBufferReg);
3498 if (!
MRI.isLiveIn(AMDGPU::SGPR32)) {
3499 Info.setStackPtrOffsetReg(AMDGPU::SGPR32);
3506 for (
unsigned Reg : AMDGPU::SGPR_32RegClass) {
3507 if (!
MRI.isLiveIn(
Reg)) {
3508 Info.setStackPtrOffsetReg(
Reg);
3513 if (Info.getStackPtrOffsetReg() == AMDGPU::SP_REG)
3520 if (ST.getFrameLowering()->hasFP(MF)) {
3521 Info.setFrameOffsetReg(AMDGPU::SGPR33);
3537 const MCPhysReg *IStart =
TRI->getCalleeSavedRegsViaCopy(Entry->getParent());
3546 if (AMDGPU::SReg_64RegClass.
contains(*
I))
3547 RC = &AMDGPU::SGPR_64RegClass;
3548 else if (AMDGPU::SReg_32RegClass.
contains(*
I))
3549 RC = &AMDGPU::SGPR_32RegClass;
3555 Entry->addLiveIn(*
I);
3560 for (
auto *Exit : Exits)
3562 TII->get(TargetOpcode::COPY), *
I)
3577 bool IsError =
false;
3581 Fn,
"unsupported non-compute shaders with HSA",
DL.getDebugLoc()));
3599 !Info->hasLDSKernelId() && !Info->hasWorkItemIDX() &&
3600 !Info->hasWorkItemIDY() && !Info->hasWorkItemIDZ());
3602 if (!Subtarget->hasFlatScratchEnabled())
3607 !Subtarget->hasArchitectedSGPRs())
3608 assert(!Info->hasWorkGroupIDX() && !Info->hasWorkGroupIDY() &&
3609 !Info->hasWorkGroupIDZ());
3612 bool IsWholeWaveFunc = Info->isWholeWaveFunction();
3630 if ((Info->getPSInputAddr() & 0x7F) == 0 ||
3631 ((Info->getPSInputAddr() & 0xF) == 0 && Info->isPSInputAllocated(11))) {
3634 Info->markPSInputAllocated(0);
3635 Info->markPSInputEnabled(0);
3637 if (Subtarget->isAmdPalOS()) {
3646 unsigned PsInputBits = Info->getPSInputAddr() & Info->getPSInputEnable();
3647 if ((PsInputBits & 0x7F) == 0 ||
3648 ((PsInputBits & 0xF) == 0 && (PsInputBits >> 11 & 1)))
3651 }
else if (IsKernel) {
3652 assert(Info->hasWorkGroupIDX() && Info->hasWorkItemIDX());
3664 if (IsKernel && Subtarget->hasKernargPreload())
3668 }
else if (!IsGraphics) {
3673 if (!Subtarget->hasFlatScratchEnabled())
3685 Info->setNumWaveDispatchSGPRs(
3687 Info->setNumWaveDispatchVGPRs(
3689 }
else if (Info->getNumKernargPreloadedSGPRs()) {
3690 Info->setNumWaveDispatchSGPRs(Info->getNumUserSGPRs());
3695 if (IsWholeWaveFunc) {
3697 {MVT::i1, MVT::Other}, Chain);
3709 for (
unsigned i = IsWholeWaveFunc ? 1 : 0, e = Ins.
size(), ArgIdx = 0; i != e;
3720 if (IsEntryFunc && VA.
isMemLoc()) {
3744 if (Arg.
isOrigArg() && Info->getArgInfo().PreloadKernArgs.count(i)) {
3748 int64_t OffsetDiff =
Offset - AlignDownOffset;
3755 Info->getArgInfo().PreloadKernArgs.find(i)->getSecond().Regs[0];
3766 NewArg = convertArgType(DAG, VT, MemVT,
DL, ArgVal,
3767 Ins[i].Flags.isSExt(), &Ins[i]);
3775 Info->getArgInfo().PreloadKernArgs.find(i)->getSecond().Regs;
3778 if (PreloadRegs.
size() == 1) {
3779 Register VReg =
MRI.getLiveInVirtReg(PreloadRegs[0]);
3784 TRI->getRegSizeInBits(*RC)));
3792 for (
auto Reg : PreloadRegs) {
3799 PreloadRegs.size()),
3816 NewArg = convertArgType(DAG, VT, MemVT,
DL, NewArg,
3817 Ins[i].Flags.isSExt(), &Ins[i]);
3829 "hidden argument in kernel signature was not preloaded",
3835 lowerKernargMemParameter(DAG, VT, MemVT,
DL, Chain,
Offset,
3836 Alignment, Ins[i].Flags.isSExt(), &Ins[i]);
3856 if (!IsEntryFunc && VA.
isMemLoc()) {
3857 SDValue Val = lowerStackParameter(DAG, VA,
DL, Chain, Arg);
3868 if (AMDGPU::VGPR_32RegClass.
contains(Reg))
3869 RC = &AMDGPU::VGPR_32RegClass;
3870 else if (AMDGPU::SGPR_32RegClass.
contains(Reg))
3871 RC = &AMDGPU::SGPR_32RegClass;
3877 if (Arg.
Flags.
isInReg() && RC == &AMDGPU::VGPR_32RegClass) {
3883 ReadFirstLane, Val);
3892 Val = convertABITypeToValueType(DAG, Val, VA,
DL);
3901 Info->setBytesInStackArgArea(StackArgSize);
3903 return Chains.
empty() ? Chain
3912 const Type *RetTy)
const {
3920 CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
3925 unsigned MaxNumVGPRs = Subtarget->getMaxNumVGPRs(MF);
3926 unsigned TotalNumVGPRs = Subtarget->getAddressableNumArchVGPRs();
3927 for (
unsigned i = MaxNumVGPRs; i < TotalNumVGPRs; ++i)
3928 if (CCInfo.
isAllocated(AMDGPU::VGPR_32RegClass.getRegister(i)))
3951 Info->setIfReturnsVoid(Outs.
empty());
3952 bool IsWaveEnd = Info->returnsVoid() && IsShader;
3971 for (
unsigned I = 0, RealRVLocIdx = 0, E = RVLocs.
size();
I != E;
3972 ++
I, ++RealRVLocIdx) {
3976 SDValue Arg = OutVals[RealRVLocIdx];
4000 ReadFirstLane, Arg);
4007 if (!Info->isEntryFunction()) {
4013 if (AMDGPU::SReg_64RegClass.
contains(*
I))
4015 else if (AMDGPU::SReg_32RegClass.
contains(*
I))
4028 unsigned Opc = AMDGPUISD::ENDPGM;
4030 Opc = Info->isWholeWaveFunction() ? AMDGPUISD::WHOLE_WAVE_RETURN
4031 : IsShader ? AMDGPUISD::RETURN_TO_EPILOG
4032 : AMDGPUISD::RET_GLUE;
4063 Val = convertABITypeToValueType(DAG, Val, VA,
DL);
4116 const auto [OutgoingArg, ArgRC, ArgTy] =
4121 const auto [IncomingArg, IncomingArgRC, Ty] =
4123 assert(IncomingArgRC == ArgRC);
4126 EVT ArgVT =
TRI->getSpillSize(*ArgRC) == 8 ? MVT::i64 : MVT::i32;
4134 InputReg = getImplicitArgPtr(DAG,
DL);
4136 std::optional<uint32_t> Id =
4138 if (Id.has_value()) {
4149 if (OutgoingArg->isRegister()) {
4150 RegsToPass.emplace_back(OutgoingArg->getRegister(), InputReg);
4151 if (!CCInfo.
AllocateReg(OutgoingArg->getRegister()))
4154 unsigned SpecialArgOffset =
4165 auto [OutgoingArg, ArgRC, Ty] =
4168 std::tie(OutgoingArg, ArgRC, Ty) =
4171 std::tie(OutgoingArg, ArgRC, Ty) =
4186 const bool NeedWorkItemIDX = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-x");
4187 const bool NeedWorkItemIDY = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-y");
4188 const bool NeedWorkItemIDZ = !CLI.
CB->
hasFnAttr(
"amdgpu-no-workitem-id-z");
4193 if (Subtarget->getMaxWorkitemID(
F, 0) != 0) {
4201 NeedWorkItemIDY && Subtarget->getMaxWorkitemID(
F, 1) != 0) {
4211 NeedWorkItemIDZ && Subtarget->getMaxWorkitemID(
F, 2) != 0) {
4220 if (!InputReg && (NeedWorkItemIDX || NeedWorkItemIDY || NeedWorkItemIDZ)) {
4221 if (!IncomingArgX && !IncomingArgY && !IncomingArgZ) {
4232 : IncomingArgY ? *IncomingArgY
4239 if (OutgoingArg->isRegister()) {
4241 RegsToPass.emplace_back(OutgoingArg->getRegister(), InputReg);
4267 if (Callee->isDivergent())
4274 const uint32_t *CallerPreserved =
TRI->getCallPreservedMask(MF, CallerCC);
4278 if (!CallerPreserved)
4281 bool CCMatch = CallerCC == CalleeCC;
4294 if (Arg.hasByValAttr())
4308 const uint32_t *CalleePreserved =
TRI->getCallPreservedMask(MF, CalleeCC);
4309 if (!
TRI->regmaskSubsetEqual(CallerPreserved, CalleePreserved))
4318 CCState CCInfo(CalleeCC, IsVarArg, MF, ArgLocs, Ctx);
4331 for (
const auto &[CCVA, ArgVal] :
zip_equal(ArgLocs, OutVals)) {
4333 if (!CCVA.isRegLoc())
4338 if (ArgVal->
isDivergent() &&
TRI->isSGPRPhysReg(CCVA.getLocReg())) {
4340 dbgs() <<
"Cannot tail call due to divergent outgoing argument in "
4364enum ChainCallArgIdx {
4386 bool UsesDynamicVGPRs =
false;
4387 if (IsChainCallConv) {
4392 auto RequestedExecIt =
4394 return Arg.OrigArgIndex == 2;
4396 assert(RequestedExecIt != CLI.
Outs.end() &&
"No node for EXEC");
4398 size_t SpecialArgsBeginIdx = RequestedExecIt - CLI.
Outs.begin();
4401 CLI.
Outs.erase(RequestedExecIt, CLI.
Outs.end());
4404 "Haven't popped all the special args");
4407 CLI.
Args[ChainCallArgIdx::Exec];
4408 if (!RequestedExecArg.
Ty->
isIntegerTy(Subtarget->getWavefrontSize()))
4416 ArgNode->getAPIntValue(),
DL, ArgNode->getValueType(0)));
4418 ChainCallSpecialArgs.
push_back(Arg.Node);
4421 PushNodeOrTargetConstant(RequestedExecArg);
4427 if (FlagsValue.
isZero()) {
4428 if (CLI.
Args.size() > ChainCallArgIdx::Flags + 1)
4430 "no additional args allowed if flags == 0");
4432 if (CLI.
Args.size() != ChainCallArgIdx::FallbackCallee + 1) {
4436 if (!Subtarget->isWave32()) {
4438 CLI, InVals,
"dynamic VGPR mode is only supported for wave32");
4441 UsesDynamicVGPRs =
true;
4442 std::for_each(CLI.
Args.begin() + ChainCallArgIdx::NumVGPRs,
4443 CLI.
Args.end(), PushNodeOrTargetConstant);
4452 bool IsSibCall =
false;
4466 "unsupported call to variadic function ");
4474 "unsupported required tail call to function ");
4479 Outs, OutVals, Ins, DAG);
4483 "site marked musttail or on llvm.amdgcn.cs.chain");
4490 if (!TailCallOpt && IsTailCall)
4514 if (!Subtarget->hasFlatScratchEnabled()) {
4537 auto *
TRI = Subtarget->getRegisterInfo();
4544 if (!IsSibCall || IsChainCallConv) {
4545 if (!Subtarget->hasFlatScratchEnabled()) {
4551 RegsToPass.emplace_back(
4559 const unsigned NumSpecialInputs = RegsToPass.size();
4561 MVT PtrVT = MVT::i32;
4564 for (
unsigned i = 0, e = ArgLocs.
size(); i != e; ++i) {
4593 RegsToPass.push_back(std::pair(VA.
getLocReg(), Arg));
4601 int32_t
Offset = LocMemOffset;
4608 unsigned OpSize = Flags.isByVal() ? Flags.getByValSize()
4614 ? Flags.getNonZeroByValAlign()
4641 if (Outs[i].Flags.isByVal()) {
4643 DAG.
getConstant(Outs[i].Flags.getByValSize(),
DL, MVT::i32);
4646 Outs[i].Flags.getNonZeroByValAlign(),
4647 Outs[i].Flags.getNonZeroByValAlign(),
4649 nullptr, std::nullopt, DstInfo,
4655 DAG.
getStore(Chain,
DL, Arg, DstAddr, DstInfo, Alignment);
4661 if (!MemOpChains.
empty())
4677 unsigned ArgIdx = 0;
4678 for (
auto [Reg, Val] : RegsToPass) {
4679 if (ArgIdx++ >= NumSpecialInputs &&
4680 (IsChainCallConv || !Val->
isDivergent()) &&
TRI->isSGPRPhysReg(Reg)) {
4706 if (IsTailCall && !IsSibCall) {
4711 std::vector<SDValue>
Ops({Chain});
4717 Ops.push_back(Callee);
4734 Ops.push_back(Callee);
4745 if (IsChainCallConv)
4750 for (
auto &[Reg, Val] : RegsToPass)
4754 const uint32_t *Mask =
TRI->getCallPreservedMask(MF, CallConv);
4755 assert(Mask &&
"Missing call preserved mask for calling convention");
4765 MVT::Glue, GlueOps),
4770 Ops.push_back(InGlue);
4776 unsigned OPC = AMDGPUISD::TC_RETURN;
4779 OPC = AMDGPUISD::TC_RETURN_GFX;
4783 OPC = UsesDynamicVGPRs ? AMDGPUISD::TC_RETURN_CHAIN_DVGPR
4784 : AMDGPUISD::TC_RETURN_CHAIN;
4790 if (Info->isWholeWaveFunction())
4791 OPC = AMDGPUISD::TC_RETURN_GFX_WholeWave;
4801 Chain =
Call.getValue(0);
4802 InGlue =
Call.getValue(1);
4804 uint64_t CalleePopBytes = NumBytes;
4825 EVT VT =
Op.getValueType();
4839 "Stack grows upwards for AMDGPU");
4841 Chain = BaseAddr.getValue(1);
4843 const bool HasFlatScratch = Subtarget->hasFlatScratchEnabled();
4844 const unsigned WavefrontSizeLog2 = Subtarget->getWavefrontSizeLog2();
4847 if (Alignment > StackAlign) {
4848 uint64_t ScaledAlignment = Alignment.value()
4849 << (HasFlatScratch ? 0 : WavefrontSizeLog2);
4850 uint64_t StackAlignMask = ScaledAlignment - 1;
4857 assert(
Size.getValueType() == MVT::i32 &&
"Size must be 32-bit");
4866 DAG.
getConstant(WavefrontSizeLog2, dl, MVT::i32));
4877 if (!HasFlatScratch) {
4880 DAG.
getConstant(WavefrontSizeLog2, dl, MVT::i32));
4897 if (
Op.getValueType() != MVT::i32)
4916 assert(
Op.getValueType() == MVT::i32);
4925 Op.getOperand(0), IntrinID, GetRoundBothImm);
4959 SDValue RoundModeTimesNumBits =
4979 TableEntry, EnumOffset);
4995 static_cast<uint32_t>(ConstMode->getZExtValue()),
5007 if (UseReducedTable) {
5013 SDValue RoundModeTimesNumBits =
5033 SDValue RoundModeTimesNumBits =
5042 NewMode = TruncTable;
5051 ReadFirstLaneID, NewMode);
5064 IntrinID, RoundBothImm, NewMode);
5072 return Op.getOperand(0);
5077 if (!Subtarget->hasSafeSmemPrefetch() && !
Op.getConstantOperandVal(4))
5086 SDValue Src =
Op.getOperand(IsStrict ? 1 : 0);
5087 EVT SrcVT = Src.getValueType();
5096 EVT DstVT =
Op.getValueType();
5105 if (
Op.getValueType() != MVT::i64)
5119 Op.getOperand(0), IntrinID, ModeHwRegImm);
5121 Op.getOperand(0), IntrinID, TrapHwRegImm);
5135 if (
Op.getOperand(1).getValueType() != MVT::i64)
5147 ReadFirstLaneID, NewModeReg);
5149 ReadFirstLaneID, NewTrapReg);
5151 unsigned ModeHwReg =
5154 unsigned TrapHwReg =
5162 IntrinID, ModeHwRegImm, NewModeReg);
5165 IntrinID, TrapHwRegImm, NewTrapReg);
5173 .
Case(
"m0", AMDGPU::M0)
5174 .
Case(
"exec", AMDGPU::EXEC)
5175 .
Case(
"exec_lo", AMDGPU::EXEC_LO)
5176 .
Case(
"exec_hi", AMDGPU::EXEC_HI)
5177 .
Case(
"flat_scratch", AMDGPU::FLAT_SCR)
5178 .
Case(
"flat_scratch_lo", AMDGPU::FLAT_SCR_LO)
5179 .
Case(
"flat_scratch_hi", AMDGPU::FLAT_SCR_HI)
5180 .
Case(
"src_flat_scratch_base", AMDGPU::SRC_FLAT_SCRATCH_BASE)
5181 .
Case(
"src_flat_scratch_base_lo", AMDGPU::SRC_FLAT_SCRATCH_BASE_LO)
5182 .
Case(
"src_flat_scratch_base_hi", AMDGPU::SRC_FLAT_SCRATCH_BASE_HI)
5188 if (!Subtarget->hasFlatScrRegister() &&
5189 TRI->regsOverlap(Reg, AMDGPU::FLAT_SCR))
5192 if (!Subtarget->hasGloballyAddressableScratch() &&
5193 TRI->regsOverlap(Reg, AMDGPU::SRC_FLAT_SCRATCH_BASE))
5198 case AMDGPU::EXEC_LO:
5199 case AMDGPU::EXEC_HI:
5200 case AMDGPU::FLAT_SCR_LO:
5201 case AMDGPU::FLAT_SCR_HI:
5202 case AMDGPU::SRC_FLAT_SCRATCH_BASE_LO:
5203 case AMDGPU::SRC_FLAT_SCRATCH_BASE_HI:
5208 case AMDGPU::FLAT_SCR:
5209 case AMDGPU::SRC_FLAT_SCRATCH_BASE:
5228 MI.setDesc(
TII->getKillTerminatorFromPseudo(
MI.getOpcode()));
5237static std::pair<MachineBasicBlock *, MachineBasicBlock *>
5259 auto Next = std::next(
I);
5270 MBB.addSuccessor(LoopBB);
5272 return std::pair(LoopBB, RemainderBB);
5279 auto I =
MI.getIterator();
5280 auto E = std::next(
I);
5302 Src->setIsKill(
false);
5312 BuildMI(*LoopBB, LoopBB->begin(),
DL,
TII->get(AMDGPU::S_SETREG_IMM32_B32))
5318 Register Reg =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5321 BuildMI(*LoopBB,
I,
DL,
TII->get(AMDGPU::S_GETREG_B32), Reg)
5345 unsigned InitReg,
unsigned ResultReg,
unsigned PhiReg,
5346 unsigned InitSaveExecReg,
int Offset,
bool UseGPRIdxMode,
5356 Register PhiExec =
MRI.createVirtualRegister(BoolRC);
5357 Register NewExec =
MRI.createVirtualRegister(BoolRC);
5359 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5360 Register CondReg =
MRI.createVirtualRegister(BoolRC);
5368 BuildMI(LoopBB,
I,
DL,
TII->get(TargetOpcode::PHI), PhiExec)
5375 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), CurrentIdxReg)
5379 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::V_CMP_EQ_U32_e64), CondReg)
5381 .
addReg(Idx.getReg(), {}, Idx.getSubReg());
5388 MRI.setSimpleHint(NewExec, CondReg);
5390 if (UseGPRIdxMode) {
5392 SGPRIdxReg = CurrentIdxReg;
5394 SGPRIdxReg =
MRI.createVirtualRegister(&AMDGPU::SGPR_32RegClass);
5395 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::S_ADD_I32), SGPRIdxReg)
5406 BuildMI(LoopBB,
I,
DL,
TII->get(AMDGPU::S_ADD_I32), AMDGPU::M0)
5439 unsigned InitResultReg,
unsigned PhiReg,
int Offset,
5440 bool UseGPRIdxMode,
Register &SGPRIdxReg) {
5448 const auto *BoolXExecRC =
TRI->getWaveMaskRegClass();
5450 Register SaveExec =
MRI.createVirtualRegister(BoolXExecRC);
5451 Register TmpExec =
MRI.createVirtualRegister(BoolXExecRC);
5467 InitResultReg, DstReg, PhiReg, TmpExec,
5468 Offset, UseGPRIdxMode, SGPRIdxReg);
5474 LoopBB->removeSuccessor(RemainderBB);
5476 LoopBB->addSuccessor(LandingPad);
5487static std::pair<unsigned, int>
5491 int NumElts =
TRI.getRegSizeInBits(*SuperRC) / 32;
5496 return std::pair(AMDGPU::sub0,
Offset);
5510 assert(Idx->getReg() != AMDGPU::NoRegister);
5535 return Idx->getReg();
5537 Register Tmp =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
5555 Register SrcReg =
TII->getNamedOperand(
MI, AMDGPU::OpName::src)->getReg();
5556 int Offset =
TII->getNamedOperand(
MI, AMDGPU::OpName::offset)->getImm();
5562 std::tie(SubReg,
Offset) =
5565 const bool UseGPRIdxMode = ST.useVGPRIndexMode();
5568 if (
TII->getRegisterInfo().isSGPRClass(IdxRC)) {
5572 if (UseGPRIdxMode) {
5579 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
true);
5588 .
addReg(SrcReg, {}, SubReg)
5592 MI.eraseFromParent();
5601 Register PhiReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5602 Register InitReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5608 UseGPRIdxMode, SGPRIdxReg);
5612 if (UseGPRIdxMode) {
5614 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
true);
5616 BuildMI(*LoopBB, InsPt,
DL, GPRIDXDesc, Dst)
5621 BuildMI(*LoopBB, InsPt,
DL,
TII->get(AMDGPU::V_MOVRELS_B32_e32), Dst)
5622 .
addReg(SrcReg, {}, SubReg)
5626 MI.eraseFromParent();
5643 int Offset =
TII->getNamedOperand(
MI, AMDGPU::OpName::offset)->getImm();
5651 std::tie(SubReg,
Offset) =
5653 const bool UseGPRIdxMode = ST.useVGPRIndexMode();
5655 if (Idx->getReg() == AMDGPU::NoRegister) {
5666 MI.eraseFromParent();
5671 if (
TII->getRegisterInfo().isSGPRClass(IdxRC)) {
5675 if (UseGPRIdxMode) {
5679 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
false);
5688 const MCInstrDesc &MovRelDesc =
TII->getIndirectRegWriteMovRelPseudo(
5689 TRI.getRegSizeInBits(*VecRC), 32,
false);
5695 MI.eraseFromParent();
5702 Register PhiReg =
MRI.createVirtualRegister(VecRC);
5706 UseGPRIdxMode, SGPRIdxReg);
5709 if (UseGPRIdxMode) {
5711 TII->getIndirectGPRIDXPseudo(
TRI.getRegSizeInBits(*VecRC),
false);
5713 BuildMI(*LoopBB, InsPt,
DL, GPRIDXDesc, Dst)
5719 const MCInstrDesc &MovRelDesc =
TII->getIndirectRegWriteMovRelPseudo(
5720 TRI.getRegSizeInBits(*VecRC), 32,
false);
5721 BuildMI(*LoopBB, InsPt,
DL, MovRelDesc, Dst)
5727 MI.eraseFromParent();
5743 bool IsAdd = (
MI.getOpcode() == AMDGPU::S_ADD_U64_PSEUDO);
5744 if (ST.hasScalarAddSub64()) {
5746 unsigned Opc = IsAdd ? AMDGPU::S_ADD_U64 : AMDGPU::S_SUB_U64;
5756 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5757 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
5760 MI,
MRI, Src0, BoolRC, AMDGPU::sub0, &AMDGPU::SReg_32RegClass);
5762 MI,
MRI, Src0, BoolRC, AMDGPU::sub1, &AMDGPU::SReg_32RegClass);
5765 MI,
MRI, Src1, BoolRC, AMDGPU::sub0, &AMDGPU::SReg_32RegClass);
5767 MI,
MRI, Src1, BoolRC, AMDGPU::sub1, &AMDGPU::SReg_32RegClass);
5772 unsigned LoOpc = IsAdd ? AMDGPU::S_ADD_U32 : AMDGPU::S_SUB_U32;
5773 unsigned HiOpc = IsAdd ? AMDGPU::S_ADDC_U32 : AMDGPU::S_SUBB_U32;
5779 Hi.setOperandDead(3);
5786 MI.eraseFromParent();
5800 Register SrcCond =
MI.getOperand(3).getReg();
5802 Register DstLo =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5803 Register DstHi =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
5805 Register SrcCondCopy =
MRI.createVirtualRegister(CondRC);
5808 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src0);
5810 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src1);
5812 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), Src0Idx));
5814 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), Src1Idx));
5817 TRI->getSubRegisterClass(Src0RC, AMDGPU::sub0);
5819 TRI->getSubRegisterClass(Src1RC, AMDGPU::sub1);
5822 MI,
MRI, Src0, Src0RC, AMDGPU::sub0, Src0SubRC);
5824 MI,
MRI, Src1, Src1RC, AMDGPU::sub0, Src1SubRC);
5827 MI,
MRI, Src0, Src0RC, AMDGPU::sub1, Src0SubRC);
5829 MI,
MRI, Src1, Src1RC, AMDGPU::sub1, Src1SubRC);
5851 MI.eraseFromParent();
5856 case AMDGPU::S_MIN_U32:
5857 return std::numeric_limits<uint32_t>::max();
5858 case AMDGPU::S_MIN_I32:
5859 return std::numeric_limits<int32_t>::max();
5860 case AMDGPU::S_MAX_U32:
5861 return std::numeric_limits<uint32_t>::min();
5862 case AMDGPU::S_MAX_I32:
5863 return std::numeric_limits<int32_t>::min();
5864 case AMDGPU::V_ADD_F32_e64:
5866 case AMDGPU::V_SUB_F32_e64:
5868 case AMDGPU::S_ADD_I32:
5869 case AMDGPU::S_SUB_I32:
5870 case AMDGPU::S_OR_B32:
5871 case AMDGPU::S_XOR_B32:
5872 return std::numeric_limits<uint32_t>::min();
5873 case AMDGPU::S_AND_B32:
5874 return std::numeric_limits<uint32_t>::max();
5875 case AMDGPU::V_MIN_F32_e64:
5876 case AMDGPU::V_MAX_F32_e64:
5878 case AMDGPU::V_CMP_LT_U64_e64:
5879 return std::numeric_limits<uint64_t>::max();
5880 case AMDGPU::V_CMP_LT_I64_e64:
5881 return std::numeric_limits<int64_t>::max();
5882 case AMDGPU::V_CMP_GT_U64_e64:
5883 return std::numeric_limits<uint64_t>::min();
5884 case AMDGPU::V_CMP_GT_I64_e64:
5885 return std::numeric_limits<int64_t>::min();
5886 case AMDGPU::V_MIN_F64_e64:
5887 case AMDGPU::V_MAX_F64_e64:
5888 case AMDGPU::V_MIN_NUM_F64_e64:
5889 case AMDGPU::V_MAX_NUM_F64_e64:
5890 return 0x7FF8000000000000;
5891 case AMDGPU::S_ADD_U64_PSEUDO:
5892 case AMDGPU::S_SUB_U64_PSEUDO:
5893 case AMDGPU::S_OR_B64:
5894 case AMDGPU::S_XOR_B64:
5895 return std::numeric_limits<uint64_t>::min();
5896 case AMDGPU::S_AND_B64:
5897 return std::numeric_limits<uint64_t>::max();
5898 case AMDGPU::V_ADD_F64_e64:
5899 case AMDGPU::V_ADD_F64_pseudo_e64:
5900 return 0x8000000000000000;
5907 return Opc == AMDGPU::S_MIN_U32 ||
Opc == AMDGPU::S_MIN_I32 ||
5908 Opc == AMDGPU::S_MAX_U32 ||
Opc == AMDGPU::S_MAX_I32 ||
5909 Opc == AMDGPU::S_ADD_I32 ||
Opc == AMDGPU::S_SUB_I32 ||
5910 Opc == AMDGPU::S_AND_B32 ||
Opc == AMDGPU::S_OR_B32 ||
5911 Opc == AMDGPU::S_XOR_B32 ||
Opc == AMDGPU::V_MIN_F32_e64 ||
5912 Opc == AMDGPU::V_MAX_F32_e64 ||
Opc == AMDGPU::V_ADD_F32_e64 ||
5913 Opc == AMDGPU::V_SUB_F32_e64;
5917 return Opc == AMDGPU::V_MIN_F32_e64 ||
Opc == AMDGPU::V_MAX_F32_e64 ||
5918 Opc == AMDGPU::V_ADD_F32_e64 ||
Opc == AMDGPU::V_SUB_F32_e64 ||
5919 Opc == AMDGPU::V_MIN_F64_e64 ||
Opc == AMDGPU::V_MAX_F64_e64 ||
5920 Opc == AMDGPU::V_MIN_NUM_F64_e64 ||
Opc == AMDGPU::V_MAX_NUM_F64_e64 ||
5921 Opc == AMDGPU::V_ADD_F64_e64 ||
Opc == AMDGPU::V_ADD_F64_pseudo_e64;
5924static std::tuple<unsigned, unsigned>
5928 case AMDGPU::S_MIN_U32:
5929 DPPOpc = AMDGPU::V_MIN_U32_dpp;
5931 case AMDGPU::S_MIN_I32:
5932 DPPOpc = AMDGPU::V_MIN_I32_dpp;
5934 case AMDGPU::S_MAX_U32:
5935 DPPOpc = AMDGPU::V_MAX_U32_dpp;
5937 case AMDGPU::S_MAX_I32:
5938 DPPOpc = AMDGPU::V_MAX_I32_dpp;
5940 case AMDGPU::S_ADD_I32:
5941 case AMDGPU::S_SUB_I32:
5942 DPPOpc = ST.hasAddNoCarryInsts() ? AMDGPU::V_ADD_U32_dpp
5943 : AMDGPU::V_ADD_CO_U32_dpp;
5945 case AMDGPU::S_AND_B32:
5946 DPPOpc = AMDGPU::V_AND_B32_dpp;
5948 case AMDGPU::S_OR_B32:
5949 DPPOpc = AMDGPU::V_OR_B32_dpp;
5951 case AMDGPU::S_XOR_B32:
5952 DPPOpc = AMDGPU::V_XOR_B32_dpp;
5954 case AMDGPU::V_ADD_F32_e64:
5955 case AMDGPU::V_SUB_F32_e64:
5956 DPPOpc = AMDGPU::V_ADD_F32_dpp;
5958 case AMDGPU::V_MIN_F32_e64:
5959 DPPOpc = AMDGPU::V_MIN_F32_dpp;
5961 case AMDGPU::V_MAX_F32_e64:
5962 DPPOpc = AMDGPU::V_MAX_F32_dpp;
5964 case AMDGPU::V_CMP_LT_U64_e64:
5965 case AMDGPU::V_CMP_LT_I64_e64:
5966 case AMDGPU::V_CMP_GT_U64_e64:
5967 case AMDGPU::V_CMP_GT_I64_e64:
5968 case AMDGPU::S_ADD_U64_PSEUDO:
5969 case AMDGPU::S_SUB_U64_PSEUDO:
5970 case AMDGPU::S_AND_B64:
5971 case AMDGPU::S_OR_B64:
5972 case AMDGPU::S_XOR_B64:
5973 case AMDGPU::V_MIN_NUM_F64_e64:
5974 case AMDGPU::V_MIN_F64_e64:
5975 case AMDGPU::V_MAX_NUM_F64_e64:
5976 case AMDGPU::V_MAX_F64_e64:
5977 case AMDGPU::V_ADD_F64_pseudo_e64:
5978 case AMDGPU::V_ADD_F64_e64:
5979 DPPOpc = AMDGPU::V_MOV_B64_DPP_PSEUDO;
5984 unsigned ClampOpc =
Opc;
5985 if (
Opc == AMDGPU::V_SUB_F32_e64)
5986 ClampOpc = AMDGPU::V_ADD_F32_e64;
5987 if (!ST.getInstrInfo()->isVALU(
Opc,
false)) {
5988 if (
Opc == AMDGPU::S_SUB_I32)
5989 ClampOpc = AMDGPU::S_ADD_I32;
5990 if (
Opc == AMDGPU::S_ADD_U64_PSEUDO ||
Opc == AMDGPU::S_SUB_U64_PSEUDO)
5991 ClampOpc = AMDGPU::V_ADD_CO_U32_e64;
5992 else if (
Opc == AMDGPU::S_AND_B64)
5993 ClampOpc = AMDGPU::V_AND_B32_e64;
5994 else if (
Opc == AMDGPU::S_OR_B64)
5995 ClampOpc = AMDGPU::V_OR_B32_e64;
5996 else if (
Opc == AMDGPU::S_XOR_B64)
5997 ClampOpc = AMDGPU::V_XOR_B32_e64;
5999 ClampOpc = ST.getInstrInfo()->getVALUOp(ClampOpc);
6001 return {DPPOpc, ClampOpc};
6004static std::pair<Register, Register>
6011 TRI->getSubRegisterClass(SrcRC, AMDGPU::sub0);
6013 TII->buildExtractSubReg(
MI,
MRI,
Op, SrcRC, AMDGPU::sub0, SrcSubRC);
6015 TII->buildExtractSubReg(
MI,
MRI,
Op, SrcRC, AMDGPU::sub1, SrcSubRC);
6016 return {Op1L, Op1H};
6030 bool isSGPR =
TRI->isSGPRClass(
MRI.getRegClass(SrcReg));
6032 unsigned Stratergy =
static_cast<unsigned>(
MI.getOperand(2).
getImm());
6033 enum WAVE_REDUCE_STRATEGY :
unsigned {
DEFAULT = 0, ITERATIVE = 1, DPP = 2 };
6035 unsigned MIOpc =
MI.getOpcode();
6049 case AMDGPU::S_MIN_U32:
6050 case AMDGPU::S_MIN_I32:
6051 case AMDGPU::V_MIN_F32_e64:
6052 case AMDGPU::S_MAX_U32:
6053 case AMDGPU::S_MAX_I32:
6054 case AMDGPU::V_MAX_F32_e64:
6055 case AMDGPU::S_AND_B32:
6056 case AMDGPU::S_OR_B32: {
6062 case AMDGPU::V_CMP_LT_U64_e64:
6063 case AMDGPU::V_CMP_LT_I64_e64:
6064 case AMDGPU::V_CMP_GT_U64_e64:
6065 case AMDGPU::V_CMP_GT_I64_e64:
6066 case AMDGPU::V_MIN_F64_e64:
6067 case AMDGPU::V_MIN_NUM_F64_e64:
6068 case AMDGPU::V_MAX_F64_e64:
6069 case AMDGPU::V_MAX_NUM_F64_e64:
6070 case AMDGPU::S_AND_B64:
6071 case AMDGPU::S_OR_B64: {
6077 case AMDGPU::S_XOR_B32:
6078 case AMDGPU::S_XOR_B64:
6079 case AMDGPU::S_ADD_I32:
6080 case AMDGPU::S_ADD_U64_PSEUDO:
6081 case AMDGPU::V_ADD_F32_e64:
6082 case AMDGPU::V_ADD_F64_e64:
6083 case AMDGPU::V_ADD_F64_pseudo_e64:
6084 case AMDGPU::S_SUB_I32:
6085 case AMDGPU::S_SUB_U64_PSEUDO:
6086 case AMDGPU::V_SUB_F32_e64: {
6089 Register ExecMask =
MRI.createVirtualRegister(WaveMaskRegClass);
6091 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6093 bool IsWave32 = ST.isWave32();
6094 unsigned MovOpc = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
6095 MCRegister ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
6096 unsigned BitCountOpc =
6097 IsWave32 ? AMDGPU::S_BCNT1_I32_B32 : AMDGPU::S_BCNT1_I32_B64;
6101 auto NewAccumulator =
6107 case AMDGPU::S_XOR_B32:
6108 case AMDGPU::S_XOR_B64: {
6114 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6116 .
addReg(NewAccumulator->getOperand(0).getReg())
6120 if (
TII->getImmOrMaterializedImm(
MRI, SrcReg) == 1) {
6122 if (
Opc == AMDGPU::S_XOR_B32) {
6127 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6129 BuildRegSequence(BB,
MI, DstReg, ParityRegister, DstHi);
6133 if (
Opc == AMDGPU::S_XOR_B32) {
6139 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6141 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6143 MRI.getRegClass(SrcReg), ST,
MRI);
6150 BuildRegSequence(BB,
MI, DstReg, DestSub0, DestSub1);
6154 case AMDGPU::S_SUB_I32: {
6155 Register NegatedVal =
MRI.createVirtualRegister(DstRegClass);
6163 .
addReg(NewAccumulator->getOperand(0).getReg());
6166 case AMDGPU::S_ADD_I32: {
6168 if (
TII->getImmOrMaterializedImm(
MRI, SrcReg) == 1) {
6171 .
addReg(NewAccumulator->getOperand(0).getReg());
6176 .
addReg(NewAccumulator->getOperand(0).getReg());
6179 case AMDGPU::S_ADD_U64_PSEUDO:
6180 case AMDGPU::S_SUB_U64_PSEUDO: {
6181 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6182 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6184 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6186 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6188 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6189 Register AddReg =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6191 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6193 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6195 MRI.getRegClass(SrcReg), ST,
MRI);
6197 if (
Opc == AMDGPU::S_ADD_U64_PSEUDO &&
6198 TII->getImmOrMaterializedImm(
MRI, SrcReg) == 1) {
6200 Register DstHi =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6202 BuildRegSequence(BB,
MI, DstReg,
6203 NewAccumulator->getOperand(0).getReg(), DstHi);
6206 if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
6209 .
addReg(NewAccumulator->getOperand(0).getReg())
6219 Register LowOpcode =
Opc == AMDGPU::S_SUB_U64_PSEUDO
6221 : NewAccumulator->getOperand(0).getReg();
6225 if (ST.hasScalarMulHiInsts()) {
6231 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6233 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6236 BuildMI(BB,
MI,
DL,
TII->get(AMDGPU::V_MUL_HI_U32_e64), VCarryReg)
6239 BuildMI(BB,
MI,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), CarryReg)
6246 Register HiVal =
Opc == AMDGPU::S_SUB_U64_PSEUDO ? AddReg : DestSub1;
6252 if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
6258 BuildRegSequence(BB,
MI, DstReg, DestSub0, DestSub1);
6261 case AMDGPU::V_ADD_F32_e64:
6262 case AMDGPU::V_ADD_F64_e64:
6263 case AMDGPU::V_ADD_F64_pseudo_e64:
6264 case AMDGPU::V_SUB_F32_e64: {
6267 Register ActiveLanesVreg =
MRI.createVirtualRegister(VregRC);
6268 Register DstVreg =
MRI.createVirtualRegister(VregRC);
6271 TII->get(is32BitOpc ? AMDGPU::V_CVT_F32_I32_e64
6272 : AMDGPU::V_CVT_F64_I32_e64),
6274 .
addReg(NewAccumulator->getOperand(0).getReg())
6279 unsigned srcMod = (MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F32 ||
6280 MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64)
6283 unsigned MulOpc = is32BitOpc ? AMDGPU::V_MUL_F32_e64
6285 ? AMDGPU::V_MUL_F64_pseudo_e64
6286 : AMDGPU::V_MUL_F64_e64;
6296 BuildMI(BB,
MI,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), DstReg)
6300 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6302 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6313 BuildRegSequence(BB,
MI, DstReg, LaneValueLoReg, LaneValueHiReg);
6325 bool NeedsMovDPP = !is32BitOpc;
6330 bool IsWave32 = ST.isWave32();
6331 unsigned MovOpcForExec = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
6332 unsigned ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
6333 if (Stratergy == WAVE_REDUCE_STRATEGY::ITERATIVE ||
6347 Register LoopIterator =
MRI.createVirtualRegister(WaveMaskRegClass);
6348 Register IdentityValReg =
MRI.createVirtualRegister(DstRegClass);
6349 Register AccumulatorReg =
MRI.createVirtualRegister(DstRegClass);
6350 Register ActiveBitsReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6351 Register NewActiveBitsReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6352 Register FF1Reg =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6353 Register LaneValueReg =
MRI.createVirtualRegister(DstRegClass);
6359 MI.getOpcode() == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64
6363 TII->get(is32BitOpc ? AMDGPU::S_MOV_B32
6364 : AMDGPU::S_MOV_B64_IMM_PSEUDO),
6373 I = ComputeLoop->begin();
6375 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::PHI), AccumulatorReg)
6379 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::PHI), ActiveBitsReg)
6383 I = ComputeLoop->end();
6387 IsWave32 ? AMDGPU::S_FF1_I32_B32 : AMDGPU::S_FF1_I32_B64;
6392 bool hasSrc0Modifier = AMDGPU::getNamedOperandIdx(
6393 Opc, AMDGPU::OpName::src0_modifiers) != -1;
6394 bool hasSrc1Modifier = AMDGPU::getNamedOperandIdx(
6395 Opc, AMDGPU::OpName::src1_modifiers) != -1;
6397 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::clamp) != -1;
6399 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel) != -1;
6401 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::omod) != -1;
6402 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
6406 if (ST.getInstrInfo()->isVALU(
Opc,
false)) {
6408 Register LaneValVgpr =
MRI.createVirtualRegister(SrcRegClass);
6409 Register VgprResultReg =
MRI.createVirtualRegister(SrcRegClass);
6410 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::COPY), LaneValVgpr)
6412 OpDstReg = VgprResultReg;
6413 LaneValueReg = LaneValVgpr;
6416 if (hasSrc0Modifier)
6418 OpInstr.addReg(AccumulatorReg);
6419 if (hasSrc1Modifier)
6421 OpInstr.addReg(LaneValueReg);
6429 OpInstr.setOperandDead(3);
6430 if (ST.getInstrInfo()->isVALU(
Opc,
false)) {
6431 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32),
6437 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6439 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6441 MRI.createVirtualRegister(&AMDGPU::SReg_64RegClass);
6443 MRI.getRegClass(SrcReg), ST,
MRI);
6445 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
6449 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::V_READLANE_B32),
6453 auto LaneValue = BuildRegSequence(*ComputeLoop,
I, LaneValReg,
6454 LaneValueLoReg, LaneValueHiReg);
6456 case AMDGPU::S_OR_B64:
6457 case AMDGPU::S_AND_B64:
6458 case AMDGPU::S_XOR_B64: {
6461 .
addReg(LaneValue->getOperand(0).getReg())
6465 case AMDGPU::V_CMP_GT_I64_e64:
6466 case AMDGPU::V_CMP_GT_U64_e64:
6467 case AMDGPU::V_CMP_LT_I64_e64:
6468 case AMDGPU::V_CMP_LT_U64_e64: {
6469 Register LaneMaskReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6471 MRI.createVirtualRegister(WaveMaskRegClass);
6473 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src);
6475 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), SrcIdx));
6476 Register AccumulatorVReg =
MRI.createVirtualRegister(VregClass);
6479 BuildRegSequence(*ComputeLoop,
I, AccumulatorVReg, SrcReg0Sub0,
6482 .
addReg(LaneValue->getOperand(0).getReg())
6483 .
addReg(AccumulatorVReg);
6485 unsigned AndOpc = IsWave32 ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64;
6486 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AndOpc), ComparisonResultReg)
6490 NewAccumulator =
BuildMI(*ComputeLoop,
I,
DL,
6491 TII->get(AMDGPU::S_CSELECT_B64), DstReg)
6492 .
addReg(LaneValue->getOperand(0).getReg())
6496 case AMDGPU::V_MIN_F64_e64:
6497 case AMDGPU::V_MIN_NUM_F64_e64:
6498 case AMDGPU::V_MAX_F64_e64:
6499 case AMDGPU::V_MAX_NUM_F64_e64:
6500 case AMDGPU::V_ADD_F64_e64:
6501 case AMDGPU::V_ADD_F64_pseudo_e64: {
6503 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src);
6505 TRI->getAllocatableClass(
TII->getRegClass(
MI.getDesc(), SrcIdx));
6506 Register AccumulatorVReg =
MRI.createVirtualRegister(VregRC);
6507 Register DstVreg =
MRI.createVirtualRegister(VregRC);
6509 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6511 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6512 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::COPY), AccumulatorVReg)
6515 MI.getOpcode() == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64
6521 .
addReg(LaneValue->getOperand(0).getReg())
6528 TII->get(AMDGPU::V_READFIRSTLANE_B32), LaneValLo);
6531 TII->get(AMDGPU::V_READFIRSTLANE_B32), LaneValHi);
6533 auto [Op1L, Op1H] =
ExtractSubRegs(*Iters, DstVregInst->getOperand(0),
6535 ReadLaneLo.addReg(Op1L);
6536 ReadLaneHi.addReg(Op1H);
6538 BuildRegSequence(*ComputeLoop,
I, DstReg, LaneValLo, LaneValHi);
6541 case AMDGPU::S_ADD_U64_PSEUDO:
6542 case AMDGPU::S_SUB_U64_PSEUDO: {
6545 .
addReg(LaneValue->getOperand(0).getReg())
6554 unsigned BITSETOpc =
6555 IsWave32 ? AMDGPU::S_BITSET0_B32 : AMDGPU::S_BITSET0_B64;
6556 BuildMI(*ComputeLoop,
I,
DL,
TII->get(BITSETOpc), NewActiveBitsReg)
6562 ActiveBits.addReg(NewActiveBitsReg).addMBB(ComputeLoop);
6566 if (!ST.hasScalarCompareEq64()) {
6568 Register LaneMaskReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6569 unsigned CMPOpc = IsWave32 ? AMDGPU::S_OR_B32 : AMDGPU::S_OR_B64;
6571 BuildMI(*ComputeLoop,
I,
DL,
TII->get(CMPOpc), LaneMaskReg);
6574 IsWave32 ? AMDGPU::S_CMP_LG_U32 : AMDGPU::S_CMP_LG_U64;
6575 SetSCCInstr =
BuildMI(*ComputeLoop,
I,
DL,
TII->get(CMPOpc));
6577 SetSCCInstr.
addReg(NewActiveBitsReg);
6578 if (ST.hasScalarCompareEq64())
6581 SetSCCInstr.
addReg(NewActiveBitsReg);
6582 BuildMI(*ComputeLoop,
I,
DL,
TII->get(AMDGPU::S_CBRANCH_SCC1))
6587 assert(ST.hasDPP() &&
"Sub Target does not support DPP Operations");
6589 Register SrcWithIdentity =
MRI.createVirtualRegister(SrcRegClass);
6590 Register IdentityVGPR =
MRI.createVirtualRegister(SrcRegClass);
6591 Register IdentitySGPR =
MRI.createVirtualRegister(DstRegClass);
6592 Register DPPRowShr1 =
MRI.createVirtualRegister(SrcRegClass);
6593 Register DPPRowShr2 =
MRI.createVirtualRegister(SrcRegClass);
6594 Register DPPRowShr4 =
MRI.createVirtualRegister(SrcRegClass);
6595 Register DPPRowShr8 =
MRI.createVirtualRegister(SrcRegClass);
6596 Register RowBcast15 =
MRI.createVirtualRegister(SrcRegClass);
6597 Register ReducedValSGPR =
MRI.createVirtualRegister(DstRegClass);
6598 Register NegatedReducedVal =
MRI.createVirtualRegister(DstRegClass);
6599 Register RowBcast31 =
MRI.createVirtualRegister(SrcRegClass);
6600 Register UndefExec =
MRI.createVirtualRegister(WaveMaskRegClass);
6604 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::IMPLICIT_DEF), UndefExec);
6608 TII->get(is32BitOpc ? AMDGPU::S_MOV_B32
6609 : AMDGPU::S_MOV_B64_IMM_PSEUDO),
6612 auto IdentityCopyInstr =
6615 unsigned DPPOpc, ClampOpc;
6631 if (isFPOp && !NeedsMovDPP)
6634 if (isFPOp && !NeedsMovDPP)
6638 if (AMDGPU::getNamedOperandIdx(DPPOpc, AMDGPU::OpName::clamp) >= 0)
6647 bool isAddSub =
false,
6648 bool needsCarryIn =
false,
6650 unsigned InstrOpc = ClampOpc;
6651 Register CarryOutReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6653 InstrOpc = AMDGPU::V_ADDC_U32_e64;
6654 auto ClampInstr =
BuildMI(*CurrBB,
MI,
DL,
TII->get(InstrOpc), Dst);
6659 ClampInstr.addReg(CarryOutReg,
6665 ClampInstr.addReg(Src0);
6668 ClampInstr.addReg(Src1);
6670 ClampInstr.addReg(CarryIn);
6671 if (AMDGPU::getNamedOperandIdx(InstrOpc, AMDGPU::OpName::clamp) >= 0)
6672 ClampInstr.addImm(0);
6674 ClampInstr.addImm(0);
6675 LastBcastInstr = ClampInstr;
6680 Opc == AMDGPU::S_ADD_U64_PSEUDO ||
Opc == AMDGPU::S_SUB_U64_PSEUDO;
6681 bool isBitWiseOpc =
Opc == AMDGPU::S_AND_B64 ||
6682 Opc == AMDGPU::S_OR_B64 ||
Opc == AMDGPU::S_XOR_B64;
6683 Register ReturnReg =
MRI.createVirtualRegister(SrcRegClass);
6684 if (isAddSubOpc || isBitWiseOpc) {
6685 Register ResLo =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6686 Register ResHi =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6691 auto [Src0Lo, Src0Hi] =
6693 auto [Src1Lo, Src1Hi] =
6695 Register CarryReg = BuildClampInstr(
6696 ResLo, Src0Lo, Src1Lo, isAddSubOpc,
false);
6697 BuildClampInstr(ResHi, Src0Hi, Src1Hi, isAddSubOpc,
6698 isAddSubOpc, CarryReg);
6699 BuildRegSequence(*CurrBB,
MI, ReturnReg, ResLo, ResHi);
6710 Register CmpMaskReg =
MRI.createVirtualRegister(WaveMaskRegClass);
6728 SrcWithIdentityInstr =
6729 BuildSetInactiveInstr(SrcWithIdentity, SrcReg, IdentityVGPR);
6732 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6734 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6736 MI, IdentityCopyInstr->getOperand(0), SrcRegClass, ST,
MRI);
6737 auto [SrcReg0Sub0, SrcReg0Sub1] =
6740 BuildSetInactiveInstr(SrcWithIdentitylo, SrcReg0Sub0, Reg0Sub0);
6742 BuildSetInactiveInstr(SrcWithIdentityhi, SrcReg0Sub1, Reg0Sub1);
6743 SrcWithIdentityInstr =
6744 BuildRegSequence(*CurrBB,
MI, SrcWithIdentity,
6751 BuildDPPMachineInstr(DPPRowShr1, SrcWithIdentityReg,
6754 DPPRowShr1 = BuildPostDPPInstr(SrcWithIdentityReg, DPPRowShr1);
6756 BuildDPPMachineInstr(DPPRowShr2, DPPRowShr1,
6759 DPPRowShr2 = BuildPostDPPInstr(DPPRowShr1, DPPRowShr2);
6761 BuildDPPMachineInstr(DPPRowShr4, DPPRowShr2,
6764 DPPRowShr4 = BuildPostDPPInstr(DPPRowShr2, DPPRowShr4);
6766 BuildDPPMachineInstr(DPPRowShr8, DPPRowShr4,
6769 DPPRowShr8 = BuildPostDPPInstr(DPPRowShr4, DPPRowShr8);
6771 if (ST.hasDPPBroadcasts()) {
6774 RowBcast15 = BuildPostDPPInstr(DPPRowShr8, RowBcast15);
6783 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6789 BuildClampInstr(RowBcast15, DPPRowShr8, SwizzledValue);
6792 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6794 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6795 Register SwizzledValue64 =
MRI.createVirtualRegister(SrcRegClass);
6810 BuildRegSequence(*CurrBB,
MI, SwizzledValue64, SwizzledValuelo,
6813 RowBcast15 = BuildPostDPPInstr(DPPRowShr8, SwizzledValue64);
6815 BuildClampInstr(RowBcast15, DPPRowShr8, SwizzledValue64);
6818 FinalDPPResult = RowBcast15;
6820 if (ST.hasDPPBroadcasts()) {
6823 RowBcast31 = BuildPostDPPInstr(RowBcast15, RowBcast31);
6826 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6828 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6829 Register PermutedValue =
MRI.createVirtualRegister(SrcRegClass);
6831 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6833 MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
6835 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6837 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6839 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::V_MBCNT_LO_U32_B32_e64),
6843 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::V_MBCNT_HI_U32_B32_e64),
6849 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::S_MOV_B32), Lane32Offset)
6857 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::S_MOV_B32), WordSizeConst)
6862 .
addReg(ShiftedThreadID);
6867 .
addReg(PermuteByteOffset)
6872 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6874 MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
6877 auto [RowBcast15Lo, RowBcast15Hi] =
6881 .
addReg(PermuteByteOffset)
6886 .
addReg(PermuteByteOffset)
6889 BuildRegSequence(*CurrBB,
MI, PermutedValue, PermutedValuelo,
6893 RowBcast31 = BuildPostDPPInstr(RowBcast15, PermutedValue);
6895 BuildClampInstr(RowBcast31, RowBcast15, PermutedValue);
6897 FinalDPPResult = RowBcast31;
6899 if (MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F32 ||
6900 MIOpc == AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64) {
6901 Register NegatedValVGPR =
MRI.createVirtualRegister(SrcRegClass);
6910 .
addReg(IsWave32 ? RowBcast15 : RowBcast31)
6913 FinalDPPResult = NegatedValVGPR;
6920 .
addImm(ST.getWavefrontSize() - 1);
6923 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6925 MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
6935 .
addImm(ST.getWavefrontSize() - 1);
6939 .
addImm(ST.getWavefrontSize() - 1);
6940 BuildRegSequence(*CurrBB,
MI, ReducedValSGPR, LaneValueLoReg,
6943 if (
Opc == AMDGPU::S_SUB_I32) {
6944 BuildMI(*CurrBB,
MI,
DL,
TII->get(AMDGPU::S_SUB_I32), NegatedReducedVal)
6948 }
else if (
Opc == AMDGPU::S_SUB_U64_PSEUDO) {
6949 auto NegatedValInstr =
6958 .
addReg(
Opc == AMDGPU::S_SUB_I32 ||
Opc == AMDGPU::S_SUB_U64_PSEUDO
6964 MI.eraseFromParent();
6979 switch (
MI.getOpcode()) {
6980 case AMDGPU::WAVE_REDUCE_UMIN_PSEUDO_U32:
6982 case AMDGPU::WAVE_REDUCE_UMIN_PSEUDO_U64:
6984 case AMDGPU::WAVE_REDUCE_MIN_PSEUDO_I32:
6986 case AMDGPU::WAVE_REDUCE_MIN_PSEUDO_I64:
6988 case AMDGPU::WAVE_REDUCE_FMIN_PSEUDO_F32:
6990 case AMDGPU::WAVE_REDUCE_FMIN_PSEUDO_F64:
6993 ? AMDGPU::V_MIN_NUM_F64_e64
6994 : AMDGPU::V_MIN_F64_e64);
6995 case AMDGPU::WAVE_REDUCE_UMAX_PSEUDO_U32:
6997 case AMDGPU::WAVE_REDUCE_UMAX_PSEUDO_U64:
6999 case AMDGPU::WAVE_REDUCE_MAX_PSEUDO_I32:
7001 case AMDGPU::WAVE_REDUCE_MAX_PSEUDO_I64:
7003 case AMDGPU::WAVE_REDUCE_FMAX_PSEUDO_F32:
7005 case AMDGPU::WAVE_REDUCE_FMAX_PSEUDO_F64:
7008 ? AMDGPU::V_MAX_NUM_F64_e64
7009 : AMDGPU::V_MAX_F64_e64);
7010 case AMDGPU::WAVE_REDUCE_ADD_PSEUDO_I32:
7012 case AMDGPU::WAVE_REDUCE_ADD_PSEUDO_U64:
7014 case AMDGPU::WAVE_REDUCE_FADD_PSEUDO_F32:
7016 case AMDGPU::WAVE_REDUCE_FADD_PSEUDO_F64:
7019 ? AMDGPU::V_ADD_F64_pseudo_e64
7020 : AMDGPU::V_ADD_F64_e64);
7021 case AMDGPU::WAVE_REDUCE_SUB_PSEUDO_I32:
7023 case AMDGPU::WAVE_REDUCE_SUB_PSEUDO_U64:
7025 case AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F32:
7027 case AMDGPU::WAVE_REDUCE_FSUB_PSEUDO_F64:
7032 ? AMDGPU::V_ADD_F64_pseudo_e64
7033 : AMDGPU::V_ADD_F64_e64);
7034 case AMDGPU::WAVE_REDUCE_AND_PSEUDO_B32:
7036 case AMDGPU::WAVE_REDUCE_AND_PSEUDO_B64:
7038 case AMDGPU::WAVE_REDUCE_OR_PSEUDO_B32:
7040 case AMDGPU::WAVE_REDUCE_OR_PSEUDO_B64:
7042 case AMDGPU::WAVE_REDUCE_XOR_PSEUDO_B32:
7044 case AMDGPU::WAVE_REDUCE_XOR_PSEUDO_B64:
7046 case AMDGPU::S_UADDO_PSEUDO:
7047 case AMDGPU::S_USUBO_PSEUDO: {
7053 unsigned Opc = (
MI.getOpcode() == AMDGPU::S_UADDO_PSEUDO)
7055 : AMDGPU::S_SUB_U32;
7063 Subtarget->isWave64() ? AMDGPU::S_CSELECT_B64 : AMDGPU::S_CSELECT_B32;
7066 MI.eraseFromParent();
7069 case AMDGPU::S_ADD_U64_PSEUDO:
7070 case AMDGPU::S_SUB_U64_PSEUDO: {
7073 case AMDGPU::V_ADD_U64_PSEUDO:
7074 case AMDGPU::V_SUB_U64_PSEUDO: {
7075 bool IsAdd = (
MI.getOpcode() == AMDGPU::V_ADD_U64_PSEUDO);
7081 if (ST.hasAddSubU64Insts()) {
7083 TII->get(IsAdd ? AMDGPU::V_ADD_U64_e64
7084 : AMDGPU::V_SUB_U64_e64),
7089 TII->legalizeOperands(*
I);
7090 MI.eraseFromParent();
7094 if (IsAdd && ST.hasLshlAddU64Inst()) {
7100 TII->legalizeOperands(*
Add);
7101 MI.eraseFromParent();
7105 const auto *CarryRC =
TRI->getWaveMaskRegClass();
7107 Register DestSub0 =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
7108 Register DestSub1 =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
7110 Register CarryReg =
MRI.createVirtualRegister(CarryRC);
7111 Register DeadCarryReg =
MRI.createVirtualRegister(CarryRC);
7114 ?
MRI.getRegClass(Src0.getReg())
7115 : &AMDGPU::VReg_64RegClass;
7117 ?
MRI.getRegClass(Src1.getReg())
7118 : &AMDGPU::VReg_64RegClass;
7121 TRI->getSubRegisterClass(Src0RC, AMDGPU::sub0);
7123 TRI->getSubRegisterClass(Src1RC, AMDGPU::sub1);
7126 MI,
MRI, Src0, Src0RC, AMDGPU::sub0, Src0SubRC);
7128 MI,
MRI, Src1, Src1RC, AMDGPU::sub0, Src1SubRC);
7131 MI,
MRI, Src0, Src0RC, AMDGPU::sub1, Src0SubRC);
7133 MI,
MRI, Src1, Src1RC, AMDGPU::sub1, Src1SubRC);
7136 IsAdd ? AMDGPU::V_ADD_CO_U32_e64 : AMDGPU::V_SUB_CO_U32_e64;
7143 unsigned HiOpc = IsAdd ? AMDGPU::V_ADDC_U32_e64 : AMDGPU::V_SUBB_U32_e64;
7157 TII->legalizeOperands(*LoHalf);
7158 TII->legalizeOperands(*HiHalf);
7159 MI.eraseFromParent();
7162 case AMDGPU::S_ADD_CO_PSEUDO:
7163 case AMDGPU::S_SUB_CO_PSEUDO: {
7173 if (Src0.isReg() &&
TRI->isVectorRegister(
MRI, Src0.getReg())) {
7174 Register RegOp0 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
7175 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp0)
7177 Src0.setReg(RegOp0);
7179 if (Src1.isReg() &&
TRI->isVectorRegister(
MRI, Src1.getReg())) {
7180 Register RegOp1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
7181 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp1)
7183 Src1.setReg(RegOp1);
7185 Register RegOp2 =
MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
7186 if (
TRI->isVectorRegister(
MRI, Src2.getReg())) {
7187 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::V_READFIRSTLANE_B32), RegOp2)
7189 Src2.setReg(RegOp2);
7192 if (ST.isWave64()) {
7193 if (ST.hasScalarCompareEq64()) {
7200 TRI->getSubRegisterClass(Src2RC, AMDGPU::sub0);
7202 MII,
MRI, Src2, Src2RC, AMDGPU::sub0, SubRC);
7204 MII,
MRI, Src2, Src2RC, AMDGPU::sub1, SubRC);
7205 Register Src2_32 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7207 BuildMI(*BB, MII,
DL,
TII->get(AMDGPU::S_OR_B32), Src2_32)
7221 unsigned Opc =
MI.getOpcode() == AMDGPU::S_ADD_CO_PSEUDO
7222 ? AMDGPU::S_ADDC_U32
7223 : AMDGPU::S_SUBB_U32;
7228 ST.isWave64() ? AMDGPU::S_CSELECT_B64 : AMDGPU::S_CSELECT_B32;
7234 MI.eraseFromParent();
7237 case AMDGPU::SI_INIT_M0: {
7240 TII->get(M0Init.
isReg() ? AMDGPU::COPY : AMDGPU::S_MOV_B32),
7243 MI.eraseFromParent();
7246 case AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM: {
7249 TII->get(AMDGPU::S_CMP_EQ_U32))
7254 case AMDGPU::GET_GROUPSTATICSIZE: {
7258 .
add(
MI.getOperand(0))
7260 MI.eraseFromParent();
7263 case AMDGPU::GET_SHADERCYCLESHILO: {
7276 Register RegHi1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7278 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES_HI, 0, 32));
7279 Register RegLo1 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7281 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES, 0, 32));
7282 Register RegHi2 =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7284 .
addImm(HwregEncoding::encode(ID_SHADER_CYCLES_HI, 0, 32));
7288 Register RegLo =
MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
7293 .
add(
MI.getOperand(0))
7298 MI.eraseFromParent();
7301 case AMDGPU::SI_INDIRECT_SRC_V1:
7302 case AMDGPU::SI_INDIRECT_SRC_V2:
7303 case AMDGPU::SI_INDIRECT_SRC_V3:
7304 case AMDGPU::SI_INDIRECT_SRC_V4:
7305 case AMDGPU::SI_INDIRECT_SRC_V5:
7306 case AMDGPU::SI_INDIRECT_SRC_V6:
7307 case AMDGPU::SI_INDIRECT_SRC_V7:
7308 case AMDGPU::SI_INDIRECT_SRC_V8:
7309 case AMDGPU::SI_INDIRECT_SRC_V9:
7310 case AMDGPU::SI_INDIRECT_SRC_V10:
7311 case AMDGPU::SI_INDIRECT_SRC_V11:
7312 case AMDGPU::SI_INDIRECT_SRC_V12:
7313 case AMDGPU::SI_INDIRECT_SRC_V16:
7314 case AMDGPU::SI_INDIRECT_SRC_V32:
7316 case AMDGPU::SI_INDIRECT_DST_V1:
7317 case AMDGPU::SI_INDIRECT_DST_V2:
7318 case AMDGPU::SI_INDIRECT_DST_V3:
7319 case AMDGPU::SI_INDIRECT_DST_V4:
7320 case AMDGPU::SI_INDIRECT_DST_V5:
7321 case AMDGPU::SI_INDIRECT_DST_V6:
7322 case AMDGPU::SI_INDIRECT_DST_V7:
7323 case AMDGPU::SI_INDIRECT_DST_V8:
7324 case AMDGPU::SI_INDIRECT_DST_V9:
7325 case AMDGPU::SI_INDIRECT_DST_V10:
7326 case AMDGPU::SI_INDIRECT_DST_V11:
7327 case AMDGPU::SI_INDIRECT_DST_V12:
7328 case AMDGPU::SI_INDIRECT_DST_V16:
7329 case AMDGPU::SI_INDIRECT_DST_V32:
7331 case AMDGPU::SI_KILL_F32_COND_IMM_PSEUDO:
7332 case AMDGPU::SI_KILL_I1_PSEUDO:
7334 case AMDGPU::V_CNDMASK_B64_PSEUDO: {
7338 case AMDGPU::SI_BR_UNDEF: {
7340 .
add(
MI.getOperand(0));
7342 MI.eraseFromParent();
7345 case AMDGPU::ADJCALLSTACKUP:
7346 case AMDGPU::ADJCALLSTACKDOWN: {
7353 case AMDGPU::SI_CALL_ISEL: {
7354 unsigned ReturnAddrReg =
TII->getRegisterInfo().getReturnAddressReg(*MF);
7365 MI.eraseFromParent();
7368 case AMDGPU::V_ADDC_U32_e32:
7369 case AMDGPU::V_SUBB_U32_e32:
7370 case AMDGPU::V_SUBBREV_U32_e32:
7373 TII->legalizeOperands(
MI);
7375 case AMDGPU::DS_GWS_INIT:
7376 case AMDGPU::DS_GWS_SEMA_BR:
7377 case AMDGPU::DS_GWS_BARRIER:
7378 case AMDGPU::DS_GWS_SEMA_V:
7379 case AMDGPU::DS_GWS_SEMA_P:
7380 case AMDGPU::DS_GWS_SEMA_RELEASE_ALL:
7388 case AMDGPU::S_SETREG_B32: {
7398 auto [ID,
Offset, Width] =
7404 const unsigned SetMask = WidthMask <<
Offset;
7407 unsigned SetDenormOp = 0;
7408 unsigned SetRoundOp = 0;
7416 SetRoundOp = AMDGPU::S_ROUND_MODE;
7417 SetDenormOp = AMDGPU::S_DENORM_MODE;
7419 SetRoundOp = AMDGPU::S_ROUND_MODE;
7421 SetDenormOp = AMDGPU::S_DENORM_MODE;
7424 if (SetRoundOp || SetDenormOp) {
7426 if (Def && Def->isMoveImmediate() && Def->getOperand(1).isImm()) {
7427 unsigned ImmVal = Def->getOperand(1).getImm();
7441 MI.eraseFromParent();
7450 MI.setDesc(
TII->get(AMDGPU::S_SETREG_B32_mode));
7454 case AMDGPU::S_INVERSE_BALLOT_U32:
7455 case AMDGPU::S_INVERSE_BALLOT_U64:
7458 MI.setDesc(
TII->get(AMDGPU::COPY));
7460 case AMDGPU::ENDPGM_TRAP: {
7462 MI.setDesc(
TII->get(AMDGPU::S_ENDPGM));
7482 MI.eraseFromParent();
7485 case AMDGPU::SIMULATED_TRAP: {
7486 assert(Subtarget->hasPrivEnabledTrap2NopBug());
7488 TII->insertSimulatedTrap(
MRI, *BB,
MI,
MI.getDebugLoc());
7489 MI.eraseFromParent();
7492 case AMDGPU::SI_TCRETURN_GFX_WholeWave:
7493 case AMDGPU::SI_WHOLE_WAVE_FUNC_RETURN: {
7499 assert(Setup &&
"Couldn't find SI_SETUP_WHOLE_WAVE_FUNC");
7500 Register OriginalExec = Setup->getOperand(0).getReg();
7501 MI.getOperand(0).setReg(OriginalExec);
7504 case AMDGPU::V_DOT2_F32_F16:
7505 case AMDGPU::V_DOT2_F32_BF16: {
7509 MRI.setSimpleHint(
MI.getOperand(0).getReg(),
MI.getOperand(6).getReg());
7512 case AMDGPU::SCHED_BARRIER:
7513 case AMDGPU::SCHED_GROUP_BARRIER:
7514 MI.getOperand(0).setImm(
MI.getOperand(0).getImm() &
7551 return (VT == MVT::i16) ? MVT::i16 : MVT::i32;
7555 return (Ty.getScalarSizeInBits() <= 16 && Subtarget->has16BitInsts())
7584 if (!Subtarget->hasMadMacF32Insts())
7585 return Subtarget->hasFastFMAF32();
7591 return Subtarget->hasFastFMAF32() || Subtarget->hasDLInsts();
7594 return Subtarget->hasFastFMAF32() && Subtarget->hasDLInsts();
7600 return Subtarget->has16BitInsts() &&
7618 F.getDenormalFPEnv());
7623 switch (Ty.getScalarSizeInBits()) {
7641 return Subtarget->hasMadMacF32Insts() &&
7644 return Subtarget->hasMadF16() &&
7655 if (Ty.getScalarSizeInBits() == 16)
7657 if (Ty.getScalarSizeInBits() == 32)
7672 F.getDenormalFPEnv());
7683 unsigned Opc =
Op.getOpcode();
7684 EVT VT =
Op.getValueType();
7696 LoOps.
append(TrailingOps.begin(), TrailingOps.end());
7697 HiOps.
append(TrailingOps.begin(), TrailingOps.end());
7710 [[maybe_unused]]
EVT VT =
Op.getValueType();
7712 assert((VT == MVT::v2i32 || VT == MVT::v4i32 || VT == MVT::v8i32 ||
7713 VT == MVT::v16i32) &&
7714 "Unexpected ValueType.");
7723 unsigned Opc =
Op.getOpcode();
7724 EVT VT =
Op.getValueType();
7733 DAG.
getNode(
Opc, SL, Lo0.getValueType(), Lo0, Lo1,
Op->getFlags());
7735 DAG.
getNode(
Opc, SL, Hi0.getValueType(), Hi0, Hi1,
Op->getFlags());
7742 unsigned Opc =
Op.getOpcode();
7743 EVT VT =
Op.getValueType();
7760 DAG.
getNode(
Opc, SL, ResVT.first, Lo0, Lo1, Lo2,
Op->getFlags());
7762 DAG.
getNode(
Opc, SL, ResVT.second, Hi0, Hi1, Hi2,
Op->getFlags());
7768 switch (
Op.getOpcode()) {
7772 return LowerBRCOND(
Op, DAG);
7774 return LowerRETURNADDR(
Op, DAG);
7776 return lowerFrameIndex(
Op, DAG);
7778 return LowerSPONENTRY(
Op, DAG);
7781 assert((!Result.getNode() || Result.getNode()->getNumValues() == 2) &&
7782 "Load should return a value and a chain");
7786 EVT VT =
Op.getValueType();
7788 return lowerFSQRTF32(
Op, DAG);
7790 return lowerFSQRTF64(
Op, DAG);
7795 return LowerTrig(
Op, DAG);
7797 return LowerSELECT(
Op, DAG);
7799 return LowerFDIV(
Op, DAG);
7801 return LowerFFREXP(
Op, DAG);
7803 return LowerATOMIC_CMP_SWAP(
Op, DAG);
7805 return LowerSTORE(
Op, DAG);
7809 return LowerGlobalAddress(MFI,
Op, DAG);
7814 return LowerExternalSymbol(
Op, DAG);
7816 return LowerINTRINSIC_WO_CHAIN(
Op, DAG);
7818 return LowerCONVERT_FROM_ARBITRARY_FP(
Op, DAG);
7820 return LowerCONVERT_TO_ARBITRARY_FP(
Op, DAG);
7822 return LowerINTRINSIC_W_CHAIN(
Op, DAG);
7824 return LowerINTRINSIC_VOID(
Op, DAG);
7826 return lowerADDRSPACECAST(
Op, DAG);
7828 return lowerINSERT_SUBVECTOR(
Op, DAG);
7830 return lowerINSERT_VECTOR_ELT(
Op, DAG);
7832 return lowerEXTRACT_VECTOR_ELT(
Op, DAG);
7834 return lowerVECTOR_SHUFFLE(
Op, DAG);
7836 return lowerSCALAR_TO_VECTOR(
Op, DAG);
7838 return lowerBUILD_VECTOR(
Op, DAG);
7841 return lowerFP_ROUND(
Op, DAG);
7843 return lowerTRAP(
Op, DAG);
7845 return lowerDEBUGTRAP(
Op, DAG);
7854 if (
Op.getValueType().isVector() &&
Op.getValueType() != MVT::v2i16 &&
7855 Op.getOperand(0).getValueType().getScalarType() == MVT::f32)
7859 if (
Op.getValueType() == MVT::bf16) {
7889 return lowerFMINNUM_FMAXNUM(
Op, DAG);
7892 return lowerFMINIMUMNUM_FMAXIMUMNUM(
Op, DAG);
7895 return lowerFLDEXP(
Op, DAG);
7900 if (Subtarget->hasVCvtPkIU16F32() &&
Op.getValueType() == MVT::i16 &&
7901 Op.getOperand(0).getValueType() == MVT::f32) {
7927 return lowerFCOPYSIGN(
Op, DAG);
7929 return lowerMUL(
Op, DAG);
7932 return lowerXMULO(
Op, DAG);
7935 return lowerXMUL_LOHI(
Op, DAG);
7956 return LowerINLINEASM(
Op, DAG);
7962static std::pair<SDValue, SDValue>
7992 EVT FittingLoadVT = LoadVT;
8024SDValue SITargetLowering::adjustLoadValueType(
unsigned Opcode,
MemSDNode *M,
8027 bool IsIntrinsic)
const {
8030 bool IsTFE =
M->getNumValues() == 3;
8031 bool Unpacked = Subtarget->hasUnpackedD16VMem();
8032 EVT LoadVT =
M->getValueType(0);
8034 EVT EquivLoadVT = LoadVT;
8051 SDVTList VTList = DAG.
getVTList(LoadDWordsVT, MVT::Other);
8053 Opcode,
DL, VTList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
8061 SDVTList VTList = DAG.
getVTList(EquivLoadVT, MVT::Other);
8065 M->getMemoryVT(),
M->getMemOperand());
8076 EVT LoadVT =
M->getValueType(0);
8085 "unsupported sub-dword format buffer load",
DL.getDebugLoc()));
8089 assert(
M->getNumValues() == 2 ||
M->getNumValues() == 3);
8090 bool IsTFE =
M->getNumValues() == 3;
8092 if (IsD16 && IsTFE && !Subtarget->hasBufferTFEFormatD16()) {
8095 "TFE D16 format buffer load is not supported on this GPU",
8098 M->getOperand(0),
DL);
8101 unsigned Opc = IsD16 ? (IsTFE ? AMDGPUISD::BUFFER_LOAD_FORMAT_D16_TFE
8102 : AMDGPUISD::BUFFER_LOAD_FORMAT_D16)
8103 : IsFormat ? (IsTFE ? AMDGPUISD::BUFFER_LOAD_FORMAT_TFE
8104 : AMDGPUISD::BUFFER_LOAD_FORMAT)
8105 : IsTFE ? AMDGPUISD::BUFFER_LOAD_TFE
8106 : AMDGPUISD::BUFFER_LOAD;
8109 return adjustLoadValueType(
Opc, M, DAG,
Ops);
8113 return handleByteShortBufferLoads(DAG, LoadVT,
DL,
Ops,
M->getMemOperand(),
8117 return getMemIntrinsicNode(
Opc,
DL,
M->getVTList(),
Ops, IntVT,
8118 M->getMemOperand(), DAG);
8122 SDVTList VTList = IsTFE ? DAG.
getVTList(CastVT, MVT::i32, MVT::Other)
8125 M->getMemOperand(), DAG);
8135 EVT VT =
N->getValueType(0);
8159 Exec = AMDGPU::EXEC_LO;
8161 Exec = AMDGPU::EXEC;
8178 bool Signed = IntrinsicID == Intrinsic::amdgcn_sbfe;
8180 EVT VT =
Op.getValueType();
8185 if (VT != MVT::i32) {
8193 return DAG.
getNode(
Signed ? AMDGPUISD::BFE_I32 : AMDGPUISD::BFE_U32,
DL, VT,
8202 EVT VT =
N->getValueType(0);
8204 unsigned IID =
N->getConstantOperandVal(0);
8205 bool IsPermLane16 = IID == Intrinsic::amdgcn_permlane16 ||
8206 IID == Intrinsic::amdgcn_permlanex16;
8207 bool IsSetInactive = IID == Intrinsic::amdgcn_set_inactive ||
8208 IID == Intrinsic::amdgcn_set_inactive_chain_arg;
8209 bool IsPermlaneShuffle = IID == Intrinsic::amdgcn_permlane_bcast ||
8210 IID == Intrinsic::amdgcn_permlane_up ||
8211 IID == Intrinsic::amdgcn_permlane_down ||
8212 IID == Intrinsic::amdgcn_permlane_xor;
8217 unsigned SplitSize = 32;
8218 if (IID == Intrinsic::amdgcn_update_dpp && (ValSize % 64 == 0) &&
8219 ST->hasDPALU_DPP() &&
8227 case Intrinsic::amdgcn_permlane16:
8228 case Intrinsic::amdgcn_permlanex16:
8229 case Intrinsic::amdgcn_update_dpp:
8234 case Intrinsic::amdgcn_writelane:
8235 case Intrinsic::amdgcn_permlane_bcast:
8236 case Intrinsic::amdgcn_permlane_up:
8237 case Intrinsic::amdgcn_permlane_down:
8238 case Intrinsic::amdgcn_permlane_xor:
8241 case Intrinsic::amdgcn_readlane:
8242 case Intrinsic::amdgcn_set_inactive:
8243 case Intrinsic::amdgcn_set_inactive_chain_arg:
8244 case Intrinsic::amdgcn_mov_dpp8:
8247 case Intrinsic::amdgcn_readfirstlane:
8248 case Intrinsic::amdgcn_permlane64:
8258 if (
SDNode *GL =
N->getGluedNode()) {
8260 GL = GL->getOperand(0).getNode();
8270 if (IID == Intrinsic::amdgcn_readlane || IID == Intrinsic::amdgcn_writelane ||
8271 IID == Intrinsic::amdgcn_mov_dpp8 ||
8272 IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16 ||
8273 IsPermlaneShuffle) {
8274 Src1 =
N->getOperand(2);
8275 if (IID == Intrinsic::amdgcn_writelane ||
8276 IID == Intrinsic::amdgcn_update_dpp || IsPermLane16 ||
8278 Src2 =
N->getOperand(3);
8281 if (ValSize == SplitSize) {
8291 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16) {
8296 if (IID == Intrinsic::amdgcn_writelane) {
8301 SDValue LaneOp = createLaneOp(Src0, Src1, Src2, MVT::i32);
8306 if (ValSize % SplitSize != 0)
8310 EVT VT =
N->getValueType(0);
8314 unsigned NumOperands =
N->getNumOperands();
8316 SDNode *GL =
N->getGluedNode();
8321 for (
unsigned i = 0; i != NE; ++i) {
8322 for (
unsigned j = 0, e = GL ? NumOperands - 1 : NumOperands; j != e;
8324 SDValue Operand =
N->getOperand(j);
8354 if (SplitSize == 32) {
8356 return unrollLaneOp(LaneOp.
getNode());
8362 unsigned SubVecNumElt =
8366 SDValue Src0SubVec, Src1SubVec, Src2SubVec;
8367 for (
unsigned i = 0, EltIdx = 0; i < ValSize / SplitSize; i++) {
8371 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive ||
8377 createLaneOp(Src0SubVec, Src1SubVec, Src2, SubVecVT));
8378 }
else if (IID == Intrinsic::amdgcn_writelane) {
8382 createLaneOp(Src0SubVec, Src1, Src2SubVec, SubVecVT));
8384 Pieces.
push_back(createLaneOp(Src0SubVec, Src1, Src2, SubVecVT));
8387 EltIdx += SubVecNumElt;
8401 if (IID == Intrinsic::amdgcn_update_dpp || IsSetInactive || IsPermLane16)
8404 if (IID == Intrinsic::amdgcn_writelane)
8407 SDValue LaneOp = createLaneOp(Src0, Src1, Src2, VecVT);
8414 EVT VT =
N->getValueType(0);
8432 auto MakeIntrinsic = [&DAG, &SL](
unsigned IID,
MVT RetVT,
8441 if (
TLI.getSubtarget()->supportsWaveWideBPermute()) {
8442 SDValue BPermute = MakeIntrinsic(Intrinsic::amdgcn_ds_bpermute, MVT::i32,
8443 {ShiftedIndex, ValueI32});
8453 SDValue WWMValue = MakeIntrinsic(Intrinsic::amdgcn_set_inactive, MVT::i32,
8454 {ValueI32, PoisonVal});
8455 SDValue WWMIndex = MakeIntrinsic(Intrinsic::amdgcn_set_inactive, MVT::i32,
8456 {ShiftedIndex, PoisonVal});
8459 MakeIntrinsic(Intrinsic::amdgcn_permlane64, MVT::i32, {WWMValue});
8462 SDValue BPermSameHalf = MakeIntrinsic(Intrinsic::amdgcn_ds_bpermute, MVT::i32,
8463 {WWMIndex, WWMValue});
8464 SDValue BPermOtherHalf = MakeIntrinsic(Intrinsic::amdgcn_ds_bpermute,
8465 MVT::i32, {WWMIndex, Swapped});
8467 MakeIntrinsic(Intrinsic::amdgcn_wwm, MVT::i32, {BPermOtherHalf});
8475 MakeIntrinsic(Intrinsic::amdgcn_mbcnt_lo, MVT::i32,
8483 DAG.
getSetCC(SL, MVT::i1, SameOrOtherHalf,
8493 switch (
N->getOpcode()) {
8510 unsigned IID =
N->getConstantOperandVal(0);
8512 case Intrinsic::amdgcn_wave_reduce_min:
8513 case Intrinsic::amdgcn_wave_reduce_umin:
8514 case Intrinsic::amdgcn_wave_reduce_max:
8515 case Intrinsic::amdgcn_wave_reduce_umax:
8516 case Intrinsic::amdgcn_wave_reduce_add:
8517 case Intrinsic::amdgcn_wave_reduce_sub:
8518 case Intrinsic::amdgcn_wave_reduce_and:
8519 case Intrinsic::amdgcn_wave_reduce_or:
8520 case Intrinsic::amdgcn_wave_reduce_xor: {
8521 EVT VT =
N->getValueType(0);
8525 bool NeedsSignExt = IID == Intrinsic::amdgcn_wave_reduce_min ||
8526 IID == Intrinsic::amdgcn_wave_reduce_max ||
8527 IID == Intrinsic::amdgcn_wave_reduce_add ||
8528 IID == Intrinsic::amdgcn_wave_reduce_sub;
8532 N->getOperand(0), ExtSrc,
N->getOperand(2));
8536 case Intrinsic::amdgcn_make_buffer_rsrc:
8537 Results.push_back(lowerPointerAsRsrcIntrin(
N, DAG));
8539 case Intrinsic::amdgcn_cvt_pkrtz: {
8544 DAG.
getNode(AMDGPUISD::CVT_PKRTZ_F16_F32, SL, MVT::i32, Src0, Src1);
8548 case Intrinsic::amdgcn_cvt_pknorm_i16:
8549 case Intrinsic::amdgcn_cvt_pknorm_u16:
8550 case Intrinsic::amdgcn_cvt_pk_i16:
8551 case Intrinsic::amdgcn_cvt_pk_u16: {
8557 if (IID == Intrinsic::amdgcn_cvt_pknorm_i16)
8558 Opcode = AMDGPUISD::CVT_PKNORM_I16_F32;
8559 else if (IID == Intrinsic::amdgcn_cvt_pknorm_u16)
8560 Opcode = AMDGPUISD::CVT_PKNORM_U16_F32;
8561 else if (IID == Intrinsic::amdgcn_cvt_pk_i16)
8562 Opcode = AMDGPUISD::CVT_PK_I16_I32;
8564 Opcode = AMDGPUISD::CVT_PK_U16_U32;
8566 EVT VT =
N->getValueType(0);
8575 case Intrinsic::amdgcn_s_buffer_load: {
8577 EVT VT =
Op.getValueType();
8579 Op.getOperand(1),
Op.getOperand(2),
8580 Op.getOperand(3), DAG));
8583 case Intrinsic::amdgcn_dead: {
8584 for (
unsigned I = 0, E =
N->getNumValues();
I < E; ++
I)
8592 if (
N->getConstantOperandVal(1) != Intrinsic::amdgcn_ptr_s_buffer_load &&
8593 N->getValueType(0).isSimple() &&
8594 SBufferLoadDiagnosticVTs[
N->getSimpleValueType(0).SimpleTy])
8599 for (
unsigned I = 0;
I < Res.getNumOperands();
I++) {
8600 Results.push_back(Res.getOperand(
I));
8603 for (
unsigned I = 0;
I <
N->getNumValues(); ++
I)
8604 Results.push_back(Res.getValue(
I));
8613 EVT VT =
N->getValueType(0);
8618 EVT SelectVT = NewVT;
8619 if (NewVT.
bitsLT(MVT::i32)) {
8622 SelectVT = MVT::i32;
8628 if (NewVT != SelectVT)
8634 if (
N->getValueType(0) != MVT::v2f16)
8646 if (
N->getValueType(0) != MVT::v2f16)
8658 if (
N->getValueType(0) != MVT::f16)
8673 if (U.get() !=
Value)
8676 if (U.getUser()->getOpcode() == Opcode)
8682unsigned SITargetLowering::isCFIntrinsic(
const SDNode *Intr)
const {
8685 case Intrinsic::amdgcn_if:
8686 return AMDGPUISD::IF;
8687 case Intrinsic::amdgcn_else:
8688 return AMDGPUISD::ELSE;
8689 case Intrinsic::amdgcn_loop:
8690 return AMDGPUISD::LOOP;
8691 case Intrinsic::amdgcn_end_cf:
8711 if (Subtarget->isAmdPalOS() || Subtarget->isMesa3DOS())
8735 assert(GVar->isDeclaration() &&
8736 "AS 3 & 13 GVs should be declaration here "
8737 "when object linking is enabled");
8752 SDNode *Intr = BRCOND.getOperand(1).getNode();
8769 Intr =
LHS.getNode();
8777 assert(BR &&
"brcond missing unconditional branch user");
8782 unsigned CFNode = isCFIntrinsic(Intr);
8800 Ops.push_back(Target);
8823 for (
unsigned i = 1, e = Intr->
getNumValues() - 1; i != e; ++i) {
8842 MVT VT =
Op.getSimpleValueType();
8845 if (
Op.getConstantOperandVal(0) != 0)
8849 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8851 if (
Info->isEntryFunction())
8868 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
8882 return Op.getValueType().bitsLE(VT)
8890 EVT DstVT =
Op.getValueType();
8897 unsigned Opc =
Op.getOpcode();
8908 bool IsStrict =
Op->isStrictFPOpcode();
8909 SDValue Src =
Op.getOperand(IsStrict ? 1 : 0);
8910 EVT SrcVT = Src.getValueType();
8911 EVT DstVT =
Op.getValueType();
8914 assert(Subtarget->hasCvtPkF16F32Inst() &&
"support v_cvt_pk_f16_f32");
8917 return SrcVT == MVT::v2f32 ?
Op : splitFP_ROUNDVectorOp(
Op, DAG);
8924 if (DstVT == MVT::f16) {
8929 if (!Subtarget->has16BitInsts()) {
8934 if (
Op->getFlags().hasApproximateFuncs()) {
8945 "custom lower FP_ROUND for f16 or bf16");
8946 assert(Subtarget->hasBF16ConversionInsts() &&
"f32 -> bf16 is legal");
8963 EVT VT =
Op.getValueType();
8965 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8966 bool IsIEEEMode =
Info->getMode().IEEE;
8972 if (IsIEEEMode && !Subtarget->hasIEEEMinimumMaximumInsts())
8975 if (VT == MVT::v4f16 || VT == MVT::v8f16 || VT == MVT::v16f16 ||
8976 VT == MVT::v32f16 || VT == MVT::v4bf16 || VT == MVT::v8bf16 ||
8977 VT == MVT::v16bf16 || VT == MVT::v32bf16 || VT == MVT::v4f64 ||
8978 VT == MVT::v8f64 || VT == MVT::v16f64 || VT == MVT::v32f64)
8984SITargetLowering::lowerFMINIMUMNUM_FMAXIMUMNUM(
SDValue Op,
8986 EVT VT =
Op.getValueType();
8988 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
8989 bool IsIEEEMode =
Info->getMode().IEEE;
8991 if (IsIEEEMode && !Subtarget->hasIEEEMinimumMaximumInsts())
8994 if (VT == MVT::v4f16 || VT == MVT::v8f16 || VT == MVT::v16f16 ||
8995 VT == MVT::v32f16 || VT == MVT::v4bf16 || VT == MVT::v8bf16 ||
8996 VT == MVT::v16bf16 || VT == MVT::v32bf16 || VT == MVT::v4f64 ||
8997 VT == MVT::v8f64 || VT == MVT::v16f64 || VT == MVT::v32f64)
9004 EVT VT =
Op.getValueType();
9008 EVT ExpVT =
Exp.getValueType();
9009 if (ExpVT == MVT::i16)
9030 {
Op.getOperand(0),
Op.getOperand(1), TruncExp});
9037 switch (
Op->getOpcode()) {
9070SITargetLowering::promoteUniformUnaryOpToI32(
SDValue Op,
9071 DAGCombinerInfo &DCI)
const {
9072 EVT OpTy =
Op.getValueType();
9073 SelectionDAG &DAG = DCI.DAG;
9090 DAGCombinerInfo &DCI)
const {
9091 const unsigned Opc =
Op.getOpcode();
9100 :
Op->getOperand(0).getValueType();
9101 auto &DAG = DCI.DAG;
9104 if (DCI.isBeforeLegalizeOps() ||
9112 LHS =
Op->getOperand(1);
9113 RHS =
Op->getOperand(2);
9115 LHS =
Op->getOperand(0);
9116 RHS =
Op->getOperand(1);
9158 EVT SignVT =
Sign.getValueType();
9160 if (MagVT == SignVT)
9181 EVT VT =
Op.getValueType();
9187 assert(VT == MVT::i64 &&
"The following code is a special for s_mul_u64");
9214 if (
Op->isDivergent())
9227 if (Op0LeadingZeros >= 32 && Op1LeadingZeros >= 32)
9229 DAG.
getMachineNode(AMDGPU::S_MUL_U64_U32_PSEUDO, SL, VT, Op0, Op1), 0);
9232 if (Op0SignBits >= 33 && Op1SignBits >= 33)
9234 DAG.
getMachineNode(AMDGPU::S_MUL_I64_I32_PSEUDO, SL, VT, Op0, Op1), 0);
9240 EVT VT =
Op.getValueType();
9247 const APInt &
C = RHSC->getAPIntValue();
9249 if (
C.isPowerOf2()) {
9251 bool UseArithShift =
isSigned && !
C.isMinSignedValue();
9278 if (
Op->isDivergent()) {
9282 if (Subtarget->hasSMulHi()) {
9293 if (!Subtarget->hasTrapHandler() ||
9295 return lowerTrapEndpgm(
Op, DAG);
9297 return Subtarget->supportsGetDoorbellID() ? lowerTrapHsa(
Op, DAG)
9298 : lowerTrapHsaQueuePtr(
Op, DAG);
9304 return DAG.
getNode(AMDGPUISD::ENDPGM_TRAP, SL, MVT::Other, Chain);
9308SITargetLowering::loadImplicitKernelArgument(
SelectionDAG &DAG,
MVT VT,
9310 ImplicitParameter Param)
const {
9314 MachinePointerInfo PtrInfo =
9331 loadImplicitKernelArgument(DAG, MVT::i64, SL,
Align(8),
QUEUE_PTR);
9334 SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
9337 if (UserSGPR == AMDGPU::NoRegister) {
9354 return DAG.
getNode(AMDGPUISD::TRAP, SL, MVT::Other,
Ops);
9363 if (Subtarget->hasPrivEnabledTrap2NopBug())
9364 return DAG.
getNode(AMDGPUISD::SIMULATED_TRAP, SL, MVT::Other, Chain);
9368 return DAG.
getNode(AMDGPUISD::TRAP, SL, MVT::Other,
Ops);
9376 if (!Subtarget->hasTrapHandler() ||
9380 "debugtrap handler not supported",
9388 return DAG.
getNode(AMDGPUISD::TRAP, SL, MVT::Other,
Ops);
9398 const SIRegisterInfo *
TRI = Subtarget->getRegisterInfo();
9399 SmallSet<Register, 8> SGPRInputRegs;
9401 unsigned NumVals = 0;
9404 const InlineAsm::Flag
Flags(
Op.getConstantOperandVal(
I));
9405 NumVals =
Flags.getNumOperandRegisters();
9409 NumVals > 0 &&
Flags.hasRegClassConstraint(RCID) &&
9410 TRI->isSGPRClass(
TRI->getRegClass(RCID));
9412 for (
unsigned J = 0; J < NumVals; ++J) {
9414 if (
const RegisterSDNode *RegNode =
9423 if (SGPRInputRegs.
empty())
9428 SDNode *
N =
Op.getOperand(
NumOps - 1).getNode();
9440 ReadFirstLaneID, SrcVal);
9444 if (
N->getNumOperands() > 3)
9445 Ops.push_back(
N->getOperand(3));
9451 SDNode *
Next =
nullptr;
9452 for (
unsigned I = 0,
E =
N->getNumOperands();
I !=
E; ++
I) {
9453 if (
N->getOperand(
I).getValueType() == MVT::Glue) {
9454 Next =
N->getOperand(
I).getNode();
9464SDValue SITargetLowering::getSegmentAperture(
unsigned AS,
const SDLoc &
DL,
9466 unsigned BaseAS = AS;
9471 SDValue Aperture = getBaseSegmentAperture(BaseAS,
DL, DAG);
9481SDValue SITargetLowering::getBaseSegmentAperture(
unsigned AS,
const SDLoc &
DL,
9485 if (Subtarget->hasApertureRegs()) {
9486 const unsigned ApertureRegNo =
9487 IsLDS ? AMDGPU::SRC_SHARED_BASE : AMDGPU::SRC_PRIVATE_BASE;
9488 assert((ApertureRegNo != AMDGPU::SRC_PRIVATE_BASE ||
9489 !Subtarget->hasGloballyAddressableScratch()) &&
9490 "Cannot use src_private_base with globally addressable scratch!");
9510 return loadImplicitKernelArgument(DAG, MVT::i32,
DL,
Align(4), Param);
9514 SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
9516 if (UserSGPR == AMDGPU::NoRegister) {
9527 uint32_t StructOffset = IsLDS ? 0x40 : 0x44;
9561 const AMDGPUTargetMachine &TM =
9565 unsigned SrcAS = ASC->getSrcAddressSpace();
9566 SDValue Src = ASC->getOperand(0);
9567 unsigned DestAS = ASC->getDestAddressSpace();
9568 bool IsNonNull = ASC->getFlags().hasNonNull();
9580 Subtarget->hasGloballyAddressableScratch()) {
9585 AMDGPU::S_MOV_B32, SL, MVT::i32,
9586 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE_LO, MVT::i32)),
9610 Subtarget->hasGloballyAddressableScratch()) {
9619 if (Subtarget->isWave64())
9625 57 - 32 - Subtarget->getWavefrontSizeLog2(), MVT::i32, SL);
9633 AMDGPU::S_MOV_B64, SL, MVT::i64,
9634 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE, MVT::i64)),
9636 CvtPtr = DAG.
getNode(
ISD::ADD, SL, MVT::i64, CvtPtr, FlatScratchBase);
9638 SDValue Aperture = getSegmentAperture(SrcAS, SL, DAG);
9659 Op.getValueType() == MVT::i64) {
9660 const SIMachineFunctionInfo *
Info =
9662 if (
Info->get32BitAddressHighBits() == 0)
9671 Src.getValueType() == MVT::i64)
9694 unsigned IdxVal =
Idx->getAsZExtVal();
9699 assert(InsNumElts % 2 == 0 &&
"expect legal vector types");
9704 EVT NewInsVT = InsNumElts == 2 ? MVT::i32
9706 MVT::i32, InsNumElts / 2);
9711 for (
unsigned I = 0;
I != InsNumElts / 2; ++
I) {
9713 if (InsNumElts == 2) {
9726 for (
unsigned I = 0;
I != InsNumElts; ++
I) {
9749 if (NumElts == 4 && EltSize == 16 && KIdx) {
9760 unsigned Idx = KIdx->getZExtValue();
9761 bool InsertLo =
Idx < 2;
9765 DAG.
getConstant(InsertLo ? Idx : (Idx - 2), SL, MVT::i32));
9771 : DAG.getBuildVector(MVT::v2i32, SL, {LoHalf, InsHalf});
9785 unsigned PieceSize = std::min(VecSize, 64u);
9786 unsigned NumPieces =
VecSize / PieceSize;
9787 unsigned EltsPerPiece = PieceSize / EltSize;
9822 InsertIntoPiece(DAG.
getBitcast(IntVT, Vec), BFM));
9834 for (
unsigned I = 0;
I != NumPieces; ++
I) {
9840 Pieces.
push_back(InsertIntoPiece(Piece, Mask));
9850 EVT ResultVT =
Op.getValueType();
9863 if (
SDValue Combined = performExtractVectorEltCombine(
Op.getNode(), DCI))
9866 if (VecSize == 128 || VecSize == 256 || VecSize == 512) {
9870 if (VecSize == 128) {
9878 }
else if (VecSize == 256) {
9881 for (
unsigned P = 0;
P < 4; ++
P) {
9887 Parts[0], Parts[1]));
9889 Parts[2], Parts[3]));
9895 for (
unsigned P = 0;
P < 8; ++
P) {
9902 Parts[0], Parts[1], Parts[2], Parts[3]));
9905 Parts[4], Parts[5], Parts[6], Parts[7]));
9908 EVT IdxVT =
Idx.getValueType();
9925 Src = DAG.
getBitcast(Src.getValueType().changeTypeToInteger(), Src);
9940 if (ResultVT == MVT::f16 || ResultVT == MVT::bf16) {
9950 return Mask[Elt + 1] == Mask[Elt] + 1 && (Mask[Elt] % 2 == 0);
9955 return Mask[Elt] >= 0 && Mask[Elt + 1] >= 0 && (Mask[Elt] & 1) &&
9956 !(Mask[Elt + 1] & 1);
9962 EVT ResultVT =
Op.getValueType();
9965 const int NewSrcNumElts = 2;
9967 int SrcNumElts =
Op.getOperand(0).getValueType().getVectorNumElements();
9983 const bool ShouldUseConsecutiveExtract = EltVT.
getSizeInBits() == 16;
10005 if (ShouldUseConsecutiveExtract &&
10008 int VecIdx =
Idx < SrcNumElts ? 0 : 1;
10009 int EltIdx =
Idx < SrcNumElts ?
Idx :
Idx - SrcNumElts;
10021 if (Idx0 >= SrcNumElts) {
10023 Idx0 -= SrcNumElts;
10026 if (Idx1 >= SrcNumElts) {
10028 Idx1 -= SrcNumElts;
10031 int AlignedIdx0 = Idx0 & ~(NewSrcNumElts - 1);
10032 int AlignedIdx1 = Idx1 & ~(NewSrcNumElts - 1);
10040 int NewMaskIdx0 = Idx0 - AlignedIdx0;
10041 int NewMaskIdx1 = Idx1 - AlignedIdx1;
10046 if (SubVec0 != SubVec1) {
10047 NewMaskIdx1 += NewSrcNumElts;
10054 {NewMaskIdx0, NewMaskIdx1});
10059 int VecIdx0 = Idx0 < SrcNumElts ? 0 : 1;
10060 int VecIdx1 = Idx1 < SrcNumElts ? 0 : 1;
10061 int EltIdx0 = Idx0 < SrcNumElts ? Idx0 : Idx0 - SrcNumElts;
10062 int EltIdx1 = Idx1 < SrcNumElts ? Idx1 : Idx1 - SrcNumElts;
10081 EVT ResultVT =
Op.getValueType();
10097 EVT VT =
Op.getValueType();
10099 if (VT == MVT::v2f16 || VT == MVT::v2i16 || VT == MVT::v2bf16) {
10100 assert(!Subtarget->hasVOP3PInsts() &&
"this should be legal");
10106 if (
Hi.isUndef()) {
10136 PartVT, SL, {
Op.getOperand(
P * 2),
Op.getOperand(
P * 2 + 1)});
10162 if (!Subtarget->isAmdHsaOS())
10205 return DAG.
getNode(AMDGPUISD::PC_ADD_REL_OFFSET64,
DL, PtrVT, Ptr);
10214 return DAG.
getNode(AMDGPUISD::PC_ADD_REL_OFFSET,
DL, PtrVT, PtrLo, PtrHi);
10222 EVT PtrVT =
Op.getValueType();
10224 const GlobalValue *GV = GSD->
getGlobal();
10237 assert(PtrVT == MVT::i32 &&
"32-bit pointer is expected.");
10258 return DAG.
getNode(AMDGPUISD::LDS,
DL, MVT::i32, GA);
10261 if (Subtarget->isAmdPalOS() || Subtarget->isMesa3DOS()) {
10262 if (Subtarget->has64BitLiterals()) {
10271 AddrLo = {DAG.
getMachineNode(AMDGPU::S_MOV_B32,
DL, MVT::i32, AddrLo), 0};
10275 AddrHi = {DAG.
getMachineNode(AMDGPU::S_MOV_B32,
DL, MVT::i32, AddrHi), 0};
10293 MachinePointerInfo PtrInfo =
10313 "unsupported alloca in VGPR 'as memory' address space (13)",
10323 Fn,
"unsupported external symbol",
Op.getDebugLoc()));
10345 unsigned Offset)
const {
10347 SDValue Param = lowerKernargMemParameter(
10358 "non-hsa intrinsic with hsa target",
DL.getDebugLoc()));
10366 "intrinsic not supported on subtarget",
DL.getDebugLoc()));
10374 unsigned NumElts = Elts.
size();
10376 if (NumElts <= 12) {
10380 Type = MVT::v16f32;
10385 for (
unsigned i = 0; i < Elts.
size(); ++i) {
10391 for (
unsigned i = Elts.
size(); i < NumElts; ++i)
10400 SDValue Src,
int ExtraElts) {
10401 EVT SrcVT = Src.getValueType();
10411 while (ExtraElts--)
10422 bool Unpacked,
bool IsD16,
int DMaskPop,
10423 int NumVDataDwords,
bool IsAtomicPacked16Bit,
10427 EVT ReqRetVT = ResultTypes[0];
10429 int NumDataDwords = ((IsD16 && !Unpacked) || IsAtomicPacked16Bit)
10430 ? (ReqRetNumElts + 1) / 2
10433 int MaskPopDwords = (!IsD16 || Unpacked) ? DMaskPop : (DMaskPop + 1) / 2;
10436 NumDataDwords == 1 ? MVT::i32 :
MVT::getVectorVT(MVT::i32, NumDataDwords);
10439 MaskPopDwords == 1 ? MVT::i32 :
MVT::getVectorVT(MVT::i32, MaskPopDwords);
10444 if (DMaskPop > 0 &&
Data.getValueType() != MaskPopVT) {
10448 SDValue(Result, 0), ZeroIdx);
10451 SDValue(Result, 0), ZeroIdx);
10455 if (DataDwordVT.
isVector() && !IsAtomicPacked16Bit)
10457 NumDataDwords - MaskPopDwords);
10462 EVT LegalReqRetVT = ReqRetVT;
10464 if (!
Data.getValueType().isInteger())
10466 Data.getValueType().changeTypeToInteger(),
Data);
10487 if (Result->getNumValues() == 1)
10494 SDValue *LWE,
bool &IsTexFail) {
10514 unsigned DimIdx,
unsigned EndIdx,
10515 unsigned NumGradients) {
10517 for (
unsigned I = DimIdx;
I < EndIdx;
I++) {
10525 if (((
I + 1) >= EndIdx) ||
10526 ((NumGradients / 2) % 2 == 1 && (
I == DimIdx + (NumGradients / 2) - 1 ||
10527 I == DimIdx + NumGradients - 1))) {
10559 !
Op.getNode()->hasAnyUseOfValue(0))
10561 const AMDGPU::MIMGBaseOpcodeInfo *BaseOpcode =
10572 ResultTypes.erase(&ResultTypes[0]);
10574 bool IsD16 =
false;
10575 bool IsG16 =
false;
10576 bool IsA16 =
false;
10578 int NumVDataDwords = 0;
10579 bool AdjustRetType =
false;
10580 bool IsAtomicPacked16Bit =
false;
10583 const unsigned ArgOffset = WithChain ? 2 : 1;
10586 unsigned DMaskLanes = 0;
10588 if (BaseOpcode->
Atomic) {
10589 VData =
Op.getOperand(2);
10591 IsAtomicPacked16Bit =
10592 (IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_F16 ||
10593 IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_F16_NORTN ||
10594 IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_BF16 ||
10595 IntrOpcode == AMDGPU::IMAGE_ATOMIC_PK_ADD_BF16_NORTN);
10600 "unsupported image atomic data type");
10612 ResultTypes[0] = Is64Bit ? MVT::v2i64 : MVT::v2i32;
10614 DMask = Is64Bit ? 0xf : 0x3;
10615 NumVDataDwords = Is64Bit ? 4 : 2;
10617 DMask = Is64Bit ? 0x3 : 0x1;
10618 NumVDataDwords = Is64Bit ? 2 : 1;
10621 DMask =
Op->getConstantOperandVal(ArgOffset + Intr->
DMaskIndex);
10624 if (BaseOpcode->
Store) {
10625 VData =
Op.getOperand(2);
10629 if (StoreScalarVT != MVT::f16 && StoreScalarVT.
getSizeInBits() != 32 &&
10632 "unsupported image store data type");
10634 if (StoreScalarVT == MVT::f16) {
10635 if (!Subtarget->hasD16Images() || !BaseOpcode->
HasD16)
10639 VData = handleD16VData(VData, DAG,
true);
10642 NumVDataDwords = (VData.
getValueType().getSizeInBits() + 31) / 32;
10643 }
else if (!BaseOpcode->
NoReturn) {
10648 if (LoadScalarVT != MVT::f16 && LoadScalarVT.
getSizeInBits() != 32 &&
10651 "unsupported image load data type");
10653 if (LoadScalarVT == MVT::f16) {
10654 if (!Subtarget->hasD16Images() || !BaseOpcode->
HasD16)
10662 (!LoadVT.
isVector() && DMaskLanes > 1))
10668 if (IsD16 && !Subtarget->hasUnpackedD16VMem() &&
10669 !(BaseOpcode->
Gather4 && Subtarget->hasImageGather4D16Bug()))
10670 NumVDataDwords = (DMaskLanes + 1) / 2;
10672 NumVDataDwords = DMaskLanes;
10674 AdjustRetType =
true;
10678 unsigned VAddrEnd = ArgOffset + Intr->
VAddrEnd;
10685 MVT GradPackVectorVT = VAddrScalarVT == MVT::f16 ? MVT::v2f16 : MVT::v2i16;
10686 IsG16 = VAddrScalarVT == MVT::f16 || VAddrScalarVT == MVT::i16;
10688 VAddrVT =
Op.getOperand(ArgOffset + Intr->
CoordStart).getSimpleValueType();
10690 MVT AddrPackVectorVT = VAddrScalarVT == MVT::f16 ? MVT::v2f16 : MVT::v2i16;
10691 IsA16 = VAddrScalarVT == MVT::f16 || VAddrScalarVT == MVT::i16;
10695 if (IsA16 && (
Op.getOperand(ArgOffset +
I).getValueType() == MVT::f16)) {
10701 {
Op.getOperand(ArgOffset +
I), DAG.
getPOISON(MVT::f16)});
10705 "Bias needs to be converted to 16 bit in A16 mode");
10710 if (BaseOpcode->
Gradients && !
ST->hasG16() && (IsA16 != IsG16)) {
10714 dbgs() <<
"Failed to lower image intrinsic: 16 bit addresses "
10715 "require 16 bit args for both gradients and addresses");
10720 if (!
ST->hasA16()) {
10721 LLVM_DEBUG(
dbgs() <<
"Failed to lower image intrinsic: Target does not "
10722 "support 16 bit addresses\n");
10732 if (BaseOpcode->
Gradients && IsG16 &&
ST->hasG16()) {
10734 const AMDGPU::MIMGG16MappingInfo *G16MappingInfo =
10736 IntrOpcode = G16MappingInfo->
G16;
10759 for (
unsigned I = ArgOffset + Intr->
CoordStart;
I < VAddrEnd;
I++)
10777 const unsigned NSAMaxSize =
ST->getNSAMaxSize(BaseOpcode->
Sampler);
10778 const bool HasPartialNSAEncoding =
ST->hasPartialNSAEncoding();
10779 const bool UseNSA =
ST->hasNSAEncoding() &&
10780 VAddrs.
size() >=
ST->getNSAThreshold(MF) &&
10781 (VAddrs.
size() <= NSAMaxSize || HasPartialNSAEncoding);
10782 const bool UsePartialNSA =
10783 UseNSA && HasPartialNSAEncoding && VAddrs.
size() > NSAMaxSize;
10786 if (UsePartialNSA) {
10788 ArrayRef(VAddrs).drop_front(NSAMaxSize - 1));
10789 }
else if (!UseNSA) {
10800 Op.getConstantOperandVal(ArgOffset + Intr->
UnormIndex);
10808 bool IsTexFail =
false;
10809 if (!
parseTexFail(TexFail, DAG, &TFE, &LWE, IsTexFail))
10818 NumVDataDwords = 1;
10820 NumVDataDwords += 1;
10821 AdjustRetType =
true;
10826 if (AdjustRetType) {
10829 if (DMaskLanes == 0 && !BaseOpcode->
Store) {
10838 MVT::i32, NumVDataDwords)
10841 ResultTypes[0] = NewVT;
10842 if (ResultTypes.size() == 3) {
10846 ResultTypes.erase(&ResultTypes[1]);
10860 Ops.push_back(VData);
10861 if (UsePartialNSA) {
10863 Ops.push_back(VAddr);
10867 Ops.push_back(VAddr);
10870 bool IndexedRsrc = IsGFX13 && RsrcVT == MVT::i32;
10871 if (RsrcVT != MVT::v4i32 && RsrcVT != MVT::v8i32 && !IndexedRsrc)
10873 Ops.push_back(Rsrc);
10874 bool IsSampIndexed =
false;
10878 IsSampIndexed = IsGFX13 && SampVT == MVT::i32;
10879 if (SampVT != MVT::v4i32 && !IsSampIndexed)
10881 Ops.push_back(Samp);
10886 if (!IsGFX12Plus || BaseOpcode->
Sampler || BaseOpcode->
MSAA)
10887 Ops.push_back(Unorm);
10889 Ops.push_back(IsA16 &&
10890 ST->hasFeature(AMDGPU::FeatureR128A16)
10896 if (!Subtarget->hasGFX90AInsts())
10897 Ops.push_back(TFE);
10901 "TFE is not supported on this GPU",
DL.getDebugLoc()));
10904 if (!IsGFX12Plus || BaseOpcode->
Sampler || BaseOpcode->
MSAA)
10905 Ops.push_back(LWE);
10911 Ops.push_back(
Op.getOperand(0));
10913 int NumVAddrDwords =
10920 NumVAddrDwords, IndexedRsrc, IsSampIndexed);
10921 }
else if (IsGFX12Plus) {
10923 NumVDataDwords, NumVAddrDwords);
10924 }
else if (IsGFX11Plus) {
10926 UseNSA ? AMDGPU::MIMGEncGfx11NSA
10927 : AMDGPU::MIMGEncGfx11Default,
10928 NumVDataDwords, NumVAddrDwords);
10929 }
else if (IsGFX10Plus) {
10931 UseNSA ? AMDGPU::MIMGEncGfx10NSA
10932 : AMDGPU::MIMGEncGfx10Default,
10933 NumVDataDwords, NumVAddrDwords);
10935 if (Subtarget->hasGFX90AInsts()) {
10937 NumVDataDwords, NumVAddrDwords);
10938 if (Opcode == -1) {
10940 DAG,
Op, OrigResultTypes,
DL,
10941 "requested image instruction is not supported on this GPU");
10944 if (Opcode == -1 &&
10947 NumVDataDwords, NumVAddrDwords);
10950 NumVDataDwords, NumVAddrDwords);
10957 MachineMemOperand *MemRef = MemOp->getMemOperand();
10976 Subtarget->hasUnpackedD16VMem(), IsD16, DMaskLanes,
10977 NumVDataDwords, IsAtomicPacked16Bit,
DL);
10986 bool HasChainResult = MMO !=
nullptr;
10990 bool IsSubwordLoad = (MemVT == MVT::i8 || MemVT == MVT::i16) &&
10991 Subtarget->hasScalarSubwordLoads();
10994 MF.
getFunction(),
"unsupported s_buffer_load result type",
10995 DL.getDebugLoc()));
10996 EVT ResultTypes[] = {VT, MVT::Other};
10998 ArrayRef(ResultTypes, HasChainResult ? 2 : 1), Chain,
DL);
11001 if (!HasChainResult) {
11013 if (!
Offset->isDivergent()) {
11021 auto HandleScalarSubwordLoads = [&](
unsigned Opcode) ->
SDValue {
11023 Opcode,
DL, DAG.
getVTList(MVT::i32, MVT::Other),
Ops, MemVT, MMO);
11026 if (HasChainResult)
11030 if (MemVT == MVT::i8 && Subtarget->hasScalarSubwordLoads())
11031 return HandleScalarSubwordLoads(AMDGPUISD::SBUFFER_LOAD_UBYTE);
11033 if (MemVT == MVT::i16 && Subtarget->hasScalarSubwordLoads())
11034 return HandleScalarSubwordLoads(AMDGPUISD::SBUFFER_LOAD_USHORT);
11039 !Subtarget->hasScalarDwordx3Loads()) {
11043 AMDGPUISD::SBUFFER_LOAD,
DL, DAG.
getVTList(WidenedVT, MVT::Other),
11048 if (HasChainResult)
11070 if ((MemVT == MVT::i8 || MemVT == MVT::i16) &&
11071 Subtarget->hasScalarSubwordLoads()) {
11075 if (HasChainResult)
11081 unsigned NumLoads = 1;
11087 if (NumElts == 8 || NumElts == 16) {
11088 NumLoads = NumElts / 4;
11092 SDVTList VTList = DAG.
getVTList({LoadVT, MVT::Other});
11097 NumLoads > 1 ?
Align(16 * NumLoads) :
Align(4));
11101 for (
unsigned i = 0; i < NumLoads; ++i) {
11104 Loads.
push_back(getMemIntrinsicNode(AMDGPUISD::BUFFER_LOAD,
DL, VTList,
Ops,
11105 LoadVT, LoadMMO, DAG));
11108 if (NumElts == 8 || NumElts == 16) {
11110 if (HasChainResult) {
11125 if (!Subtarget->hasArchitectedSGPRs())
11130 return DAG.
getNode(AMDGPUISD::BFE_U32, SL, VT, TTMP8,
11137 unsigned Width)
const {
11139 using namespace AMDGPU::Hwreg;
11141 AMDGPU::S_GETREG_B32_const, SL, MVT::i32,
11181 EVT DstVT =
Op.getValueType();
11183 assert((!IsF16 || Subtarget->hasFP8F16ConversionInsts()) &&
11184 "fp8/bf8 -> f16 conversion requires FP8F16ConversionInsts");
11188 Opc = IsBF8 ? AMDGPUISD::CVT_PK_F16_BF8 : AMDGPUISD::CVT_PK_F16_FP8;
11190 Opc = IsBF8 ? AMDGPUISD::CVT_PK_F32_BF8 : AMDGPUISD::CVT_PK_F32_FP8;
11203SITargetLowering::LowerCONVERT_FROM_ARBITRARY_FP(
SDValue Op,
11212 const bool HasE5M3ConversionInsts =
11213 Subtarget->hasFP8ConversionInsts() && Subtarget->hasFP8E5M3Insts();
11214 const bool IsSupported = IsFP8 || IsBF8 || (IsE5M3 && HasE5M3ConversionInsts);
11218 EVT DstVT =
Op.getValueType();
11222 !Subtarget->hasFP8F16ConversionInsts())
11232 "only the v2f32 vector result is custom lowered");
11238 auto ConvertByte = [&](
unsigned ByteSel) {
11239 return DAG.
getNode(AMDGPUISD::CVT_F32_FP8_E5M3, SL, MVT::f32, Src,
11244 return ConvertByte(0);
11245 return DAG.
getBuildVector(DstVT, SL, {ConvertByte(0), ConvertByte(1)});
11250 if (Src.getValueType() != MVT::i32) {
11260 if (EltVT == MVT::f16 || EltVT == MVT::f32)
11261 return lowerFromFP8(
Op, IsBF8, DAG);
11269 EVT ResVT =
Op.getValueType();
11270 bool IsF16 = Src.getValueType().getScalarType() == MVT::f16;
11271 assert((!IsF16 || Subtarget->hasF16FP8ConversionInsts()) &&
11272 "f16 -> fp8/bf8 conversion requires F16FP8ConversionInsts");
11274 "only the v2i8 vector result is custom lowered");
11278 IsBF8 ? AMDGPUISD::CVT_PK_BF8_F16 : AMDGPUISD::CVT_PK_FP8_F16;
11283 unsigned Opc = IsBF8 ? AMDGPUISD::CVT_PK_BF8_F32
11284 : IsE5M3 ? AMDGPUISD::CVT_PK_FP8_F32_E5M3
11285 : AMDGPUISD::CVT_PK_FP8_F32;
11293 DAG.
getNode(
Opc, SL, MVT::i32, Src, Src, PoisonI32, WordSel);
11305SITargetLowering::LowerCONVERT_TO_ARBITRARY_FP(
SDValue Op,
11314 const bool HasE5M3ConversionInsts =
11315 Subtarget->hasFP8ConversionInsts() && Subtarget->hasFP8E5M3Insts();
11316 const bool IsSupported = IsFP8 || IsBF8 || (IsE5M3 && HasE5M3ConversionInsts);
11326 if (!IsE5M3 &&
Op.getConstantOperandVal(3) != 0)
11329 EVT SrcEltVT =
Op.getOperand(0).getValueType().getScalarType();
11332 if (SrcEltVT == MVT::f32)
11333 return lowerToFP8(
Op, IsBF8, IsE5M3, DAG);
11334 if (!IsE5M3 && SrcEltVT == MVT::f16 &&
11335 Subtarget->hasF16FP8ConversionInsts()) {
11338 if (!
Op.getValueType().isVector())
11340 return lowerToFP8(
Op, IsBF8,
false, DAG);
11348 auto *MFI = MF.
getInfo<SIMachineFunctionInfo>();
11350 EVT VT =
Op.getValueType();
11352 unsigned IntrinsicID =
Op.getConstantOperandVal(0);
11356 switch (IntrinsicID) {
11357 case Intrinsic::amdgcn_wave_reduce_min:
11358 case Intrinsic::amdgcn_wave_reduce_umin:
11359 case Intrinsic::amdgcn_wave_reduce_fmin:
11360 case Intrinsic::amdgcn_wave_reduce_max:
11361 case Intrinsic::amdgcn_wave_reduce_umax:
11362 case Intrinsic::amdgcn_wave_reduce_fmax:
11363 case Intrinsic::amdgcn_wave_reduce_add:
11364 case Intrinsic::amdgcn_wave_reduce_fadd:
11365 case Intrinsic::amdgcn_wave_reduce_sub:
11366 case Intrinsic::amdgcn_wave_reduce_fsub:
11367 case Intrinsic::amdgcn_wave_reduce_and:
11368 case Intrinsic::amdgcn_wave_reduce_or:
11369 case Intrinsic::amdgcn_wave_reduce_xor: {
11370 EVT SrcVT =
Op.getOperand(1).getValueType();
11373 bool NeedsSignExt = IntrinsicID == Intrinsic::amdgcn_wave_reduce_min ||
11374 IntrinsicID == Intrinsic::amdgcn_wave_reduce_max ||
11375 IntrinsicID == Intrinsic::amdgcn_wave_reduce_add ||
11376 IntrinsicID == Intrinsic::amdgcn_wave_reduce_sub;
11380 auto SrcType = IsFPOp ? MVT::f16 : MVT::i16;
11381 auto ExtType = IsFPOp ? MVT::f32 : MVT::i32;
11385 Op.getOperand(0), ExtendedSrc, Strategy);
11394 case Intrinsic::amdgcn_implicit_buffer_ptr: {
11395 if (!MFI->getUserSGPRInfo().hasImplicitBufferPtr()) {
11396 const char *
Error =
11397 Subtarget->hasArchitectedFlatScratch()
11398 ?
"intrinsic not supported on subtarget"
11399 : !Subtarget->isMesa3DOS()
11400 ?
"intrinsic not supported for OS"
11401 :
"intrinsic not supported for calling convention";
11407 return getPreloadedValue(DAG, *MFI, VT,
11410 case Intrinsic::amdgcn_dispatch_ptr:
11411 case Intrinsic::amdgcn_queue_ptr: {
11412 if (!Subtarget->isAmdHsaOrMesa(MF.
getFunction())) {
11414 MF.
getFunction(),
"unsupported hsa intrinsic without hsa target",
11415 DL.getDebugLoc()));
11419 auto RegID = IntrinsicID == Intrinsic::amdgcn_dispatch_ptr
11422 return getPreloadedValue(DAG, *MFI, VT, RegID);
11424 case Intrinsic::amdgcn_implicitarg_ptr: {
11426 return getImplicitArgPtr(DAG,
DL);
11427 return getPreloadedValue(DAG, *MFI, VT,
11430 case Intrinsic::amdgcn_kernarg_segment_ptr: {
11436 return getPreloadedValue(DAG, *MFI, VT,
11439 case Intrinsic::amdgcn_dispatch_id: {
11442 case Intrinsic::amdgcn_rcp:
11443 return DAG.
getNode(AMDGPUISD::RCP,
DL, VT,
Op.getOperand(1));
11444 case Intrinsic::amdgcn_rsq:
11445 return DAG.
getNode(AMDGPUISD::RSQ,
DL, VT,
Op.getOperand(1));
11446 case Intrinsic::amdgcn_rsq_legacy:
11450 case Intrinsic::amdgcn_rcp_legacy:
11453 return DAG.
getNode(AMDGPUISD::RCP_LEGACY,
DL, VT,
Op.getOperand(1));
11454 case Intrinsic::amdgcn_fma_legacy:
11455 case Intrinsic::amdgcn_sudot4:
11456 case Intrinsic::amdgcn_sudot8:
11457 case Intrinsic::amdgcn_tanh:
11459 case Intrinsic::amdgcn_rsq_clamp: {
11461 return DAG.
getNode(AMDGPUISD::RSQ_CLAMP,
DL, VT,
Op.getOperand(1));
11473 case Intrinsic::r600_read_ngroups_x:
11474 if (Subtarget->isAmdHsaOS())
11477 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
11480 case Intrinsic::r600_read_ngroups_y:
11481 if (Subtarget->isAmdHsaOS())
11484 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
11487 case Intrinsic::r600_read_ngroups_z:
11488 if (Subtarget->isAmdHsaOS())
11491 return lowerKernargMemParameter(DAG, VT, VT,
DL, DAG.
getEntryNode(),
11494 case Intrinsic::r600_read_local_size_x:
11495 if (Subtarget->isAmdHsaOS())
11498 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
11500 case Intrinsic::r600_read_local_size_y:
11501 if (Subtarget->isAmdHsaOS())
11504 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
11506 case Intrinsic::r600_read_local_size_z:
11507 if (Subtarget->isAmdHsaOS())
11510 return lowerImplicitZextParam(DAG,
Op, MVT::i16,
11512 case Intrinsic::amdgcn_workgroup_id_x:
11513 return lowerWorkGroupId(DAG, *MFI, VT,
11517 case Intrinsic::amdgcn_workgroup_id_y:
11518 return lowerWorkGroupId(DAG, *MFI, VT,
11522 case Intrinsic::amdgcn_workgroup_id_z:
11523 return lowerWorkGroupId(DAG, *MFI, VT,
11527 case Intrinsic::amdgcn_cluster_id_x:
11528 return Subtarget->hasClusters()
11529 ? getPreloadedValue(DAG, *MFI, VT,
11531 : DAG.getPOISON(VT);
11532 case Intrinsic::amdgcn_cluster_id_y:
11533 return Subtarget->hasClusters()
11534 ? getPreloadedValue(DAG, *MFI, VT,
11537 case Intrinsic::amdgcn_cluster_id_z:
11538 return Subtarget->hasClusters()
11539 ? getPreloadedValue(DAG, *MFI, VT,
11542 case Intrinsic::amdgcn_cluster_workgroup_id_x:
11543 return lowerClusterWorkGroupValue(
11545 case Intrinsic::amdgcn_cluster_workgroup_id_y:
11546 return lowerClusterWorkGroupValue(
11548 case Intrinsic::amdgcn_cluster_workgroup_id_z:
11549 return lowerClusterWorkGroupValue(
11551 case Intrinsic::amdgcn_cluster_workgroup_flat_id:
11552 return Subtarget->hasClusters()
11555 case Intrinsic::amdgcn_cluster_workgroup_max_id_x:
11556 return lowerClusterWorkGroupValue(
11558 case Intrinsic::amdgcn_cluster_workgroup_max_id_y:
11559 return lowerClusterWorkGroupValue(
11561 case Intrinsic::amdgcn_cluster_workgroup_max_id_z:
11562 return lowerClusterWorkGroupValue(
11564 case Intrinsic::amdgcn_cluster_workgroup_max_flat_id:
11565 return lowerClusterWorkGroupValue(
11567 case Intrinsic::amdgcn_wave_id:
11568 return lowerWaveID(DAG,
Op);
11569 case Intrinsic::amdgcn_lds_kernel_id: {
11571 return getLDSKernelId(DAG,
DL);
11572 return getPreloadedValue(DAG, *MFI, VT,
11575 case Intrinsic::amdgcn_workitem_id_x:
11576 return lowerWorkitemID(DAG,
Op, 0, MFI->getArgInfo().WorkItemIDX);
11577 case Intrinsic::amdgcn_workitem_id_y:
11578 return lowerWorkitemID(DAG,
Op, 1, MFI->getArgInfo().WorkItemIDY);
11579 case Intrinsic::amdgcn_workitem_id_z:
11580 return lowerWorkitemID(DAG,
Op, 2, MFI->getArgInfo().WorkItemIDZ);
11581 case Intrinsic::amdgcn_wavefrontsize:
11583 SDLoc(
Op), MVT::i32);
11584 case Intrinsic::amdgcn_s_buffer_load: {
11585 unsigned CPol =
Op.getConstantOperandVal(3);
11593 Op.getOperand(2),
Op.getOperand(3), DAG);
11595 case Intrinsic::amdgcn_fdiv_fast:
11596 return lowerFDIV_FAST(
Op, DAG);
11597 case Intrinsic::amdgcn_sin:
11598 return DAG.
getNode(AMDGPUISD::SIN_HW,
DL, VT,
Op.getOperand(1));
11600 case Intrinsic::amdgcn_cos:
11601 return DAG.
getNode(AMDGPUISD::COS_HW,
DL, VT,
Op.getOperand(1));
11603 case Intrinsic::amdgcn_mul_u24:
11604 return DAG.
getNode(AMDGPUISD::MUL_U24,
DL, VT,
Op.getOperand(1),
11606 case Intrinsic::amdgcn_mul_i24:
11607 return DAG.
getNode(AMDGPUISD::MUL_I24,
DL, VT,
Op.getOperand(1),
11610 case Intrinsic::amdgcn_log_clamp: {
11616 case Intrinsic::amdgcn_fract:
11617 return DAG.
getNode(AMDGPUISD::FRACT,
DL, VT,
Op.getOperand(1));
11619 case Intrinsic::amdgcn_class: {
11621 EVT SrcVT = Src.getValueType();
11622 bool IsLegal = SrcVT == MVT::f32 || SrcVT == MVT::f64 ||
11623 (SrcVT == MVT::f16 && Subtarget->has16BitInsts());
11627 "llvm.amdgcn.class only supports f16, f32, and f64",
11628 DL.getDebugLoc()));
11631 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, VT, Src,
Op.getOperand(2));
11633 case Intrinsic::amdgcn_div_fmas:
11634 return DAG.
getNode(AMDGPUISD::DIV_FMAS,
DL, VT,
Op.getOperand(1),
11635 Op.getOperand(2),
Op.getOperand(3),
Op.getOperand(4));
11637 case Intrinsic::amdgcn_div_fixup:
11638 return DAG.
getNode(AMDGPUISD::DIV_FIXUP,
DL, VT,
Op.getOperand(1),
11639 Op.getOperand(2),
Op.getOperand(3));
11641 case Intrinsic::amdgcn_div_scale: {
11647 SDValue Denominator =
Op.getOperand(2);
11656 return DAG.
getNode(AMDGPUISD::DIV_SCALE,
DL,
Op->getVTList(), Src0,
11657 Denominator, Numerator);
11659 case Intrinsic::amdgcn_ballot:
11661 case Intrinsic::amdgcn_fmed3:
11662 return DAG.
getNode(AMDGPUISD::FMED3,
DL, VT,
Op.getOperand(1),
11663 Op.getOperand(2),
Op.getOperand(3),
Op->getFlags());
11664 case Intrinsic::amdgcn_fdot2:
11665 return DAG.
getNode(AMDGPUISD::FDOT2,
DL, VT,
Op.getOperand(1),
11666 Op.getOperand(2),
Op.getOperand(3),
Op.getOperand(4));
11667 case Intrinsic::amdgcn_fmul_legacy:
11668 return DAG.
getNode(AMDGPUISD::FMUL_LEGACY,
DL, VT,
Op.getOperand(1),
11670 case Intrinsic::amdgcn_sbfe:
11671 case Intrinsic::amdgcn_ubfe:
11673 case Intrinsic::amdgcn_cvt_pkrtz:
11674 case Intrinsic::amdgcn_cvt_pknorm_i16:
11675 case Intrinsic::amdgcn_cvt_pknorm_u16:
11676 case Intrinsic::amdgcn_cvt_pk_i16:
11677 case Intrinsic::amdgcn_cvt_pk_u16: {
11679 EVT VT =
Op.getValueType();
11682 if (IntrinsicID == Intrinsic::amdgcn_cvt_pkrtz)
11683 Opcode = AMDGPUISD::CVT_PKRTZ_F16_F32;
11684 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pknorm_i16)
11685 Opcode = AMDGPUISD::CVT_PKNORM_I16_F32;
11686 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pknorm_u16)
11687 Opcode = AMDGPUISD::CVT_PKNORM_U16_F32;
11688 else if (IntrinsicID == Intrinsic::amdgcn_cvt_pk_i16)
11689 Opcode = AMDGPUISD::CVT_PK_I16_I32;
11691 Opcode = AMDGPUISD::CVT_PK_U16_U32;
11694 return DAG.
getNode(Opcode,
DL, VT,
Op.getOperand(1),
Op.getOperand(2));
11697 DAG.
getNode(Opcode,
DL, MVT::i32,
Op.getOperand(1),
Op.getOperand(2));
11700 case Intrinsic::amdgcn_fmad_ftz:
11701 return DAG.
getNode(AMDGPUISD::FMAD_FTZ,
DL, VT,
Op.getOperand(1),
11702 Op.getOperand(2),
Op.getOperand(3));
11704 case Intrinsic::amdgcn_if_break:
11706 Op->getOperand(1),
Op->getOperand(2)),
11709 case Intrinsic::amdgcn_groupstaticsize: {
11715 const GlobalValue *GV =
11721 case Intrinsic::amdgcn_is_shared:
11722 case Intrinsic::amdgcn_is_private: {
11729 unsigned AS = (IntrinsicID == Intrinsic::amdgcn_is_shared)
11733 Subtarget->hasGloballyAddressableScratch()) {
11736 AMDGPU::S_MOV_B32,
DL, MVT::i32,
11737 DAG.
getRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE_HI, MVT::i32)),
11746 SDValue Aperture = getSegmentAperture(AS, SL, DAG);
11749 case Intrinsic::amdgcn_perm:
11750 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
Op.getOperand(1),
11751 Op.getOperand(2),
Op.getOperand(3));
11752 case Intrinsic::amdgcn_reloc_constant: {
11762 case Intrinsic::amdgcn_swmmac_f16_16x16x32_f16:
11763 case Intrinsic::amdgcn_swmmac_bf16_16x16x32_bf16:
11764 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf16:
11765 case Intrinsic::amdgcn_swmmac_f32_16x16x32_f16:
11766 case Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_fp8:
11767 case Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_bf8:
11768 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_fp8:
11769 case Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_bf8: {
11770 if (
Op.getOperand(4).getValueType() == MVT::i32)
11776 Op.getOperand(0),
Op.getOperand(1),
Op.getOperand(2),
11777 Op.getOperand(3), IndexKeyi32);
11779 case Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_fp8:
11780 case Intrinsic::amdgcn_swmmac_f32_16x16x128_fp8_bf8:
11781 case Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_fp8:
11782 case Intrinsic::amdgcn_swmmac_f32_16x16x128_bf8_bf8:
11783 case Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_fp8:
11784 case Intrinsic::amdgcn_swmmac_f16_16x16x128_fp8_bf8:
11785 case Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_fp8:
11786 case Intrinsic::amdgcn_swmmac_f16_16x16x128_bf8_bf8: {
11787 if (
Op.getOperand(4).getValueType() == MVT::i64)
11792 Op.getOperand(4).getValueType() == MVT::v2i32
11796 {Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
11797 Op.getOperand(3), IndexKeyi64, Op.getOperand(5),
11798 Op.getOperand(6)});
11800 case Intrinsic::amdgcn_swmmac_f16_16x16x64_f16:
11801 case Intrinsic::amdgcn_swmmac_bf16_16x16x64_bf16:
11802 case Intrinsic::amdgcn_swmmac_f32_16x16x64_bf16:
11803 case Intrinsic::amdgcn_swmmac_bf16f32_16x16x64_bf16:
11804 case Intrinsic::amdgcn_swmmac_f32_16x16x64_f16:
11805 case Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8: {
11806 EVT IndexKeyTy = IntrinsicID == Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8
11809 if (
Op.getOperand(6).getValueType() == IndexKeyTy)
11814 Op.getOperand(6).getValueType().isVector()
11818 Op.getOperand(0),
Op.getOperand(1),
Op.getOperand(2),
11819 Op.getOperand(3),
Op.getOperand(4),
Op.getOperand(5),
11820 IndexKey,
Op.getOperand(7),
Op.getOperand(8)};
11821 if (IntrinsicID == Intrinsic::amdgcn_swmmac_i32_16x16x128_iu8)
11822 Args.push_back(
Op.getOperand(9));
11825 case Intrinsic::amdgcn_swmmac_i32_16x16x32_iu4:
11826 case Intrinsic::amdgcn_swmmac_i32_16x16x32_iu8:
11827 case Intrinsic::amdgcn_swmmac_i32_16x16x64_iu4: {
11828 if (
Op.getOperand(6).getValueType() == MVT::i32)
11834 {Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
11835 Op.getOperand(3), Op.getOperand(4), Op.getOperand(5),
11836 IndexKeyi32, Op.getOperand(7)});
11838 case Intrinsic::amdgcn_wmma_scale_f32_16x16x128_f8f6f4:
11839 case Intrinsic::amdgcn_wmma_scale16_f32_16x16x128_f8f6f4: {
11840 unsigned AFmt = (unsigned)
Op.getConstantOperandVal(1);
11841 unsigned BFmt = (unsigned)
Op.getConstantOperandVal(3);
11842 unsigned AScaleFmt = (unsigned)
Op.getConstantOperandVal(8);
11843 unsigned BScaleFmt = (unsigned)
Op.getConstantOperandVal(11);
11847 "invalid matrix and scale format combination in wmma call");
11853 case Intrinsic::amdgcn_readlane:
11854 case Intrinsic::amdgcn_readfirstlane:
11855 case Intrinsic::amdgcn_writelane:
11856 case Intrinsic::amdgcn_permlane16:
11857 case Intrinsic::amdgcn_permlanex16:
11858 case Intrinsic::amdgcn_permlane64:
11859 case Intrinsic::amdgcn_set_inactive:
11860 case Intrinsic::amdgcn_set_inactive_chain_arg:
11861 case Intrinsic::amdgcn_mov_dpp8:
11862 case Intrinsic::amdgcn_update_dpp:
11863 case Intrinsic::amdgcn_permlane_bcast:
11864 case Intrinsic::amdgcn_permlane_up:
11865 case Intrinsic::amdgcn_permlane_down:
11866 case Intrinsic::amdgcn_permlane_xor:
11868 case Intrinsic::amdgcn_dead: {
11870 for (
const EVT ValTy :
Op.getNode()->values())
11874 case Intrinsic::amdgcn_wave_shuffle:
11877 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
11879 return lowerImage(
Op, ImageDimIntr, DAG,
false);
11890 return DAG.
getRegister(AMDGPU::SGPR_NULL, MVT::i32);
11902 auto GetArg = [&](
unsigned Arg) {
11906 SDValue Rsrc = bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG);
11907 auto [VOffset,
Offset] =
11908 splitBufferOffsets(GetArg(*
Info.getVOffsetArg()), DAG);
11914 Ops.push_back(VData);
11915 if (std::optional<unsigned> CmpArg =
Info.getCmpArg())
11916 Ops.push_back(GetArg(*CmpArg));
11917 Ops.push_back(Rsrc);
11918 std::optional<unsigned> VIndexArg =
Info.getVIndexArg();
11919 Ops.push_back(VIndexArg ? GetArg(*VIndexArg)
11921 Ops.push_back(VOffset);
11922 Ops.push_back(SOffset);
11924 if (std::optional<unsigned> FormatArg =
Info.getFormatArg())
11925 Ops.push_back(GetArg(*FormatArg));
11926 Ops.push_back(GetArg(*
Info.getAuxArg()));
11933 unsigned NewOpcode)
const {
11935 const AMDGPU::BufferIntrinsicInfo &
Info =
11942 "unsupported buffer atomic data type");
11950 M->getMemOperand());
11956SDValue SITargetLowering::lowerBufferIntrinsicWithChain(
11961 auto GetArg = [&](
unsigned Arg) {
11965 switch (
Info.Kind) {
11966 case AMDGPU::BufferKindSLoad: {
11974 return lowerSBuffer(
11975 Op.getValueType(),
M->getMemoryVT(),
DL,
Op.getOperand(0),
11976 bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG),
11977 GetArg(*
Info.getSOffsetArg()), CachePolicy, DAG,
M->getMemOperand());
11979 case AMDGPU::BufferKindLoad:
11980 case AMDGPU::BufferKindAtomicLoad: {
11982 if (!
Info.isTyped())
11983 return lowerIntrinsicLoad(M,
Info.isFormatFromRsrc(), DAG,
Ops);
11985 EVT LoadVT =
Op.getValueType();
11987 return adjustLoadValueType(AMDGPUISD::TBUFFER_LOAD_FORMAT_D16, M, DAG,
11989 return getMemIntrinsicNode(AMDGPUISD::TBUFFER_LOAD_FORMAT,
DL,
11990 Op->getVTList(),
Ops, LoadVT,
M->getMemOperand(),
11993 case AMDGPU::BufferKindAtomicCmpSwap: {
11995 if (Src.getValueSizeInBits() != 32 && Src.getValueSizeInBits() != 64) {
11998 "unsupported buffer atomic data type");
12002 Op->getVTList(),
Ops,
Op.getValueType(),
12003 M->getMemOperand());
12014 unsigned NumOperands =
N->getNumOperands();
12015 if (
N->getOperand(NumOperands - 1) ==
Zero)
12025static std::optional<uint32_t>
12027 std::optional<uint64_t> BarVal;
12029 BarVal =
C->getZExtValue();
12030 }
else if (BarOp->
isUndef()) {
12049 return *BarVal & 0x3F;
12050 return std::nullopt;
12055 unsigned IntrID =
Op.getConstantOperandVal(1);
12058 if (
const AMDGPU::BufferIntrinsicInfo *BufInfo =
12060 BufInfo && BufInfo->
Kind != AMDGPU::BufferKindAtomicRMW)
12061 return lowerBufferIntrinsicWithChain(
Op, *BufInfo, DAG);
12064 case Intrinsic::amdgcn_cluster_load_b32:
12065 case Intrinsic::amdgcn_cluster_load_b64:
12066 case Intrinsic::amdgcn_cluster_load_b128: {
12067 if (Subtarget->hasGFX1250_STRICT())
12071 case Intrinsic::amdgcn_ds_ordered_add:
12072 case Intrinsic::amdgcn_ds_ordered_swap: {
12077 unsigned IndexOperand =
M->getConstantOperandVal(7);
12078 unsigned WaveRelease =
M->getConstantOperandVal(8);
12079 unsigned WaveDone =
M->getConstantOperandVal(9);
12081 unsigned OrderedCountIndex = IndexOperand & 0x3f;
12082 IndexOperand &= ~0x3f;
12083 unsigned CountDw = 0;
12086 CountDw = (IndexOperand >> 24) & 0xf;
12087 IndexOperand &= ~(0xf << 24);
12089 if (CountDw < 1 || CountDw > 4) {
12092 Fn,
"ds_ordered_count: dword count must be between 1 and 4",
12093 DL.getDebugLoc()));
12098 if (IndexOperand) {
12101 Fn,
"ds_ordered_count: bad index operand",
DL.getDebugLoc()));
12104 if (WaveDone && !WaveRelease) {
12108 Fn,
"ds_ordered_count: wave_done requires wave_release",
12109 DL.getDebugLoc()));
12112 unsigned Instruction = IntrID == Intrinsic::amdgcn_ds_ordered_add ? 0 : 1;
12113 unsigned ShaderType =
12115 unsigned Offset0 = OrderedCountIndex << 2;
12116 unsigned Offset1 = WaveRelease | (WaveDone << 1) | (Instruction << 4);
12119 Offset1 |= (CountDw - 1) << 6;
12122 Offset1 |= ShaderType << 2;
12124 unsigned Offset = Offset0 | (Offset1 << 8);
12131 M->getVTList(),
Ops,
M->getMemoryVT(),
12132 M->getMemOperand());
12134 case Intrinsic::amdgcn_raw_buffer_atomic_fadd:
12135 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fadd:
12136 case Intrinsic::amdgcn_struct_buffer_atomic_fadd:
12137 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fadd:
12138 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_FADD);
12139 case Intrinsic::amdgcn_raw_buffer_atomic_fmin:
12140 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fmin:
12141 case Intrinsic::amdgcn_struct_buffer_atomic_fmin:
12142 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fmin:
12143 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_FMIN);
12144 case Intrinsic::amdgcn_raw_buffer_atomic_fmax:
12145 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_fmax:
12146 case Intrinsic::amdgcn_struct_buffer_atomic_fmax:
12147 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_fmax:
12148 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_FMAX);
12149 case Intrinsic::amdgcn_raw_buffer_atomic_swap:
12150 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_swap:
12151 case Intrinsic::amdgcn_struct_buffer_atomic_swap:
12152 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_swap:
12153 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SWAP);
12154 case Intrinsic::amdgcn_raw_buffer_atomic_add:
12155 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_add:
12156 case Intrinsic::amdgcn_struct_buffer_atomic_add:
12157 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_add:
12158 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_ADD);
12159 case Intrinsic::amdgcn_raw_buffer_atomic_sub:
12160 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_sub:
12161 case Intrinsic::amdgcn_struct_buffer_atomic_sub:
12162 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_sub:
12163 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SUB);
12164 case Intrinsic::amdgcn_raw_buffer_atomic_smin:
12165 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smin:
12166 case Intrinsic::amdgcn_struct_buffer_atomic_smin:
12167 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smin:
12168 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SMIN);
12169 case Intrinsic::amdgcn_raw_buffer_atomic_umin:
12170 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umin:
12171 case Intrinsic::amdgcn_struct_buffer_atomic_umin:
12172 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umin:
12173 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_UMIN);
12174 case Intrinsic::amdgcn_raw_buffer_atomic_smax:
12175 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_smax:
12176 case Intrinsic::amdgcn_struct_buffer_atomic_smax:
12177 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_smax:
12178 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_SMAX);
12179 case Intrinsic::amdgcn_raw_buffer_atomic_umax:
12180 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_umax:
12181 case Intrinsic::amdgcn_struct_buffer_atomic_umax:
12182 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_umax:
12183 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_UMAX);
12184 case Intrinsic::amdgcn_raw_buffer_atomic_and:
12185 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_and:
12186 case Intrinsic::amdgcn_struct_buffer_atomic_and:
12187 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_and:
12188 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_AND);
12189 case Intrinsic::amdgcn_raw_buffer_atomic_or:
12190 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_or:
12191 case Intrinsic::amdgcn_struct_buffer_atomic_or:
12192 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_or:
12193 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_OR);
12194 case Intrinsic::amdgcn_raw_buffer_atomic_xor:
12195 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_xor:
12196 case Intrinsic::amdgcn_struct_buffer_atomic_xor:
12197 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_xor:
12198 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_XOR);
12199 case Intrinsic::amdgcn_raw_buffer_atomic_inc:
12200 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_inc:
12201 case Intrinsic::amdgcn_struct_buffer_atomic_inc:
12202 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_inc:
12203 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_INC);
12204 case Intrinsic::amdgcn_raw_buffer_atomic_dec:
12205 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_dec:
12206 case Intrinsic::amdgcn_struct_buffer_atomic_dec:
12207 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_dec:
12208 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_DEC);
12209 case Intrinsic::amdgcn_raw_buffer_atomic_sub_clamp_u32:
12210 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_sub_clamp_u32:
12211 case Intrinsic::amdgcn_struct_buffer_atomic_sub_clamp_u32:
12212 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_sub_clamp_u32:
12213 return lowerBufferAtomicIntrin(
Op, DAG, AMDGPUISD::BUFFER_ATOMIC_CSUB);
12214 case Intrinsic::amdgcn_raw_buffer_atomic_cond_sub_u32:
12215 case Intrinsic::amdgcn_raw_ptr_buffer_atomic_cond_sub_u32:
12216 case Intrinsic::amdgcn_struct_buffer_atomic_cond_sub_u32:
12217 case Intrinsic::amdgcn_struct_ptr_buffer_atomic_cond_sub_u32:
12218 return lowerBufferAtomicIntrin(
Op, DAG,
12219 AMDGPUISD::BUFFER_ATOMIC_COND_SUB_U32);
12220 case Intrinsic::amdgcn_image_bvh_dual_intersect_ray:
12221 case Intrinsic::amdgcn_image_bvh8_intersect_ray: {
12223 SDValue NodePtr =
M->getOperand(2);
12224 SDValue RayExtent =
M->getOperand(3);
12225 SDValue InstanceMask =
M->getOperand(4);
12226 SDValue RayOrigin =
M->getOperand(5);
12227 SDValue RayDir =
M->getOperand(6);
12229 SDValue TDescr =
M->getOperand(8);
12234 bool IsBVH8 = IntrID == Intrinsic::amdgcn_image_bvh8_intersect_ray;
12235 const unsigned NumVDataDwords = 10;
12236 const unsigned NumVAddrDwords = IsBVH8 ? 11 : 12;
12238 IsBVH8 ? AMDGPU::IMAGE_BVH8_INTERSECT_RAY
12239 : AMDGPU::IMAGE_BVH_DUAL_INTERSECT_RAY,
12240 AMDGPU::MIMGEncGfx12, NumVDataDwords, NumVAddrDwords);
12244 Ops.push_back(NodePtr);
12247 {DAG.getBitcast(MVT::i32, RayExtent),
12248 DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, InstanceMask)}));
12249 Ops.push_back(RayOrigin);
12250 Ops.push_back(RayDir);
12251 Ops.push_back(Offsets);
12252 Ops.push_back(TDescr);
12253 Ops.push_back(
M->getChain());
12256 MachineMemOperand *MemRef =
M->getMemOperand();
12260 case Intrinsic::amdgcn_image_bvh_intersect_ray: {
12262 SDValue NodePtr =
M->getOperand(2);
12263 SDValue RayExtent =
M->getOperand(3);
12264 SDValue RayOrigin =
M->getOperand(4);
12265 SDValue RayDir =
M->getOperand(5);
12266 SDValue RayInvDir =
M->getOperand(6);
12267 SDValue TDescr =
M->getOperand(7);
12279 const unsigned NumVDataDwords = 4;
12280 const unsigned NumVAddrDwords = IsA16 ? (Is64 ? 9 : 8) : (Is64 ? 12 : 11);
12281 const unsigned NumVAddrs = IsGFX11Plus ? (IsA16 ? 4 : 5) : NumVAddrDwords;
12282 const bool UseNSA = (Subtarget->hasNSAEncoding() &&
12285 const unsigned BaseOpcodes[2][2] = {
12286 {AMDGPU::IMAGE_BVH_INTERSECT_RAY, AMDGPU::IMAGE_BVH_INTERSECT_RAY_a16},
12287 {AMDGPU::IMAGE_BVH64_INTERSECT_RAY,
12288 AMDGPU::IMAGE_BVH64_INTERSECT_RAY_a16}};
12292 IsGFX12Plus ? AMDGPU::MIMGEncGfx12
12293 : IsGFX11 ? AMDGPU::MIMGEncGfx11NSA
12294 : AMDGPU::MIMGEncGfx10NSA,
12295 NumVDataDwords, NumVAddrDwords);
12299 IsGFX11 ? AMDGPU::MIMGEncGfx11Default
12300 : AMDGPU::MIMGEncGfx10Default,
12301 NumVDataDwords, NumVAddrDwords);
12307 auto packLanes = [&DAG, &
Ops, &
DL](
SDValue Op,
bool IsAligned) {
12310 if (Lanes[0].getValueSizeInBits() == 32) {
12311 for (
unsigned I = 0;
I < 3; ++
I)
12318 Ops.push_back(Lanes[2]);
12330 if (UseNSA && IsGFX11Plus) {
12331 Ops.push_back(NodePtr);
12333 Ops.push_back(RayOrigin);
12338 for (
unsigned I = 0;
I < 3; ++
I) {
12341 {DirLanes[I], InvDirLanes[I]})));
12345 Ops.push_back(RayDir);
12346 Ops.push_back(RayInvDir);
12353 Ops.push_back(NodePtr);
12356 packLanes(RayOrigin,
true);
12357 packLanes(RayDir,
true);
12358 packLanes(RayInvDir,
false);
12363 if (NumVAddrDwords > 12) {
12371 Ops.push_back(MergedOps);
12374 Ops.push_back(TDescr);
12376 Ops.push_back(
M->getChain());
12379 MachineMemOperand *MemRef =
M->getMemOperand();
12383 case Intrinsic::amdgcn_global_atomic_fmin_num:
12384 case Intrinsic::amdgcn_global_atomic_fmax_num:
12385 case Intrinsic::amdgcn_flat_atomic_fmin_num:
12386 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
12393 unsigned Opcode = 0;
12395 case Intrinsic::amdgcn_global_atomic_fmin_num:
12396 case Intrinsic::amdgcn_flat_atomic_fmin_num: {
12400 case Intrinsic::amdgcn_global_atomic_fmax_num:
12401 case Intrinsic::amdgcn_flat_atomic_fmax_num: {
12408 return DAG.
getAtomic(Opcode, SDLoc(
Op),
M->getMemoryVT(),
M->getVTList(),
12409 Ops,
M->getMemOperand());
12411 case Intrinsic::amdgcn_s_alloc_vgpr: {
12419 ReadFirstLaneID, NumVGPRs);
12422 Op.getOperand(0),
Op.getOperand(1), NumVGPRs);
12424 case Intrinsic::amdgcn_s_get_barrier_state:
12425 case Intrinsic::amdgcn_s_get_named_barrier_state: {
12430 std::optional<uint32_t> BarID;
12431 if (IntrID == Intrinsic::amdgcn_s_get_named_barrier_state)
12434 BarID =
C->getZExtValue();
12437 Opc = AMDGPU::S_GET_BARRIER_STATE_IMM;
12440 Ops.push_back(Chain);
12442 Opc = AMDGPU::S_GET_BARRIER_STATE_M0;
12443 if (IntrID == Intrinsic::amdgcn_s_get_named_barrier_state) {
12454 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
12455 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
12456 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B: {
12460 EVT VT =
Op->getValueType(0);
12464 case Intrinsic::amdgcn_av_load_b8:
12465 case Intrinsic::amdgcn_av_load_b16:
12466 case Intrinsic::amdgcn_av_load_b32:
12467 case Intrinsic::amdgcn_av_load_b64:
12468 case Intrinsic::amdgcn_av_load_b128: {
12472 EVT VT =
Op->getValueType(0);
12479 case Intrinsic::amdgcn_flat_load_monitor_b32:
12480 case Intrinsic::amdgcn_flat_load_monitor_b64:
12481 case Intrinsic::amdgcn_flat_load_monitor_b128: {
12486 Op->getVTList(), {Chain, Ptr},
12489 case Intrinsic::amdgcn_global_load_monitor_b32:
12490 case Intrinsic::amdgcn_global_load_monitor_b64:
12491 case Intrinsic::amdgcn_global_load_monitor_b128: {
12496 Op->getVTList(), {Chain, Ptr},
12501 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
12503 return lowerImage(
Op, ImageDimIntr, DAG,
true);
12511SDValue SITargetLowering::getMemIntrinsicNode(
unsigned Opcode,
const SDLoc &
DL,
12518 EVT VT = VTList.
VTs[0];
12521 bool IsTFE = VTList.
NumVTs == 3;
12524 unsigned NumOpDWords = NumValueDWords + 1;
12526 SDVTList OpDWordsVTList = DAG.
getVTList(OpDWordsVT, VTList.
VTs[2]);
12527 MachineMemOperand *OpDWordsMMO =
12529 SDValue Op = getMemIntrinsicNode(Opcode,
DL, OpDWordsVTList,
Ops,
12530 OpDWordsVT, OpDWordsMMO, DAG);
12535 if (!Subtarget->hasDwordx3LoadStores() &&
12536 (VT == MVT::v3i32 || VT == MVT::v3f32)) {
12540 SDVTList WidenedVTList = DAG.
getVTList(WidenedVT, VTList.
VTs[1]);
12542 WidenedMemVT, WidenedMMO);
12552 bool ImageStore)
const {
12562 if (Subtarget->hasUnpackedD16VMem()) {
12576 if (ImageStore && Subtarget->hasImageStoreD16Bug()) {
12587 for (
unsigned I = 0;
I < Elts.
size() / 2;
I += 1) {
12593 if ((NumElements % 2) == 1) {
12595 unsigned I = Elts.
size() / 2;
12611 if (NumElements == 3) {
12631 return BufInfo->IsAsync;
12633 case Intrinsic::amdgcn_load_async_to_lds:
12634 case Intrinsic::amdgcn_global_load_async_lds:
12642SDValue SITargetLowering::lowerBufferIntrinsicVoid(
12648 auto GetArg = [&](
unsigned Arg) {
12652 switch (
Info.Kind) {
12653 case AMDGPU::BufferKindStore: {
12658 if (
Info.isTyped()) {
12661 VData = handleD16VData(VData, DAG);
12663 getBufferIntrinsicOps(
Op, Info, DAG, VData);
12664 unsigned Opc = IsD16 ? AMDGPUISD::TBUFFER_STORE_FORMAT_D16
12665 : AMDGPUISD::TBUFFER_STORE_FORMAT;
12667 M->getMemoryVT(),
M->getMemOperand());
12670 bool IsFormat =
Info.isFormatFromRsrc();
12676 "unsupported sub-dword format buffer store",
DL.getDebugLoc()));
12681 VData = handleD16VData(VData, DAG);
12693 IsFormat ? AMDGPUISD::BUFFER_STORE_FORMAT : AMDGPUISD::BUFFER_STORE;
12694 Opc = IsD16 ? AMDGPUISD::BUFFER_STORE_FORMAT_D16 :
Opc;
12698 return handleByteShortBufferStores(DAG, VDataVT,
DL,
Ops.data(), M);
12701 M->getMemoryVT(),
M->getMemOperand());
12703 case AMDGPU::BufferKindLoadToLDS: {
12705 std::optional<unsigned> VIndexArg =
Info.getVIndexArg();
12706 bool HasVIndex = VIndexArg.has_value();
12709 unsigned Size = GetArg(*
Info.getSizeArg())->getAsZExtVal();
12715 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_UBYTE_LDS_BOTHEN
12716 : AMDGPU::BUFFER_LOAD_UBYTE_LDS_IDXEN
12717 : HasVOffset ? AMDGPU::BUFFER_LOAD_UBYTE_LDS_OFFEN
12718 : AMDGPU::BUFFER_LOAD_UBYTE_LDS_OFFSET;
12721 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_USHORT_LDS_BOTHEN
12722 : AMDGPU::BUFFER_LOAD_USHORT_LDS_IDXEN
12723 : HasVOffset ? AMDGPU::BUFFER_LOAD_USHORT_LDS_OFFEN
12724 : AMDGPU::BUFFER_LOAD_USHORT_LDS_OFFSET;
12727 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORD_LDS_BOTHEN
12728 : AMDGPU::BUFFER_LOAD_DWORD_LDS_IDXEN
12729 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORD_LDS_OFFEN
12730 : AMDGPU::BUFFER_LOAD_DWORD_LDS_OFFSET;
12733 if (!Subtarget->hasLDSLoadB96_B128())
12735 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX3_LDS_BOTHEN
12736 : AMDGPU::BUFFER_LOAD_DWORDX3_LDS_IDXEN
12737 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX3_LDS_OFFEN
12738 : AMDGPU::BUFFER_LOAD_DWORDX3_LDS_OFFSET;
12741 if (!Subtarget->hasLDSLoadB96_B128())
12743 Opc = HasVIndex ? HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX4_LDS_BOTHEN
12744 : AMDGPU::BUFFER_LOAD_DWORDX4_LDS_IDXEN
12745 : HasVOffset ? AMDGPU::BUFFER_LOAD_DWORDX4_LDS_OFFEN
12746 : AMDGPU::BUFFER_LOAD_DWORDX4_LDS_OFFSET;
12754 if (HasVIndex && HasVOffset)
12757 else if (HasVIndex)
12758 Ops.push_back(GetArg(*VIndexArg));
12759 else if (HasVOffset)
12760 Ops.push_back(VOffset);
12762 SDValue Rsrc = bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG);
12763 Ops.push_back(Rsrc);
12764 Ops.push_back(GetArg(*
Info.getSOffsetArg()));
12765 Ops.push_back(GetArg(*
Info.getImmOffsetArg()));
12767 unsigned Aux = GetArg(*
Info.getAuxArg())->getAsZExtVal();
12785 case AMDGPU::BufferKindPrefetch: {
12788 bufferRsrcPtrToVector(GetArg(
Info.RsrcArg), DAG),
12789 GetArg(*
Info.getSOffsetArg()),
12790 GetArg(*
Info.getSizeArg()),
12794 Op->getVTList(),
Ops,
M->getMemoryVT(),
12795 M->getMemOperand());
12806 unsigned IntrinsicID =
Op.getConstantOperandVal(1);
12808 if (
const AMDGPU::BufferIntrinsicInfo *BufInfo =
12810 return lowerBufferIntrinsicVoid(
Op, *BufInfo, DAG);
12812 switch (IntrinsicID) {
12813 case Intrinsic::amdgcn_cluster_load_async_to_lds_b8:
12814 case Intrinsic::amdgcn_cluster_load_async_to_lds_b32:
12815 case Intrinsic::amdgcn_cluster_load_async_to_lds_b64:
12816 case Intrinsic::amdgcn_cluster_load_async_to_lds_b128: {
12817 if (Subtarget->hasGFX1250_STRICT())
12821 case Intrinsic::amdgcn_exp_compr: {
12842 unsigned Opc =
Done->isZero() ? AMDGPU::EXP : AMDGPU::EXP_DONE;
12849 case Intrinsic::amdgcn_load_to_lds:
12850 case Intrinsic::amdgcn_load_async_to_lds:
12851 case Intrinsic::amdgcn_global_load_lds:
12852 case Intrinsic::amdgcn_global_load_async_lds: {
12853 if (!Subtarget->hasVMemToLDSLoad())
12857 unsigned Size =
Op->getConstantOperandVal(4);
12862 Opc = AMDGPU::GLOBAL_LOAD_LDS_UBYTE;
12865 Opc = AMDGPU::GLOBAL_LOAD_LDS_USHORT;
12868 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORD;
12871 if (!Subtarget->hasLDSLoadB96_B128())
12873 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORDX3;
12876 if (!Subtarget->hasLDSLoadB96_B128())
12878 Opc = AMDGPU::GLOBAL_LOAD_LDS_DWORDX4;
12894 if (
LHS->isDivergent())
12898 RHS.getOperand(0).getValueType() == MVT::i32) {
12901 VOffset =
RHS.getOperand(0);
12905 Ops.push_back(Addr);
12913 Ops.push_back(VOffset);
12916 Ops.push_back(
Op.getOperand(5));
12918 unsigned Aux =
Op.getConstantOperandVal(6);
12933 case Intrinsic::amdgcn_end_cf:
12935 Op->getOperand(2), Chain),
12937 case Intrinsic::amdgcn_s_barrier_signal_var: {
12944 if (CntC && CntC->isZero()) {
12949 std::array<SDValue, 2>
Ops = {
12952 Op->getVTList(),
Ops);
12958 case Intrinsic::amdgcn_s_barrier_init: {
12965 unsigned Opc = IntrinsicID == Intrinsic::amdgcn_s_barrier_init
12966 ? AMDGPU::S_BARRIER_INIT_M0
12967 : AMDGPU::S_BARRIER_SIGNAL_M0;
12977 constexpr unsigned ShAmt = 16;
12988 case Intrinsic::amdgcn_s_wakeup_barrier: {
12989 if (!Subtarget->hasSWakeupBarrier())
12993 case Intrinsic::amdgcn_s_barrier_join: {
13001 switch (IntrinsicID) {
13004 case Intrinsic::amdgcn_s_barrier_join:
13005 Opc = AMDGPU::S_BARRIER_JOIN_IMM;
13007 case Intrinsic::amdgcn_s_wakeup_barrier:
13008 Opc = AMDGPU::S_WAKEUP_BARRIER_IMM;
13013 Ops.push_back(Chain);
13015 switch (IntrinsicID) {
13018 case Intrinsic::amdgcn_s_barrier_join:
13019 Opc = AMDGPU::S_BARRIER_JOIN_M0;
13021 case Intrinsic::amdgcn_s_wakeup_barrier:
13022 Opc = AMDGPU::S_WAKEUP_BARRIER_M0;
13034 case Intrinsic::amdgcn_s_prefetch_data:
13035 case Intrinsic::amdgcn_s_prefetch_inst: {
13038 return Op.getOperand(0);
13041 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
13042 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
13043 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
13051 case Intrinsic::amdgcn_av_store_b8:
13052 case Intrinsic::amdgcn_av_store_b16:
13053 case Intrinsic::amdgcn_av_store_b32:
13054 case Intrinsic::amdgcn_av_store_b64:
13055 case Intrinsic::amdgcn_av_store_b128: {
13063 if (
const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
13065 return lowerImage(
Op, ImageDimIntr, DAG,
true);
13081 return PtrVT == MVT::i64;
13095std::pair<SDValue, SDValue>
13108 bool CheckNUW =
Subtarget->hasGFX1250Insts();
13116 unsigned ImmOffset =
C1->getZExtValue();
13125 unsigned Overflow = ImmOffset & ~MaxImm;
13126 ImmOffset -= Overflow;
13127 if ((int32_t)Overflow < 0) {
13128 Overflow += ImmOffset;
13133 auto OverflowVal = DAG.
getConstant(Overflow,
DL, MVT::i32);
13152void SITargetLowering::setBufferOffsets(
SDValue CombinedOffset,
13154 Align Alignment)
const {
13156 SDLoc
DL(CombinedOffset);
13158 uint32_t
Imm =
C->getZExtValue();
13159 uint32_t SOffset, ImmOffset;
13160 if (
TII->splitMUBUFOffset(
Imm, SOffset, ImmOffset, Alignment)) {
13171 bool CheckNUW = Subtarget->hasGFX1250Insts();
13174 uint32_t SOffset, ImmOffset;
13177 TII->splitMUBUFOffset(
Offset, SOffset, ImmOffset, Alignment)) {
13185 SDValue SOffsetZero = Subtarget->hasRestrictedSOffset()
13194SDValue SITargetLowering::bufferRsrcPtrToVector(
SDValue MaybePointer,
13197 return MaybePointer;
13211 SDValue NumRecords =
Op->getOperand(3);
13217 if (Subtarget->getBufferResourceNumRecordsWidth() == 45) {
13220 DAG.
getConstant((1ULL << 45) - 1, Loc, MVT::i64));
13239 SDValue ExtShiftedStrideVec =
13251 DAG.
getNode(
ISD::OR, Loc, MVT::i64, NumRecordsRHS, ExtShiftedStride);
13253 DAG.
getNode(
ISD::OR, Loc, MVT::i64, CombinedFields, ExtShiftedFlags);
13258 auto [LowHalf, HighHalf] =
13259 DAG.
SplitScalar(Pointer, Loc, MVT::i32, MVT::i32);
13269 NumRecords, Flags);
13281 bool IsTFE)
const {
13286 ? AMDGPUISD::BUFFER_LOAD_UBYTE_TFE
13287 : AMDGPUISD::BUFFER_LOAD_USHORT_TFE;
13290 SDVTList VTs = DAG.
getVTList(MVT::v2i32, MVT::Other);
13302 ? AMDGPUISD::BUFFER_LOAD_UBYTE
13303 : AMDGPUISD::BUFFER_LOAD_USHORT;
13305 SDVTList ResList = DAG.
getVTList(MVT::i32, MVT::Other);
13319 if (VDataType == MVT::f16 || VDataType == MVT::bf16)
13323 Ops[1] = BufferStoreExt;
13324 unsigned Opc = (VDataType == MVT::i8) ? AMDGPUISD::BUFFER_STORE_BYTE
13325 : AMDGPUISD::BUFFER_STORE_SHORT;
13328 M->getMemOperand());
13353 DAGCombinerInfo &DCI)
const {
13354 SelectionDAG &DAG = DCI.DAG;
13355 if (Ld->getAlign() <
Align(4) || Ld->isDivergent())
13359 unsigned AS = Ld->getAddressSpace();
13368 EVT MemVT = Ld->getMemoryVT();
13369 if ((MemVT.
isSimple() && !DCI.isAfterLegalizeDAG()) ||
13376 "unexpected vector extload");
13379 SDValue Ptr = Ld->getBasePtr();
13382 Ld->getOffset(), Ld->getPointerInfo(), MVT::i32, Ld->getAlign(),
13383 Ld->getMemOperand()->getFlags(), Ld->getAAInfo());
13388 "unexpected fp extload");
13403 EVT VT = Ld->getValueType(0);
13406 DCI.AddToWorklist(Cvt.
getNode());
13411 DCI.AddToWorklist(Cvt.
getNode());
13422 if (Info.isEntryFunction())
13423 return Info.getUserSGPRInfo().hasFlatScratchInit();
13433 EVT MemVT = MemOp->getMemoryVT();
13441 "unsupported access of VGPR 'as memory' address space (13); only "
13442 "dword-aligned whole-dword loads and stores are implemented",
13443 DL.getDebugLoc()));
13453 if (MemOp->getAlign() <
Align(4))
13461 if (!Subtarget->getRegisterInfo()->getVGPRClassForBitWidth(
BitWidth) ||
13467 if (MemVT == ViewVT)
13471 Store->getBasePtr(),
Store->getMemOperand());
13476 Load->getMemOperand()->clearRanges();
13478 Load->getBasePtr(),
Load->getMemOperand());
13481 Load->getValueType(0));
13485 SDValue Chain = MemOp->getChain();
13492 unsigned NumDwords =
BitWidth / 32;
13493 RegVT = NumDwords == 1
13495 : EVT::getVectorVT(*DAG.
getContext(), MVT::i32, NumDwords);
13501 AMDGPUISD::REG_STORE,
DL, DAG.
getVTList(MVT::Other),
13502 {Chain, Value, Index}, MemVT,
Store->getMemOperand());
13506 AMDGPUISD::REG_LOAD,
DL, DAG.
getVTList(RegVT, MVT::Other), {Chain, Index},
13507 MemVT,
Load->getMemOperand());
13511 Load->getValueType(0));
13512 if (
Value == NewLoad)
13521 "Unexpected custom extending load!");
13522 EVT MemVT =
Load->getMemoryVT();
13523 MachineMemOperand *MMO =
Load->getMemOperand();
13530 isTypeLegal(MemVT) && Subtarget->hasScalarSubwordLoads() &&
13537 BasePtr, MVT::i16, MMO);
13560 EVT RealMemVT = (MemVT == MVT::i1) ? MVT::i8 : MVT::i16;
13586 Op.getValueType().getVectorElementType() == MVT::i32 &&
13587 "Custom lowering for non-i32 vectors hasn't been implemented.");
13590 unsigned AS =
Load->getAddressSpace();
13591 if (Subtarget->hasLDSMisalignedBugInWGPMode() &&
13598 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
13602 !Subtarget->hasMultiDwordFlatScratchAddressing())
13614 Alignment >=
Align(4) && NumElements < 32) {
13616 (Subtarget->hasScalarDwordx3Loads() && NumElements == 3))
13628 if (NumElements > 4)
13631 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
13641 switch (Subtarget->getMaxPrivateElementSize()) {
13647 if (NumElements > 2)
13652 if (NumElements > 4)
13655 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
13664 auto Flags =
Load->getMemOperand()->getFlags();
13666 Load->getAlign(), Flags, &
Fast) &&
13674 MemVT, *
Load->getMemOperand())) {
13683 EVT VT =
Op.getValueType();
13720 EVT VT =
Op.getValueType();
13721 const SDNodeFlags
Flags =
Op->getFlags();
13723 bool AllowInaccurateRcp =
Flags.hasApproximateFuncs();
13729 if (!AllowInaccurateRcp && VT != MVT::f16 && VT != MVT::bf16)
13732 if (CLHS->isOne()) {
13745 return DAG.
getNode(AMDGPUISD::RCP, SL, VT,
RHS);
13749 if (CLHS->isMinusOne()) {
13758 if (!AllowInaccurateRcp &&
13759 ((VT != MVT::f16 && VT != MVT::bf16) || !
Flags.hasAllowReciprocal()))
13773 EVT VT =
Op.getValueType();
13774 const SDNodeFlags
Flags =
Op->getFlags();
13776 bool AllowInaccurateDiv =
Flags.hasApproximateFuncs();
13777 if (!AllowInaccurateDiv)
13801 if (IsNegRcp || (CLHS && CLHS->
isOne()))
13813 return DAG.
getNode(Opcode, SL, VT,
A,
B, Flags);
13823 Opcode = AMDGPUISD::FMUL_W_CHAIN;
13827 return DAG.
getNode(Opcode, SL, VTList,
13836 return DAG.
getNode(Opcode, SL, VT, {
A,
B,
C}, Flags);
13846 Opcode = AMDGPUISD::FMA_W_CHAIN;
13850 return DAG.
getNode(Opcode, SL, VTList,
13856 if (
SDValue FastLowered = lowerFastUnsafeFDIV(
Op, DAG))
13857 return FastLowered;
13860 EVT VT =
Op.getValueType();
13867 if (VT == MVT::bf16) {
13890 unsigned FMADOpCode =
13894 DAG.
getNode(AMDGPUISD::RCP, SL, MVT::f32, RHSExt,
Op->getFlags());
13897 SDValue Err = DAG.
getNode(FMADOpCode, SL, MVT::f32, NegRHSExt, Quot, LHSExt,
13899 Quot = DAG.
getNode(FMADOpCode, SL, MVT::f32, Err, Rcp, Quot,
Op->getFlags());
13900 Err = DAG.
getNode(FMADOpCode, SL, MVT::f32, NegRHSExt, Quot, LHSExt,
13910 return DAG.
getNode(AMDGPUISD::DIV_FIXUP, SL, MVT::f16, RDst,
RHS,
LHS,
13916 SDNodeFlags
Flags =
Op->getFlags();
13926 const APFloat K0Val(0x1p+96f);
13929 const APFloat K1Val(0x1p-32f);
13956 assert(ST->hasDenormModeInst() &&
"Requires S_DENORM_MODE");
13957 uint32_t DPDenormModeDefault = Info->getMode().fpDenormModeDPValue();
13958 uint32_t Mode = SPDenormMode | (DPDenormModeDefault << 2);
13963 if (
SDValue FastLowered = lowerFastUnsafeFDIV(
Op, DAG))
13964 return FastLowered;
13970 SDNodeFlags
Flags =
Op->getFlags();
13971 Flags.setNoFPExcept(
true);
13979 SDVTList ScaleVT = DAG.
getVTList(MVT::f32, MVT::i1);
13988 DAG.
getNode(AMDGPUISD::RCP, SL, MVT::f32, DenominatorScaled, Flags);
13992 using namespace AMDGPU::Hwreg;
13993 const unsigned Denorm32Reg = HwregEncoding::encode(ID_MODE, 4, 2);
13997 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
13998 const DenormalMode DenormMode =
Info->getMode().FP32Denormals;
14001 const bool HasDynamicDenormals =
14007 if (!PreservesDenormals) {
14012 SDVTList BindParamVTs = DAG.
getVTList(MVT::Other, MVT::Glue);
14015 if (HasDynamicDenormals) {
14019 SavedDenormMode =
SDValue(GetReg, 0);
14025 SDNode *EnableDenorm;
14026 if (Subtarget->hasDenormModeInst()) {
14027 const SDValue EnableDenormValue =
14030 EnableDenorm = DAG.
getNode(AMDGPUISD::DENORM_MODE, SL, BindParamVTs, Glue,
14034 const SDValue EnableDenormValue =
14036 EnableDenorm = DAG.
getMachineNode(AMDGPU::S_SETREG_B32, SL, BindParamVTs,
14037 {EnableDenormValue,
BitField, Glue});
14047 ApproxRcp, One, NegDivScale0, Flags);
14050 ApproxRcp, Fma0, Flags);
14056 NumeratorScaled,
Mul, Flags);
14062 NumeratorScaled, Fma3, Flags);
14064 if (!PreservesDenormals) {
14065 SDNode *DisableDenorm;
14066 if (!HasDynamicDenormals && Subtarget->hasDenormModeInst()) {
14070 SDVTList BindParamVTs = DAG.
getVTList(MVT::Other, MVT::Glue);
14072 DAG.
getNode(AMDGPUISD::DENORM_MODE, SL, BindParamVTs,
14076 assert(HasDynamicDenormals == (
bool)SavedDenormMode);
14077 const SDValue DisableDenormValue =
14078 HasDynamicDenormals
14083 AMDGPU::S_SETREG_B32, SL, MVT::Other,
14094 {Fma4, Fma1, Fma3, Scale},
Flags);
14096 return DAG.
getNode(AMDGPUISD::DIV_FIXUP, SL, MVT::f32, Fmas,
RHS,
LHS, Flags);
14100 if (
SDValue FastLowered = lowerFastUnsafeFDIV64(
Op, DAG))
14101 return FastLowered;
14109 SDVTList ScaleVT = DAG.
getVTList(MVT::f64, MVT::i1);
14115 SDValue Rcp = DAG.
getNode(AMDGPUISD::RCP, SL, MVT::f64, DivScale0);
14133 if (!Subtarget->hasUsableDivScaleConditionOutput()) {
14163 DAG.
getNode(AMDGPUISD::DIV_FMAS, SL, MVT::f64, Fma4, Fma3,
Mul, Scale);
14165 return DAG.
getNode(AMDGPUISD::DIV_FIXUP, SL, MVT::f64, Fmas,
Y,
X);
14169 EVT VT =
Op.getValueType();
14171 if (VT == MVT::f32)
14172 return LowerFDIV32(
Op, DAG);
14174 if (VT == MVT::f64)
14175 return LowerFDIV64(
Op, DAG);
14177 if (VT == MVT::f16 || VT == MVT::bf16)
14178 return LowerFDIV16(
Op, DAG);
14187 EVT ResultExpVT =
Op->getValueType(1);
14188 EVT InstrExpVT = VT == MVT::f16 ? MVT::i16 : MVT::i32;
14198 if (Subtarget->hasFractBug()) {
14216 assert(!
Store->isTruncatingStore() &&
"Unexpected custom truncating store!");
14217 EVT VT =
Store->getMemoryVT();
14219 if (VT == MVT::i1) {
14223 Store->getBasePtr(), MVT::i1,
Store->getMemOperand());
14227 Store->getValue().getValueType().getScalarType() == MVT::i32);
14229 unsigned AS =
Store->getAddressSpace();
14230 if (Subtarget->hasLDSMisalignedBugInWGPMode() &&
14238 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
14242 !Subtarget->hasMultiDwordFlatScratchAddressing())
14249 if (NumElements > 4)
14252 if (NumElements == 3 && !Subtarget->hasDwordx3LoadStores())
14256 VT, *
Store->getMemOperand()))
14262 switch (Subtarget->getMaxPrivateElementSize()) {
14266 if (NumElements > 2)
14270 if (NumElements > 4 ||
14271 (NumElements == 3 && !Subtarget->hasFlatScratchEnabled()))
14279 auto Flags =
Store->getMemOperand()->getFlags();
14295 assert(!Subtarget->has16BitInsts());
14296 SDNodeFlags
Flags =
Op->getFlags();
14310 SDNodeFlags
Flags =
Op->getFlags();
14311 MVT VT =
Op.getValueType().getSimpleVT();
14419 SDNodeFlags
Flags =
Op->getFlags();
14428 if (!
Flags.hasApproximateFuncs()) {
14460 if (!
Flags.hasApproximateFuncs()) {
14469 ScaleDownFactor, ZeroInt);
14476 if (
Flags.hasNoInfs()) {
14492 EVT VT =
Op.getValueType();
14503 if (!
V.getValueType().isVector())
14511 if (Subtarget->hasTrigReducedRange()) {
14513 TrigVal = UnrollIfVec(DAG.
getNode(AMDGPUISD::FRACT,
DL, VT, MulVal, Flags));
14518 switch (
Op.getOpcode()) {
14520 TrigVal = DAG.
getNode(AMDGPUISD::COS_HW, SDLoc(
Op), VT, TrigVal, Flags);
14523 TrigVal = DAG.
getNode(AMDGPUISD::SIN_HW, SDLoc(
Op), VT, TrigVal, Flags);
14529 return UnrollIfVec(TrigVal);
14549 EVT VT =
Op.getValueType();
14557 Op->getVTList(),
Ops, VT,
14566SITargetLowering::performUCharToFloatCombine(
SDNode *
N,
14567 DAGCombinerInfo &DCI)
const {
14568 EVT VT =
N->getValueType(0);
14570 if (ScalarVT != MVT::f32 && ScalarVT != MVT::f16)
14573 SelectionDAG &DAG = DCI.DAG;
14577 EVT SrcVT = Src.getValueType();
14583 if (DCI.isAfterLegalizeDAG() && SrcVT == MVT::i32) {
14586 DCI.AddToWorklist(Cvt.
getNode());
14589 if (ScalarVT != MVT::f32) {
14601 DAGCombinerInfo &DCI)
const {
14612 SelectionDAG &DAG = DCI.DAG;
14631 for (
unsigned I = 0;
I != NumElts; ++
I) {
14655 if (NewElts.
size() == 1)
14677 for (
unsigned I = 0;
I != NumElts; ++
I) {
14712SDValue SITargetLowering::performSHLPtrCombine(
SDNode *
N,
unsigned AddrSpace,
14714 DAGCombinerInfo &DCI)
const {
14731 SelectionDAG &DAG = DCI.DAG;
14744 AM.BaseOffs =
Offset.getSExtValue();
14749 EVT VT =
N->getValueType(0);
14755 Flags.setNoUnsignedWrap(
14756 N->getFlags().hasNoUnsignedWrap() &&
14768 switch (
N->getOpcode()) {
14779 DAGCombinerInfo &DCI)
const {
14780 SelectionDAG &DAG = DCI.DAG;
14787 SDValue NewPtr = performSHLPtrCombine(Ptr.
getNode(),
N->getAddressSpace(),
14788 N->getMemoryVT(), DCI);
14792 NewOps[PtrIdx] = NewPtr;
14801 return (
Opc ==
ISD::AND && (Val == 0 || Val == 0xffffffff)) ||
14802 (
Opc ==
ISD::OR && (Val == 0xffffffff || Val == 0)) ||
14811SDValue SITargetLowering::splitBinaryBitConstantOp(
14815 uint32_t ValLo =
Lo_32(Val);
14816 uint32_t ValHi =
Hi_32(Val);
14823 if (Subtarget->has64BitLiterals() && CRHS->
hasOneUse() &&
14837 if (V.getValueType() != MVT::i1)
14839 switch (V.getOpcode()) {
14844 case AMDGPUISD::FP_CLASS:
14856 return V.getResNo() == 1;
14858 unsigned IntrinsicID = V.getConstantOperandVal(0);
14859 switch (IntrinsicID) {
14860 case Intrinsic::amdgcn_is_shared:
14861 case Intrinsic::amdgcn_is_private:
14884 if (!(
C & 0x000000ff))
14885 ZeroByteMask |= 0x000000ff;
14886 if (!(
C & 0x0000ff00))
14887 ZeroByteMask |= 0x0000ff00;
14888 if (!(
C & 0x00ff0000))
14889 ZeroByteMask |= 0x00ff0000;
14890 if (!(
C & 0xff000000))
14891 ZeroByteMask |= 0xff000000;
14892 uint32_t NonZeroByteMask = ~ZeroByteMask;
14893 if ((NonZeroByteMask &
C) != NonZeroByteMask)
14906 assert(
V.getValueSizeInBits() == 32);
14908 if (
V.getNumOperands() != 2)
14917 switch (
V.getOpcode()) {
14922 return (0x03020100 & ConstMask) | (0x0c0c0c0c & ~ConstMask);
14927 return (0x03020100 & ~ConstMask) | ConstMask;
14934 return uint32_t((0x030201000c0c0c0cull <<
C) >> 32);
14940 return uint32_t(0x0c0c0c0c03020100ull >>
C);
14947 DAGCombinerInfo &DCI)
const {
14948 if (DCI.isBeforeLegalize())
14951 SelectionDAG &DAG = DCI.DAG;
14952 EVT VT =
N->getValueType(0);
14957 if (VT == MVT::i64 && CRHS) {
14959 splitBinaryBitConstantOp(DCI, SDLoc(
N),
ISD::AND,
LHS, CRHS))
14963 if (CRHS && VT == MVT::i32) {
14973 unsigned Shift = CShift->getZExtValue();
14975 unsigned Offset = NB + Shift;
14976 if ((
Offset & (Bits - 1)) == 0) {
14979 DAG.
getNode(AMDGPUISD::BFE_U32, SL, MVT::i32,
LHS->getOperand(0),
15000 Sel = (
LHS.getConstantOperandVal(2) & Sel) | (~Sel & 0x0c0c0c0c);
15002 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15012 if (Shift && Shift->getZExtValue() < 16 &&
15031 if (
Y.getOpcode() !=
ISD::FABS ||
Y.getOperand(0) !=
X ||
15036 if (
X !=
LHS.getOperand(1))
15040 const ConstantFPSDNode *
C1 =
15042 if (!
C1 || !
C1->isInfinity() ||
C1->isNegative())
15057 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, MVT::i1,
X,
15063 if (
RHS.getOpcode() ==
ISD::SETCC &&
LHS.getOpcode() == AMDGPUISD::FP_CLASS)
15066 if (
LHS.getOpcode() ==
ISD::SETCC &&
RHS.getOpcode() == AMDGPUISD::FP_CLASS &&
15074 (
RHS.getOperand(0) ==
LHS.getOperand(0) &&
15075 LHS.getOperand(0) ==
LHS.getOperand(1))) {
15077 unsigned NewMask = LCC ==
ISD::SETO ?
Mask->getZExtValue() & ~OrdMask
15078 :
Mask->getZExtValue() & OrdMask;
15081 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, MVT::i1,
RHS.getOperand(0),
15099 TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
15102 if (LHSMask != ~0u && RHSMask != ~0u) {
15105 if (LHSMask > RHSMask) {
15112 uint32_t LHSUsedLanes = ~(LHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15113 uint32_t RHSUsedLanes = ~(RHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15116 if (!(LHSUsedLanes & RHSUsedLanes) &&
15119 !(LHSUsedLanes == 0x0c0c0000 && RHSUsedLanes == 0x00000c0c)) {
15125 uint32_t
Mask = LHSMask & RHSMask;
15126 for (
unsigned I = 0;
I < 32;
I += 8) {
15127 uint32_t ByteSel = 0xff <<
I;
15128 if ((LHSMask & ByteSel) == 0x0c || (RHSMask & ByteSel) == 0x0c)
15129 Mask &= (0x0c <<
I) & 0xffffffff;
15134 uint32_t Sel =
Mask | (LHSUsedLanes & 0x04040404);
15137 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15187static const std::optional<ByteProvider<SDValue>>
15189 unsigned Depth = 0) {
15192 return std::nullopt;
15194 if (
Op.getValueSizeInBits() < 8)
15195 return std::nullopt;
15197 if (
Op.getValueType().isVector())
15200 switch (
Op->getOpcode()) {
15213 NarrowVT = VTSign->getVT();
15216 return std::nullopt;
15219 if (SrcIndex >= NarrowByteWidth)
15220 return std::nullopt;
15228 return std::nullopt;
15230 uint64_t BitShift = ShiftOp->getZExtValue();
15232 if (BitShift % 8 != 0)
15233 return std::nullopt;
15235 uint64_t NewSrcIndex = SrcIndex + BitShift / 8;
15236 if (NewSrcIndex >=
Op.getScalarValueSizeInBits() / 8)
15237 return std::nullopt;
15256static const std::optional<ByteProvider<SDValue>>
15258 unsigned StartingIndex = 0) {
15262 return std::nullopt;
15264 unsigned BitWidth =
Op.getScalarValueSizeInBits();
15266 return std::nullopt;
15268 return std::nullopt;
15270 bool IsVec =
Op.getValueType().isVector();
15271 switch (
Op.getOpcode()) {
15274 return std::nullopt;
15279 return std::nullopt;
15283 return std::nullopt;
15286 if (!
LHS->isConstantZero() && !
RHS->isConstantZero())
15287 return std::nullopt;
15288 if (!
LHS ||
LHS->isConstantZero())
15290 if (!
RHS ||
RHS->isConstantZero())
15292 return std::nullopt;
15297 return std::nullopt;
15301 return std::nullopt;
15303 uint32_t BitMask = BitMaskOp->getZExtValue();
15305 uint32_t IndexMask = 0xFF << (Index * 8);
15307 if ((IndexMask & BitMask) != IndexMask) {
15310 if (IndexMask & BitMask)
15311 return std::nullopt;
15320 return std::nullopt;
15324 if (!ShiftOp ||
Op.getValueType().isVector())
15325 return std::nullopt;
15327 uint64_t BitsProvided =
Op.getValueSizeInBits();
15328 if (BitsProvided % 8 != 0)
15329 return std::nullopt;
15331 uint64_t BitShift = ShiftOp->getAPIntValue().urem(BitsProvided);
15333 return std::nullopt;
15335 uint64_t ConcatSizeInBytes = BitsProvided / 4;
15336 uint64_t ByteShift = BitShift / 8;
15338 uint64_t NewIndex = (Index + ByteShift) % ConcatSizeInBytes;
15339 uint64_t BytesProvided = BitsProvided / 8;
15340 SDValue NextOp =
Op.getOperand(NewIndex >= BytesProvided ? 0 : 1);
15341 NewIndex %= BytesProvided;
15348 return std::nullopt;
15352 return std::nullopt;
15354 uint64_t BitShift = ShiftOp->getZExtValue();
15356 return std::nullopt;
15358 auto BitsProvided =
Op.getScalarValueSizeInBits();
15359 if (BitsProvided % 8 != 0)
15360 return std::nullopt;
15362 uint64_t BytesProvided = BitsProvided / 8;
15363 uint64_t ByteShift = BitShift / 8;
15364 if (Index + ByteShift < BytesProvided)
15366 Index + ByteShift);
15369 return std::nullopt;
15375 return std::nullopt;
15379 return std::nullopt;
15381 uint64_t BitShift = ShiftOp->getZExtValue();
15382 if (BitShift % 8 != 0)
15383 return std::nullopt;
15384 uint64_t ByteShift = BitShift / 8;
15390 return Index < ByteShift
15393 Depth + 1, StartingIndex);
15402 return std::nullopt;
15410 NarrowBitWidth = VTSign->getVT().getSizeInBits();
15412 if (NarrowBitWidth % 8 != 0)
15413 return std::nullopt;
15414 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
15416 if (Index >= NarrowByteWidth)
15418 ? std::optional<ByteProvider<SDValue>>(
15426 return std::nullopt;
15430 if (NarrowByteWidth >= Index) {
15435 return std::nullopt;
15442 return std::nullopt;
15448 unsigned NarrowBitWidth = L->getMemoryVT().getSizeInBits();
15449 if (NarrowBitWidth % 8 != 0)
15450 return std::nullopt;
15451 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
15456 if (Index >= NarrowByteWidth) {
15458 ? std::optional<ByteProvider<SDValue>>(
15463 if (NarrowByteWidth > Index) {
15467 return std::nullopt;
15472 return std::nullopt;
15475 Depth + 1, StartingIndex);
15481 return std::nullopt;
15482 auto VecIdx = IdxOp->getZExtValue();
15483 auto ScalarSize =
Op.getScalarValueSizeInBits();
15484 if (ScalarSize < 32)
15485 Index = ScalarSize == 8 ? VecIdx : VecIdx * 2 + Index;
15487 StartingIndex, Index);
15490 case AMDGPUISD::PERM: {
15492 return std::nullopt;
15496 return std::nullopt;
15499 (PermMask->getZExtValue() & (0xFF << (Index * 8))) >> (Index * 8);
15500 if (IdxMask > 0x07 && IdxMask != 0x0c)
15501 return std::nullopt;
15503 auto NextOp =
Op.getOperand(IdxMask > 0x03 ? 0 : 1);
15504 auto NextIndex = IdxMask > 0x03 ? IdxMask % 4 : IdxMask;
15506 return IdxMask != 0x0c ?
calculateSrcByte(NextOp, StartingIndex, NextIndex)
15512 return std::nullopt;
15527 return !OpVT.
isVector() && OpVT.getSizeInBits() == 16;
15534 auto MemVT = L->getMemoryVT();
15537 return L->getMemoryVT().getSizeInBits() == 16;
15547 int Low8 = Mask & 0xff;
15548 int Hi8 = (Mask & 0xff00) >> 8;
15550 assert(Low8 < 8 && Hi8 < 8);
15552 bool IsConsecutive = (Hi8 - Low8 == 1);
15557 bool Is16Aligned = !(Low8 % 2);
15559 return IsConsecutive && Is16Aligned;
15567 int Low16 = PermMask & 0xffff;
15568 int Hi16 = (PermMask & 0xffff0000) >> 16;
15578 auto OtherOpIs16Bit = TempOtherOp.getValueSizeInBits() == 16 ||
15580 if (!OtherOpIs16Bit)
15588 unsigned DWordOffset) {
15593 assert(Src.getValueSizeInBits().isKnownMultipleOf(8));
15598 if (Src.getValueType().isVector()) {
15599 auto ScalarTySize = Src.getScalarValueSizeInBits();
15600 auto ScalarTy = Src.getValueType().getScalarType();
15601 if (ScalarTySize == 32) {
15605 if (ScalarTySize > 32) {
15608 DAG.
getConstant(DWordOffset / (ScalarTySize / 32), SL, MVT::i32));
15609 auto ShiftVal = 32 * (DWordOffset % (ScalarTySize / 32));
15616 assert(ScalarTySize < 32);
15625 auto NumElements =
TypeSize / ScalarTySize;
15626 auto Trunc32Elements = (ScalarTySize * NumElements) / 32;
15627 auto NormalizedTrunc = Trunc32Elements * 32 / ScalarTySize;
15628 auto NumElementsIn32 = 32 / ScalarTySize;
15629 auto NumAvailElements = DWordOffset < Trunc32Elements
15631 : NumElements - NormalizedTrunc;
15644 auto ShiftVal = 32 * DWordOffset;
15652 [[maybe_unused]]
EVT VT =
N->getValueType(0);
15657 for (
int i = 0; i < 4; i++) {
15659 std::optional<ByteProvider<SDValue>>
P =
15662 if (!
P ||
P->isConstantZero())
15667 if (PermNodes.
size() != 4)
15670 std::pair<unsigned, unsigned> FirstSrc(0, PermNodes[0].SrcOffset / 4);
15671 std::optional<std::pair<unsigned, unsigned>> SecondSrc;
15673 for (
size_t i = 0; i < PermNodes.
size(); i++) {
15674 auto PermOp = PermNodes[i];
15677 int SrcByteAdjust = 4;
15681 if (!PermOp.hasSameSrc(PermNodes[FirstSrc.first]) ||
15682 ((PermOp.SrcOffset / 4) != FirstSrc.second)) {
15684 if (!PermOp.hasSameSrc(PermNodes[SecondSrc->first]) ||
15685 ((PermOp.SrcOffset / 4) != SecondSrc->second))
15689 SecondSrc = {i, PermNodes[i].SrcOffset / 4};
15690 assert(!(PermNodes[SecondSrc->first].Src->getValueSizeInBits() % 8));
15693 assert((PermOp.SrcOffset % 4) + SrcByteAdjust < 8);
15695 PermMask |= ((PermOp.SrcOffset % 4) + SrcByteAdjust) << (i * 8);
15698 SDValue Op = *PermNodes[FirstSrc.first].Src;
15700 assert(
Op.getValueSizeInBits() == 32);
15704 int Low16 = PermMask & 0xffff;
15705 int Hi16 = (PermMask & 0xffff0000) >> 16;
15707 bool WellFormedLow = (Low16 == 0x0504) || (Low16 == 0x0100);
15708 bool WellFormedHi = (Hi16 == 0x0706) || (Hi16 == 0x0302);
15711 if (WellFormedLow && WellFormedHi)
15715 SDValue OtherOp = SecondSrc ? *PermNodes[SecondSrc->first].Src :
Op;
15724 (
N->getOperand(0) ==
Op ||
N->getOperand(0) == OtherOp) &&
15725 (
N->getOperand(1) ==
Op ||
N->getOperand(1) == OtherOp))
15730 assert(
Op.getValueType().isByteSized() &&
15741 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
Op, OtherOp,
15748 DAGCombinerInfo &DCI)
const {
15749 SelectionDAG &DAG = DCI.DAG;
15753 EVT VT =
N->getValueType(0);
15754 if (VT == MVT::i1) {
15756 if (
LHS.getOpcode() == AMDGPUISD::FP_CLASS &&
15757 RHS.getOpcode() == AMDGPUISD::FP_CLASS) {
15759 if (Src !=
RHS.getOperand(0))
15764 if (!CLHS || !CRHS)
15768 static const uint32_t MaxMask = 0x3ff;
15773 return DAG.
getNode(AMDGPUISD::FP_CLASS,
DL, MVT::i1, Src,
15780 if (VT == MVT::i32 && !DCI.isBeforeLegalize()) {
15781 for (
unsigned I : {1u, 0
u}) {
15790 if (
N->isDivergent() && !
Cond->isDivergent() && !
Cond.hasOneUse())
15804 LHS.getOpcode() == AMDGPUISD::PERM &&
15810 Sel |=
LHS.getConstantOperandVal(2);
15812 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15819 TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
15823 auto usesCombinedOperand = [](SDNode *OrUse) {
15826 !OrUse->getValueType(0).isVector())
15830 for (
auto *VUser : OrUse->users()) {
15831 if (!VUser->getValueType(0).isVector())
15838 if (VUser->getOpcode() == VectorwiseOp)
15844 if (!
any_of(
N->users(), usesCombinedOperand))
15850 if (LHSMask != ~0u && RHSMask != ~0u) {
15853 if (LHSMask > RHSMask) {
15860 uint32_t LHSUsedLanes = ~(LHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15861 uint32_t RHSUsedLanes = ~(RHSMask & 0x0c0c0c0c) & 0x0c0c0c0c;
15864 if (!(LHSUsedLanes & RHSUsedLanes) &&
15867 !(LHSUsedLanes == 0x0c0c0000 && RHSUsedLanes == 0x00000c0c)) {
15869 LHSMask &= ~RHSUsedLanes;
15870 RHSMask &= ~LHSUsedLanes;
15872 LHSMask |= LHSUsedLanes & 0x04040404;
15874 uint32_t Sel = LHSMask | RHSMask;
15877 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32,
LHS.getOperand(0),
15882 if (LHSMask == ~0u || RHSMask == ~0u) {
15923 return IdentitySrc;
15929 if (VT != MVT::i64 || DCI.isBeforeLegalizeOps())
15944 if (SrcVT == MVT::i32) {
15949 DCI.AddToWorklist(LowOr.
getNode());
15950 DCI.AddToWorklist(HiBits.getNode());
15961 N->getOperand(0), CRHS))
15969 DAGCombinerInfo &DCI)
const {
15970 if (
SDValue RV = reassociateScalarOps(
N, DCI.DAG))
15977 SelectionDAG &DAG = DCI.DAG;
15979 EVT VT =
N->getValueType(0);
15980 if (CRHS && VT == MVT::i64) {
15982 splitBinaryBitConstantOp(DCI, SDLoc(
N),
ISD::XOR,
LHS, CRHS))
15989 unsigned Opc =
LHS.getOpcode();
16019 LHS->getOperand(0), FNegLHS, FNegRHS);
16028SITargetLowering::performZeroOrAnyExtendCombine(
SDNode *
N,
16029 DAGCombinerInfo &DCI)
const {
16030 if (!Subtarget->has16BitInsts() ||
16034 EVT VT =
N->getValueType(0);
16035 if (VT != MVT::i32)
16039 if (Src.getValueType() != MVT::i16)
16042 if (!Src->hasOneUse())
16045 if (
SDValue Ext = performExtendTruncShiftCombine(
N, DCI))
16052 std::optional<ByteProvider<SDValue>> BP0 =
16054 if (!BP0 || BP0->SrcOffset >= 4 || !BP0->Src)
16058 std::optional<ByteProvider<SDValue>> BP1 =
16060 if (!BP1 || BP1->SrcOffset >= 4 || !BP1->Src)
16068 SelectionDAG &DAG = DCI.DAG;
16070 uint32_t PermMask = 0x0c0c0c0c;
16073 PermMask = (PermMask & ~0xFF) | (BP0->SrcOffset + 4);
16078 PermMask = (PermMask & ~(0xFF << 8)) | (BP1->SrcOffset << 8);
16081 return DAG.
getNode(AMDGPUISD::PERM,
DL, MVT::i32, V0,
V1,
16089SITargetLowering::performExtendTruncShiftCombine(
SDNode *
N,
16090 DAGCombinerInfo &DCI)
const {
16094 const unsigned Opc =
N->getOpcode();
16097 if (
N->getValueType(0) != MVT::i32 || Src.getValueType() != MVT::i16 ||
16098 Src.getOpcode() != (IsSigned ?
ISD::SRA :
ISD::SRL) || !Src.hasOneUse() ||
16104 if (!IsSigned && !Src->isDivergent())
16107 SDValue X = Src.getOperand(0).getOperand(0);
16109 if (
X.getValueType() != MVT::i32 || !Shift || Shift->getZExtValue() == 0 ||
16110 Shift->getZExtValue() >= 16 || (IsSigned && Shift->getZExtValue() != 8))
16113 SelectionDAG &DAG = DCI.DAG;
16115 const unsigned Width = 16 - Shift->getZExtValue();
16128SITargetLowering::performSignExtendInRegCombine(
SDNode *
N,
16129 DAGCombinerInfo &DCI)
const {
16135 if (((Src.getOpcode() == AMDGPUISD::SBUFFER_LOAD_UBYTE &&
16136 VTSign->getVT() == MVT::i8) ||
16137 (Src.getOpcode() == AMDGPUISD::SBUFFER_LOAD_USHORT &&
16138 VTSign->getVT() == MVT::i16))) {
16139 assert(Subtarget->hasScalarSubwordLoads() &&
16140 "s_buffer_load_{u8, i8} are supported "
16141 "in GFX12 (or newer) architectures.");
16142 unsigned Opc = (Src.getOpcode() == AMDGPUISD::SBUFFER_LOAD_UBYTE)
16143 ? AMDGPUISD::SBUFFER_LOAD_BYTE
16144 : AMDGPUISD::SBUFFER_LOAD_SHORT;
16147 DCI.DAG.getVTList(MVT::i32, Src.getOperand(0).getValueType());
16155 SDValue BufferLoad = DCI.DAG.getMemIntrinsicNode(
16156 Opc,
DL, ResList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
16157 return DCI.DAG.getMergeValues({BufferLoad, BufferLoad.
getValue(1)},
DL);
16159 if (((Src.getOpcode() == AMDGPUISD::BUFFER_LOAD_UBYTE &&
16160 VTSign->getVT() == MVT::i8) ||
16161 (Src.getOpcode() == AMDGPUISD::BUFFER_LOAD_USHORT &&
16162 VTSign->getVT() == MVT::i16)) &&
16171 Src.getOperand(6), Src.getOperand(7)};
16174 DCI.DAG.getVTList(MVT::i32, Src.getOperand(0).getValueType());
16175 unsigned Opc = (Src.getOpcode() == AMDGPUISD::BUFFER_LOAD_UBYTE)
16176 ? AMDGPUISD::BUFFER_LOAD_BYTE
16177 : AMDGPUISD::BUFFER_LOAD_SHORT;
16178 SDValue BufferLoadSignExt = DCI.DAG.getMemIntrinsicNode(
16179 Opc, SDLoc(
N), ResList,
Ops,
M->getMemoryVT(),
M->getMemOperand());
16180 return DCI.DAG.getMergeValues(
16181 {BufferLoadSignExt, BufferLoadSignExt.
getValue(1)}, SDLoc(
N));
16187 DAGCombinerInfo &DCI)
const {
16188 SelectionDAG &DAG = DCI.DAG;
16195 if (
N->getOperand(0).isUndef())
16202 DAGCombinerInfo &DCI)
const {
16203 EVT VT =
N->getValueType(0);
16214 return DCI.DAG.getNode(AMDGPUISD::RSQ, SDLoc(
N), VT, N0.
getOperand(0),
16223 unsigned MaxDepth)
const {
16224 EVT VT =
Op.getValueType();
16226 "expected a floating-point value to query canonicality of");
16232 unsigned MaxDepth)
const {
16234 "QueryVT must be a floating-point scalar type");
16235 EVT VT =
Op.getValueType();
16239 unsigned Opcode =
Op.getOpcode();
16244 const auto &
F = CFP->getValueAPF();
16245 if (
F.isNaN() &&
F.isSignaling())
16247 if (!
F.isDenormal())
16279 case AMDGPUISD::FMUL_LEGACY:
16280 case AMDGPUISD::FMAD_FTZ:
16281 case AMDGPUISD::RCP:
16282 case AMDGPUISD::RSQ:
16283 case AMDGPUISD::RSQ_CLAMP:
16284 case AMDGPUISD::RCP_LEGACY:
16285 case AMDGPUISD::RCP_IFLAG:
16286 case AMDGPUISD::LOG:
16287 case AMDGPUISD::EXP:
16288 case AMDGPUISD::DIV_SCALE:
16289 case AMDGPUISD::DIV_FMAS:
16290 case AMDGPUISD::DIV_FIXUP:
16291 case AMDGPUISD::FRACT:
16292 case AMDGPUISD::CVT_PKRTZ_F16_F32:
16293 case AMDGPUISD::CVT_F32_UBYTE0:
16294 case AMDGPUISD::CVT_F32_UBYTE1:
16295 case AMDGPUISD::CVT_F32_UBYTE2:
16296 case AMDGPUISD::CVT_F32_UBYTE3:
16297 case AMDGPUISD::FP_TO_FP16:
16298 case AMDGPUISD::SIN_HW:
16299 case AMDGPUISD::COS_HW:
16311 if (
Op.getValueType() == MVT::i32) {
16317 if (RHS->getZExtValue() == 0xffff0000) {
16328 return Op.getValueType().getScalarType() != MVT::f16;
16338 case AMDGPUISD::CLAMP:
16339 case AMDGPUISD::FMED3:
16340 case AMDGPUISD::FMAX3:
16341 case AMDGPUISD::FMIN3:
16342 case AMDGPUISD::FMAXIMUM3:
16343 case AMDGPUISD::FMINIMUM3: {
16349 if (Subtarget->supportsMinMaxDenormModes() ||
16359 for (
unsigned I = 0, E =
Op.getNumOperands();
I != E; ++
I) {
16374 for (
unsigned i = 0, e =
Op.getNumOperands(); i != e; ++i) {
16408 if (
Op.getValueType() == MVT::i16) {
16420 unsigned IntrinsicID =
Op.getConstantOperandVal(0);
16422 switch (IntrinsicID) {
16423 case Intrinsic::amdgcn_update_dpp: {
16424 enum UpdateDPPOperand {
16431 if (QueryVT == MVT::f32 && (VT == MVT::i32 || VT == MVT::f32) &&
16432 Op.getConstantOperandVal(RowMask) == 0xf &&
16433 Op.getConstantOperandVal(BankMask) == 0xf &&
16434 Op.getConstantOperandVal(BoundCtrl) != 0)
16439 case Intrinsic::amdgcn_cvt_pkrtz:
16440 case Intrinsic::amdgcn_cubeid:
16441 case Intrinsic::amdgcn_frexp_mant:
16442 case Intrinsic::amdgcn_fdot2:
16443 case Intrinsic::amdgcn_rcp:
16444 case Intrinsic::amdgcn_rsq:
16445 case Intrinsic::amdgcn_rsq_clamp:
16446 case Intrinsic::amdgcn_rcp_legacy:
16447 case Intrinsic::amdgcn_rsq_legacy:
16448 case Intrinsic::amdgcn_trig_preop:
16449 case Intrinsic::amdgcn_tanh:
16450 case Intrinsic::amdgcn_log:
16451 case Intrinsic::amdgcn_exp2:
16452 case Intrinsic::amdgcn_sqrt:
16470 unsigned MaxDepth)
const {
16473 unsigned Opcode =
MI->getOpcode();
16475 if (Opcode == AMDGPU::G_FCANONICALIZE)
16478 std::optional<FPValueAndVReg> FCR;
16481 if (FCR->Value.isSignaling())
16483 if (!FCR->Value.isDenormal())
16494 case AMDGPU::G_FADD:
16495 case AMDGPU::G_FSUB:
16496 case AMDGPU::G_FMUL:
16497 case AMDGPU::G_FCEIL:
16498 case AMDGPU::G_FFLOOR:
16499 case AMDGPU::G_FRINT:
16500 case AMDGPU::G_FNEARBYINT:
16501 case AMDGPU::G_INTRINSIC_FPTRUNC_ROUND:
16502 case AMDGPU::G_INTRINSIC_TRUNC:
16503 case AMDGPU::G_INTRINSIC_ROUNDEVEN:
16504 case AMDGPU::G_FMA:
16505 case AMDGPU::G_FMAD:
16506 case AMDGPU::G_FSQRT:
16507 case AMDGPU::G_FDIV:
16508 case AMDGPU::G_FREM:
16509 case AMDGPU::G_FPOW:
16510 case AMDGPU::G_FPEXT:
16511 case AMDGPU::G_FLOG:
16512 case AMDGPU::G_FLOG2:
16513 case AMDGPU::G_FLOG10:
16514 case AMDGPU::G_FPTRUNC:
16515 case AMDGPU::G_AMDGPU_RCP_IFLAG:
16516 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE0:
16517 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE1:
16518 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE2:
16519 case AMDGPU::G_AMDGPU_CVT_F32_UBYTE3:
16521 case AMDGPU::G_FNEG:
16522 case AMDGPU::G_FABS:
16523 case AMDGPU::G_FCOPYSIGN:
16525 case AMDGPU::G_FMINNUM:
16526 case AMDGPU::G_FMAXNUM:
16527 case AMDGPU::G_FMINNUM_IEEE:
16528 case AMDGPU::G_FMAXNUM_IEEE:
16529 case AMDGPU::G_FMINIMUM:
16530 case AMDGPU::G_FMAXIMUM:
16531 case AMDGPU::G_FMINIMUMNUM:
16532 case AMDGPU::G_FMAXIMUMNUM: {
16533 if (Subtarget->supportsMinMaxDenormModes() ||
16540 case AMDGPU::G_BUILD_VECTOR:
16545 case AMDGPU::G_INTRINSIC:
16546 case AMDGPU::G_INTRINSIC_CONVERGENT:
16548 case Intrinsic::amdgcn_fmul_legacy:
16549 case Intrinsic::amdgcn_fmad_ftz:
16550 case Intrinsic::amdgcn_sqrt:
16551 case Intrinsic::amdgcn_fmed3:
16552 case Intrinsic::amdgcn_sin:
16553 case Intrinsic::amdgcn_cos:
16554 case Intrinsic::amdgcn_log:
16555 case Intrinsic::amdgcn_exp2:
16556 case Intrinsic::amdgcn_log_clamp:
16557 case Intrinsic::amdgcn_rcp:
16558 case Intrinsic::amdgcn_rcp_legacy:
16559 case Intrinsic::amdgcn_rsq:
16560 case Intrinsic::amdgcn_rsq_clamp:
16561 case Intrinsic::amdgcn_rsq_legacy:
16562 case Intrinsic::amdgcn_div_scale:
16563 case Intrinsic::amdgcn_div_fmas:
16564 case Intrinsic::amdgcn_div_fixup:
16565 case Intrinsic::amdgcn_fract:
16566 case Intrinsic::amdgcn_cvt_pkrtz:
16567 case Intrinsic::amdgcn_cubeid:
16568 case Intrinsic::amdgcn_cubema:
16569 case Intrinsic::amdgcn_cubesc:
16570 case Intrinsic::amdgcn_cubetc:
16571 case Intrinsic::amdgcn_frexp_mant:
16572 case Intrinsic::amdgcn_fdot2:
16573 case Intrinsic::amdgcn_trig_preop:
16574 case Intrinsic::amdgcn_tanh:
16593 if (
C.isDenormal()) {
16606 if (
C.isSignaling()) {
16621SITargetLowering::performFCanonicalizeCombine(
SDNode *
N,
16622 DAGCombinerInfo &DCI)
const {
16623 SelectionDAG &DAG = DCI.DAG;
16625 EVT VT =
N->getValueType(0);
16634 return getCanonicalConstantFP(DAG, SDLoc(
N), VT, CFP->getValueAPF());
16649 EVT EltVT =
Lo.getValueType();
16658 for (
unsigned I = 0;
I != 2; ++
I) {
16662 getCanonicalConstantFP(DAG, SL, EltVT, CFP->getValueAPF());
16663 }
else if (
Op.isUndef()) {
16698 return AMDGPUISD::FMAX3;
16700 return AMDGPUISD::FMAXIMUM3;
16702 return AMDGPUISD::SMAX3;
16704 return AMDGPUISD::UMAX3;
16708 return AMDGPUISD::FMIN3;
16710 return AMDGPUISD::FMINIMUM3;
16712 return AMDGPUISD::SMIN3;
16714 return AMDGPUISD::UMIN3;
16735 if (!MinK || !MaxK)
16747 unsigned Med3Opc =
Signed ? AMDGPUISD::SMED3 : AMDGPUISD::UMED3;
16748 if (VT == MVT::i32 || (VT == MVT::i16 && Subtarget->hasMed3_16()))
16749 return DAG.
getNode(Med3Opc, SL, VT, Src, MaxVal, MinVal);
16773 bool IsKnownNoNaNs)
const {
16809 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
16815 if (
Info->getMode().DX10Clamp) {
16824 if (VT == MVT::f32 || (VT == MVT::f16 && Subtarget->hasMed3_16())) {
16856 return (VT == MVT::f32) || (VT == MVT::f16 &&
Subtarget.hasMin3Max3_16()) ||
16857 (VT == MVT::v2f16 &&
Subtarget.hasMin3Max3PKF16());
16860 return (VT == MVT::f32 &&
Subtarget.hasMinimum3Maximum3F32()) ||
16861 (VT == MVT::f16 &&
Subtarget.hasMinimum3Maximum3F16()) ||
16862 (VT == MVT::v2f16 &&
Subtarget.hasMinimum3Maximum3PKF16());
16867 return (VT == MVT::i32) || (VT == MVT::i16 &&
Subtarget.hasMin3Max3_16());
16876 DAGCombinerInfo &DCI)
const {
16877 SelectionDAG &DAG = DCI.DAG;
16888 auto IsTreeWithCombinableChildren = [
Opc](
SDValue Op) {
16889 return (
Op.getOperand(0).getOpcode() ==
Opc &&
16890 Op.getOperand(0).hasOneUse()) ||
16892 Op.getOperand(1).hasOneUse());
16897 bool HasCombinableTreeChild =
16898 CanTreeCombineApply && (IsTreeWithCombinableChildren(Op0) ||
16899 IsTreeWithCombinableChildren(Op1));
16908 if (CanTreeCombineApply && !HasCombinableTreeChild) {
16946 if (
Known.isNonZero() &&
Known.Zero.getBoolValue())
16954 if (
SDValue Med3 = performIntMed3ImmCombine(
16959 if (
SDValue Med3 = performIntMed3ImmCombine(
16965 if (
SDValue Med3 = performIntMed3ImmCombine(
16970 if (
SDValue Med3 = performIntMed3ImmCombine(
16983 (
Opc == AMDGPUISD::FMIN_LEGACY &&
16984 Op0.
getOpcode() == AMDGPUISD::FMAX_LEGACY)) &&
16985 (VT == MVT::f32 || VT == MVT::f64 ||
16986 (VT == MVT::f16 && Subtarget->has16BitInsts()) ||
16987 (VT == MVT::bf16 && Subtarget->hasBF16PackedInsts()) ||
16988 (VT == MVT::v2bf16 && Subtarget->hasBF16PackedInsts()) ||
16989 (VT == MVT::v2f16 && Subtarget->hasVOP3PInsts())) &&
16991 if (
SDValue Res = performFPMed3ImmCombine(DAG, SDLoc(
N), Op0, Op1,
16992 N->getFlags().hasNoNaNs()))
16999 const SDNodeFlags
Flags =
N->getFlags();
17001 !Subtarget->hasIEEEMinimumMaximumInsts() &&
17005 return DAG.
getNode(NewOpc, SDLoc(
N), VT, Op0, Op1, Flags);
17015 return (CA->isPosZero() && CB->isOne()) ||
17016 (CA->isOne() && CB->isPosZero());
17025 DAGCombinerInfo &DCI)
const {
17026 EVT VT =
N->getValueType(0);
17030 SelectionDAG &DAG = DCI.DAG;
17041 return DAG.
getNode(AMDGPUISD::CLAMP, SL, VT, Src2);
17045 const SIMachineFunctionInfo *
Info = MF.
getInfo<SIMachineFunctionInfo>();
17049 if (
Info->getMode().DX10Clamp) {
17062 return DAG.
getNode(AMDGPUISD::CLAMP, SL, VT, Src0);
17069 DAGCombinerInfo &DCI)
const {
17072 if (
Src0.isUndef() &&
Src1.isUndef())
17073 return DCI.DAG.getUNDEF(
N->getValueType(0));
17080SITargetLowering::performExponentOnlyScaleCombine(
SDNode *
N,
17081 DAGCombinerInfo &DCI)
const {
17082 std::optional<unsigned> ScaleArgIdx =
17088 unsigned OpIdx = *ScaleArgIdx + 1;
17089 SelectionDAG &DAG = DCI.DAG;
17096 Ops[OpIdx] = DemandedScale;
17110 bool IsDivergentIdx,
17112 if (Subtarget->getCLOpts().use_divergent_register_indexing)
17115 unsigned VecSize = EltSize * NumElem;
17118 if (VecSize <= 64 && EltSize < 32)
17127 if (IsDivergentIdx)
17131 unsigned NumInsts = NumElem +
17132 ((EltSize + 31) / 32) * NumElem ;
17136 if (Subtarget->useVGPRIndexMode())
17137 return NumInsts <= 16;
17141 if (Subtarget->hasMovrel())
17142 return NumInsts <= 15;
17148 SDValue Idx =
N->getOperand(
N->getNumOperands() - 1);
17159 EltSize, NumElem, Idx->isDivergent(),
getSubtarget());
17163SITargetLowering::performExtractVectorEltCombine(
SDNode *
N,
17164 DAGCombinerInfo &DCI)
const {
17170 EVT ResVT =
N->getValueType(0);
17194 if (!
C ||
C->getZExtValue() != 0x1f)
17210 if (Vec.
hasOneUse() && DCI.isBeforeLegalize() && VecEltVT == ResVT) {
17238 DCI.AddToWorklist(Elt0.
getNode());
17239 DCI.AddToWorklist(Elt1.
getNode());
17270 if (KImm && KImm->getValueType(0).getSizeInBits() == 64) {
17271 uint64_t KImmValue = KImm->getZExtValue();
17273 (KImmValue >> (32 *
Idx->getZExtValue())) & 0xffffffff, SL, MVT::i32);
17276 if (KFPImm && KFPImm->getValueType(0).getSizeInBits() == 64) {
17278 KFPImm->getValueAPF().bitcastToAPInt().getZExtValue();
17279 return DAG.
getConstant((KFPImmValue >> (32 *
Idx->getZExtValue())) &
17285 if (!DCI.isBeforeLegalize())
17292 VecSize > 32 && VecSize % 32 == 0 && Idx) {
17295 unsigned BitIndex =
Idx->getZExtValue() * VecEltSize;
17296 unsigned EltIdx = BitIndex / 32;
17297 unsigned LeftoverBitIdx = BitIndex % 32;
17301 DCI.AddToWorklist(Cast.
getNode());
17305 DCI.AddToWorklist(Elt.
getNode());
17308 DCI.AddToWorklist(Srl.
getNode());
17312 DCI.AddToWorklist(
Trunc.getNode());
17314 if (VecEltVT == ResVT) {
17326SITargetLowering::performInsertVectorEltCombine(
SDNode *
N,
17327 DAGCombinerInfo &DCI)
const {
17341 SelectionDAG &DAG = DCI.DAG;
17344 EVT IdxVT =
Idx.getValueType();
17361 Src.getOperand(0).getValueType() == MVT::f16) {
17362 return Src.getOperand(0);
17366 APFloat Val = CFP->getValueAPF();
17367 bool LosesInfo =
true;
17377 DAGCombinerInfo &DCI)
const {
17378 assert(Subtarget->has16BitInsts() && !Subtarget->hasMed3_16() &&
17379 "combine only useful on gfx8");
17381 SDValue TruncSrc =
N->getOperand(0);
17382 EVT VT =
N->getValueType(0);
17383 if (VT != MVT::f16)
17386 if (TruncSrc.
getOpcode() != AMDGPUISD::FMED3 ||
17390 SelectionDAG &DAG = DCI.DAG;
17421unsigned SITargetLowering::getFusedOpcode(
const SelectionDAG &DAG,
17423 const SDNode *N1)
const {
17428 if (((VT == MVT::f32 &&
17430 (VT == MVT::f16 && Subtarget->hasMadF16() &&
17447 EVT VT =
N->getValueType(0);
17448 if (VT != MVT::i32 && VT != MVT::i64)
17454 unsigned Opc =
N->getOpcode();
17509 if (!Const ||
Hi_32(Const->getZExtValue()) !=
uint32_t(-1))
17528 DAGCombinerInfo &DCI)
const {
17531 SelectionDAG &DAG = DCI.DAG;
17532 EVT VT =
N->getValueType(0);
17542 if (!
N->isDivergent() && Subtarget->hasSMulHi())
17546 if (NumBits <= 32 || NumBits > 64)
17557 if (!Subtarget->hasFullRate64Ops()) {
17558 unsigned NumUsers = 0;
17559 for (SDNode *User :
LHS->
users()) {
17562 if (!
User->isAnyAdd())
17586 bool MulSignedLo =
false;
17587 if (!MulLHSUnsigned32 || !MulRHSUnsigned32) {
17596 if (VT != MVT::i64) {
17619 getMad64_32(DAG, SL, MVT::i64, MulLHSLo, MulRHSLo, AddRHS, MulSignedLo);
17621 if (!MulSignedLo && (!MulLHSUnsigned32 || !MulRHSUnsigned32)) {
17622 auto [AccumLo, AccumHi] = DAG.
SplitScalar(Accum, SL, MVT::i32, MVT::i32);
17624 if (!MulLHSUnsigned32) {
17631 if (!MulRHSUnsigned32) {
17642 if (VT != MVT::i64)
17648SITargetLowering::foldAddSub64WithZeroLowBitsTo32(
SDNode *
N,
17649 DAGCombinerInfo &DCI)
const {
17659 SelectionDAG &DAG = DCI.DAG;
17674 unsigned Opcode =
N->getOpcode();
17678 DAG.
getNode(Opcode, SL, MVT::i32,
Hi, ConstHi32,
N->getFlags());
17689static std::optional<ByteProvider<SDValue>>
17692 if (!Byte0 || Byte0->isConstantZero()) {
17693 return std::nullopt;
17696 if (Byte1 && !Byte1->isConstantZero()) {
17697 return std::nullopt;
17703 unsigned FirstCs =
First & 0x0c0c0c0c;
17704 unsigned SecondCs = Second & 0x0c0c0c0c;
17705 unsigned FirstNoCs =
First & ~0x0c0c0c0c;
17706 unsigned SecondNoCs = Second & ~0x0c0c0c0c;
17708 assert((FirstCs & 0xFF) | (SecondCs & 0xFF));
17709 assert((FirstCs & 0xFF00) | (SecondCs & 0xFF00));
17710 assert((FirstCs & 0xFF0000) | (SecondCs & 0xFF0000));
17711 assert((FirstCs & 0xFF000000) | (SecondCs & 0xFF000000));
17713 return (FirstNoCs | SecondNoCs) | (FirstCs & SecondCs);
17727 assert(Src0.Src.has_value() && Src1.Src.has_value());
17730 Src0s.
push_back({*Src0.Src, ((Src0.SrcOffset % 4) << 24) + 0x0c0c0c,
17731 Src0.SrcOffset / 4});
17732 Src1s.
push_back({*Src1.Src, ((Src1.SrcOffset % 4) << 24) + 0x0c0c0c,
17733 Src1.SrcOffset / 4});
17737 for (
int BPI = 0; BPI < 2; BPI++) {
17740 BPP = {Src1, Src0};
17742 unsigned ZeroMask = 0x0c0c0c0c;
17743 unsigned FMask = 0xFF << (8 * (3 - Step));
17745 unsigned FirstMask =
17746 (BPP.first.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask);
17747 unsigned SecondMask =
17748 (BPP.second.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask);
17752 int FirstGroup = -1;
17753 for (
int I = 0;
I < 2;
I++) {
17755 auto MatchesFirst = [&BPP](
DotSrc &IterElt) {
17756 return IterElt.SrcOp == *BPP.first.Src &&
17757 (IterElt.DWordOffset == (BPP.first.SrcOffset / 4));
17761 if (Match != Srcs.
end()) {
17762 Match->PermMask =
addPermMasks(FirstMask, Match->PermMask);
17767 if (FirstGroup != -1) {
17769 auto MatchesSecond = [&BPP](
DotSrc &IterElt) {
17770 return IterElt.SrcOp == *BPP.second.Src &&
17771 (IterElt.DWordOffset == (BPP.second.SrcOffset / 4));
17774 if (Match != Srcs.
end()) {
17775 Match->PermMask =
addPermMasks(SecondMask, Match->PermMask);
17777 Srcs.
push_back({*BPP.second.Src, SecondMask, BPP.second.SrcOffset / 4});
17785 unsigned ZeroMask = 0x0c0c0c0c;
17786 unsigned FMask = 0xFF << (8 * (3 - Step));
17790 ((Src0.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask)),
17791 Src0.SrcOffset / 4});
17794 ((Src1.SrcOffset % 4) << (8 * (3 - Step)) | (ZeroMask & ~FMask)),
17795 Src1.SrcOffset / 4});
17803 if (Srcs.
size() == 1) {
17804 auto *Elt = Srcs.
begin();
17808 if (Elt->PermMask == 0x3020100)
17811 return DAG.
getNode(AMDGPUISD::PERM, SL, MVT::i32, EltOp, EltOp,
17815 auto *FirstElt = Srcs.
begin();
17816 auto *SecondElt = std::next(FirstElt);
17823 auto FirstMask = FirstElt->PermMask;
17824 auto SecondMask = SecondElt->PermMask;
17826 unsigned FirstCs = FirstMask & 0x0c0c0c0c;
17827 unsigned FirstPlusFour = FirstMask | 0x04040404;
17830 FirstMask = (FirstPlusFour & 0x0F0F0F0F) | FirstCs;
17842 FirstElt = std::next(SecondElt);
17843 if (FirstElt == Srcs.
end())
17846 SecondElt = std::next(FirstElt);
17849 if (SecondElt == Srcs.
end()) {
17854 DAG.
getNode(AMDGPUISD::PERM, SL, MVT::i32, EltOp, EltOp,
17855 DAG.
getConstant(FirstElt->PermMask, SL, MVT::i32)));
17861 return Perms.
size() == 2
17867 for (
auto &[EntryVal, EntryMask, EntryOffset] : Srcs) {
17868 EntryMask = EntryMask >> ((4 - ChainLength) * 8);
17869 auto ZeroMask = ChainLength == 2 ? 0x0c0c0000 : 0x0c000000;
17870 EntryMask += ZeroMask;
17875 auto Opcode =
Op.getOpcode();
17877 return (Opcode ==
ISD::MUL || Opcode == AMDGPUISD::MUL_U24 ||
17878 Opcode == AMDGPUISD::MUL_I24);
17881static std::optional<bool>
17892 bool S0IsSigned = Known0.countMinLeadingOnes() > 0;
17895 bool S1IsSigned = Known1.countMinLeadingOnes() > 0;
17897 assert(!(S0IsUnsigned && S0IsSigned));
17898 assert(!(S1IsUnsigned && S1IsSigned));
17906 if ((S0IsUnsigned && S1IsUnsigned) || (S0IsSigned && S1IsSigned))
17912 if ((S0IsUnsigned && S1IsSigned) || (S0IsSigned && S1IsUnsigned))
17913 return std::nullopt;
17925 if ((S0IsSigned && !(S1IsSigned || S1IsUnsigned)) ||
17926 ((S1IsSigned && !(S0IsSigned || S0IsUnsigned))))
17931 if ((!(S1IsSigned || S1IsUnsigned) && !(S0IsSigned || S0IsUnsigned)))
17937 if ((S0IsUnsigned && !(S1IsSigned || S1IsUnsigned)) ||
17938 ((S1IsUnsigned && !(S0IsSigned || S0IsUnsigned))))
17939 return std::nullopt;
17945 DAGCombinerInfo &DCI)
const {
17946 SelectionDAG &DAG = DCI.DAG;
17947 EVT VT =
N->getValueType(0);
17953 if (Subtarget->hasMad64_32()) {
17959 if (
SDValue V = reassociateScalarOps(
N, DAG)) {
17963 if (VT == MVT::i64) {
17971 (Subtarget->hasDot1Insts() || Subtarget->hasDot8Insts())) {
17973 std::optional<bool> IsSigned;
17979 int ChainLength = 0;
17980 for (
int I = 0;
I < 4;
I++) {
17992 TempNode->getOperand(MulIdx), *Src0, *Src1,
17993 TempNode->getOperand(MulIdx)->getOperand(0),
17994 TempNode->getOperand(MulIdx)->getOperand(1), DAG);
17998 IsSigned = *IterIsSigned;
17999 if (*IterIsSigned != *IsSigned)
18002 auto AddIdx = 1 - MulIdx;
18005 if (
I == 2 &&
isMul(TempNode->getOperand(AddIdx))) {
18006 Src2s.
push_back(TempNode->getOperand(AddIdx));
18016 TempNode->getOperand(AddIdx), *Src0, *Src1,
18017 TempNode->getOperand(AddIdx)->getOperand(0),
18018 TempNode->getOperand(AddIdx)->getOperand(1), DAG);
18022 if (*IterIsSigned != *IsSigned)
18026 ChainLength =
I + 2;
18030 TempNode = TempNode->getOperand(AddIdx);
18032 ChainLength =
I + 1;
18034 if (TempNode.getOpcode() !=
ISD::ADD)
18036 LHS = TempNode->getOperand(0);
18037 RHS = TempNode->getOperand(1);
18040 if (ChainLength < 2)
18046 if (ChainLength < 4) {
18056 bool UseOriginalSrc =
false;
18057 if (ChainLength == 4 && Src0s.
size() == 1 && Src1s.
size() == 1 &&
18058 Src0s.
begin()->PermMask == Src1s.
begin()->PermMask &&
18059 Src0s.
begin()->SrcOp.getValueSizeInBits() >= 32 &&
18060 Src1s.
begin()->SrcOp.getValueSizeInBits() >= 32) {
18061 SmallVector<unsigned, 4> SrcBytes;
18062 auto Src0Mask = Src0s.
begin()->PermMask;
18063 SrcBytes.
push_back((Src0Mask >> 24) & 0xFF);
18064 bool UniqueEntries =
true;
18065 for (
auto I = 1;
I < 4;
I++) {
18066 auto NextByte = (Src0Mask >> ((3 -
I) * 8)) & 0xFF;
18069 UniqueEntries =
false;
18075 if (UniqueEntries) {
18076 UseOriginalSrc =
true;
18078 auto *FirstElt = Src0s.
begin();
18082 auto *SecondElt = Src1s.
begin();
18084 SecondElt->DWordOffset);
18093 if (!UseOriginalSrc) {
18100 DAG.
getExtOrTrunc(*IsSigned, Src2s[ChainLength - 1], SL, MVT::i32);
18103 : Intrinsic::amdgcn_udot4,
18113 if (VT != MVT::i32 || !DCI.isAfterLegalizeDAG())
18118 unsigned Opc =
LHS.getOpcode();
18130 auto Cond =
RHS.getOperand(0);
18135 SDVTList VTList = DAG.
getVTList(MVT::i32, MVT::i1);
18152 DAGCombinerInfo &DCI)
const {
18153 SelectionDAG &DAG = DCI.DAG;
18155 EVT VT =
N->getValueType(0);
18168 SDNodeFlags ShlFlags = N1->
getFlags();
18172 SDNodeFlags NewShlFlags =
18177 DCI.AddToWorklist(Inner.
getNode());
18184 if (Subtarget->hasMad64_32()) {
18194 if (VT == MVT::i64) {
18208 if (!YIsConstant && !ZIsConstant && !
X->isDivergent() &&
18209 Y->isDivergent() !=
Z->isDivergent()) {
18218 if (
Y->isDivergent())
18221 SDNodeFlags ReassocFlags =
18224 DCI.AddToWorklist(UniformInner.
getNode());
18236 DAGCombinerInfo &DCI)
const {
18237 SelectionDAG &DAG = DCI.DAG;
18238 EVT VT =
N->getValueType(0);
18240 if (VT == MVT::i64) {
18245 if (VT != MVT::i32)
18254 unsigned Opc =
RHS.getOpcode();
18261 auto Cond =
RHS.getOperand(0);
18266 SDVTList VTList = DAG.
getVTList(MVT::i32, MVT::i1);
18292 ConstantSDNode *ShiftAmt =
18294 unsigned BitWidth =
X.getValueType().getScalarSizeInBits();
18305 DAGCombinerInfo &DCI)
const {
18309 SelectionDAG &DAG = DCI.DAG;
18310 EVT VT =
N->getValueType(0);
18322 if (
A ==
LHS.getOperand(1)) {
18323 unsigned FusedOp = getFusedOpcode(DAG,
N,
LHS.getNode());
18324 if (FusedOp != 0) {
18326 return DAG.
getNode(FusedOp, SL, VT,
A, Two,
RHS);
18334 if (
A ==
RHS.getOperand(1)) {
18335 unsigned FusedOp = getFusedOpcode(DAG,
N,
RHS.getNode());
18336 if (FusedOp != 0) {
18338 return DAG.
getNode(FusedOp, SL, VT,
A, Two,
LHS);
18347 DAGCombinerInfo &DCI)
const {
18351 SelectionDAG &DAG = DCI.DAG;
18353 EVT VT =
N->getValueType(0);
18366 if (
A ==
LHS.getOperand(1)) {
18367 unsigned FusedOp = getFusedOpcode(DAG,
N,
LHS.getNode());
18368 if (FusedOp != 0) {
18372 return DAG.
getNode(FusedOp, SL, VT,
A, Two, NegRHS);
18381 if (
A ==
RHS.getOperand(1)) {
18382 unsigned FusedOp = getFusedOpcode(DAG,
N,
RHS.getNode());
18383 if (FusedOp != 0) {
18385 return DAG.
getNode(FusedOp, SL, VT,
A, NegTwo,
LHS);
18394 DAGCombinerInfo &DCI)
const {
18395 SelectionDAG &DAG = DCI.DAG;
18397 EVT VT =
N->getValueType(0);
18399 if (VT != MVT::f16 && VT != MVT::bf16)
18405 SDNodeFlags
Flags =
N->getFlags();
18406 SDNodeFlags RHSFlags =
RHS->getFlags();
18412 bool IsNegative =
false;
18413 if (CLHS->
isOne() || (IsNegative = CLHS->isMinusOne())) {
18422 Rsq = DAG.
getNode(AMDGPUISD::RSQ, SL, VT, SqrtOp, Flags);
18423 }
else if (VT == MVT::f16) {
18432 DAG.
getNode(AMDGPUISD::RSQ, SL, MVT::f32, Ext, Flags);
18449 DAGCombinerInfo &DCI)
const {
18450 SelectionDAG &DAG = DCI.DAG;
18451 EVT VT =
N->getValueType(0);
18455 if (!
N->isDivergent() &&
getSubtarget()->hasSALUFloatInsts() &&
18456 (ScalarVT == MVT::f32 || ScalarVT == MVT::f16)) {
18471 if ((ScalarVT == MVT::f64 || ScalarVT == MVT::f32 || ScalarVT == MVT::f16) &&
18476 const ConstantFPSDNode *FalseNode =
18486 if (ScalarVT == MVT::f32 &&
18492 if (TrueNodeExpVal == INT_MIN)
18495 if (FalseNodeExpVal == INT_MIN)
18515 DAGCombinerInfo &DCI)
const {
18516 SelectionDAG &DAG = DCI.DAG;
18517 EVT VT =
N->getValueType(0);
18520 if (!Subtarget->hasDot10Insts() || VT != MVT::f32)
18548 bool AllowInaccuracy =
N->getFlags().hasApproximateFuncs() &&
18549 FMA->getFlags().hasApproximateFuncs();
18550 if (!AllowInaccuracy) {
18553 if (Subtarget->dot2UnconditionalFlush()) {
18565 if (
N->getFlags().hasAllowContract() &&
FMA->getFlags().hasAllowContract()) {
18601 if (Vec1 == Vec2 || Vec3 == Vec4)
18607 if ((Vec1 == Vec3 && Vec2 == Vec4) || (Vec1 == Vec4 && Vec2 == Vec3)) {
18608 return DAG.
getNode(AMDGPUISD::FDOT2, SL, MVT::f32, Vec1, Vec2, FMAAcc,
18651 EVT VT =
LHS.getValueType();
18652 assert(VT == MVT::f64 &&
"Incorrect operand type!");
18699 const std::optional<bool> KnownEq =
18740 const std::optional<bool> KnownUge =
18782 const std::optional<bool> KnownUle =
18805 DAGCombinerInfo &DCI)
const {
18806 SelectionDAG &DAG = DCI.DAG;
18811 EVT VT =
LHS.getValueType();
18840 return LHS.getOperand(0);
18854 const APInt &CT =
LHS.getConstantOperandAPInt(1);
18855 const APInt &CF =
LHS.getConstantOperandAPInt(2);
18860 return DAG.
getNOT(SL,
LHS.getOperand(0), MVT::i1);
18863 return LHS.getOperand(0);
18869 if (VT == MVT::i64) {
18872 const KnownBits LHSKnownLo32 = LHSKnown.
trunc(32);
18873 const KnownBits RHSKnownLo32 = RHSKnown.
trunc(32);
18900 const std::optional<bool> KnownEq =
18908 const std::optional<bool> KnownEq =
18919 const std::optional<bool> KnownUge =
18939 const std::optional<bool> KnownUle =
18963 const KnownBits LHSKnownHi32 = LHSKnown.
extractBits(32, 32);
18964 const KnownBits RHSKnownHi32 = RHSKnown.
extractBits(32, 32);
18965 const std::optional<bool> KnownEq =
18968 if (KnownEq ==
true) {
18974 return DAG.
getSetCC(SL,
N->getValueType(0), LHSLo, RHSLo, NewCC);
19006 DAG.
getVTList(MVT::i32, MVT::i1), {Op0Lo, Op1Lo});
19011 {Op0Hi, Op1Hi, CarryInHi});
19021 DCI.CombineTo(
LHS.getNode(), Result);
19025 if (VT != MVT::f32 && VT != MVT::f64 &&
19026 (!Subtarget->has16BitInsts() || VT != MVT::f16))
19041 const unsigned IsInfMask =
19043 const unsigned IsFiniteMask =
19048 return DAG.
getNode(AMDGPUISD::FP_CLASS, SL, MVT::i1,
LHS.getOperand(0),
19053 if (VT == MVT::f64) {
19064SITargetLowering::performCvtF32UByteNCombine(
SDNode *
N,
19065 DAGCombinerInfo &DCI)
const {
19066 SelectionDAG &DAG = DCI.DAG;
19068 unsigned Offset =
N->getOpcode() - AMDGPUISD::CVT_F32_UBYTE0;
19087 unsigned ShiftOffset = 8 *
Offset;
19089 ShiftOffset -=
C->getZExtValue();
19091 ShiftOffset +=
C->getZExtValue();
19093 if (ShiftOffset < 32 && (ShiftOffset % 8) == 0) {
19094 return DAG.
getNode(AMDGPUISD::CVT_F32_UBYTE0 + ShiftOffset / 8, SL,
19095 MVT::f32, Shifted);
19106 DCI.AddToWorklist(
N);
19113 return DAG.
getNode(
N->getOpcode(), SL, MVT::f32, DemandedSrc);
19119 DAGCombinerInfo &DCI)
const {
19128 (
F.isNaN() && MF.
getInfo<SIMachineFunctionInfo>()->getMode().DX10Clamp)) {
19129 return DCI.DAG.getConstantFP(
Zero, SDLoc(
N),
N->getValueType(0));
19134 return DCI.DAG.getConstantFP(One, SDLoc(
N),
N->getValueType(0));
19136 return getCanonicalConstantFP(DCI.DAG, SDLoc(
N),
N->getValueType(0),
F);
19146 FrexpInput =
V.getOperand(0);
19156SITargetLowering::performFrexpSelectCombine(
SDNode *
N,
19157 DAGCombinerInfo &DCI)
const {
19159 if (Subtarget->hasFractBug())
19171 bool CondSelectsZero;
19179 CondSelectsZero =
true;
19180 }
else if (
isFrexpExp(TrueVal, FrexpInput)) {
19183 CondSelectsZero =
false;
19195 bool IsNonFiniteTest =
false;
19207 bool LHSMatchesFrexp =
19208 (CondLHS == FrexpInput) ||
19209 (LHSIsFabs &&
peekFPSignOps(FAbsInput) == FrexpInputStripped) ||
19211 bool RHSMatchesFrexp = (CondRHS == FrexpInput) ||
19219 SelectionDAG &DAG = DCI.DAG;
19220 if (LHSMatchesFrexp &&
19222 IsNonFiniteTest = CondSelectsZero;
19224 IsNonFiniteTest = CondSelectsZero;
19231 IsNonFiniteTest = CondSelectsZero;
19238 IsNonFiniteTest = !CondSelectsZero;
19244 SelectionDAG &DAG = DCI.DAG;
19245 if (LHSMatchesFrexp &&
19247 IsNonFiniteTest = !CondSelectsZero;
19249 IsNonFiniteTest = !CondSelectsZero;
19253 if (!IsNonFiniteTest)
19261 DAGCombinerInfo &DCI)
const {
19282 bool isFloatingPoint =
LHS.getValueType().isFloatingPoint();
19283 bool isInteger =
LHS.getValueType().isInteger();
19286 if (!isFloatingPoint && !isInteger)
19291 bool isNonEquality =
19293 if (!isEquality && !isNonEquality)
19310 if (isFloatingPoint) {
19312 if (!Val.
isNormal() || Subtarget->getInstrInfo()->isInlineConstant(Val))
19315 const std::optional<int64_t> Val =
19324 if (!(isEquality && TrueVal == ConstVal) &&
19325 !(isNonEquality && FalseVal == ConstVal))
19329 if (isFloatingPoint && isNonEquality && FalseVal == ConstVal &&
19330 !
Cond->getFlags().hasNoNaNs() && !DCI.DAG.isKnownNeverNaN(ArgVal))
19337 SelectLHS, SelectRHS);
19342 switch (
N->getOpcode()) {
19364 if (
auto Res = promoteUniformOpToI32(
SDValue(
N, 0), DCI))
19385 switch (
N->getOpcode()) {
19387 return performAddCombine(
N, DCI);
19389 return performPtrAddCombine(
N, DCI);
19391 return performSubCombine(
N, DCI);
19393 return performFAddCombine(
N, DCI);
19395 return performFSubCombine(
N, DCI);
19397 return performFDivCombine(
N, DCI);
19399 return performFMulCombine(
N, DCI);
19401 return performSetCCCombine(
N, DCI);
19403 if (
auto Res = performFrexpSelectCombine(
N, DCI))
19405 if (
auto Res = performSelectCombine(
N, DCI))
19420 case AMDGPUISD::FMIN_LEGACY:
19421 case AMDGPUISD::FMAX_LEGACY:
19422 return performMinMaxCombine(
N, DCI);
19424 return performFMACombine(
N, DCI);
19426 return performAndCombine(
N, DCI);
19428 return performOrCombine(
N, DCI);
19431 if (
N->getValueType(0) == MVT::i32 &&
N->isDivergent() &&
19432 TII->pseudoToMCOpcode(AMDGPU::V_PERM_B32_e64) != -1) {
19438 return performXorCombine(
N, DCI);
19441 return performZeroOrAnyExtendCombine(
N, DCI);
19443 return performExtendTruncShiftCombine(
N, DCI);
19445 return performSignExtendInRegCombine(
N, DCI);
19446 case AMDGPUISD::FP_CLASS:
19447 return performClassCombine(
N, DCI);
19449 return performFCanonicalizeCombine(
N, DCI);
19450 case AMDGPUISD::RCP:
19451 return performRcpCombine(
N, DCI);
19453 case AMDGPUISD::FRACT:
19454 case AMDGPUISD::RSQ:
19455 case AMDGPUISD::RCP_LEGACY:
19456 case AMDGPUISD::RCP_IFLAG:
19457 case AMDGPUISD::RSQ_CLAMP: {
19466 return performUCharToFloatCombine(
N, DCI);
19468 return performFCopySignCombine(
N, DCI);
19469 case AMDGPUISD::CVT_F32_UBYTE0:
19470 case AMDGPUISD::CVT_F32_UBYTE1:
19471 case AMDGPUISD::CVT_F32_UBYTE2:
19472 case AMDGPUISD::CVT_F32_UBYTE3:
19473 return performCvtF32UByteNCombine(
N, DCI);
19474 case AMDGPUISD::FMED3:
19475 return performFMed3Combine(
N, DCI);
19476 case AMDGPUISD::CVT_PKRTZ_F16_F32:
19477 return performCvtPkRTZCombine(
N, DCI);
19479 if (
SDValue Res = performExponentOnlyScaleCombine(
N, DCI))
19482 case AMDGPUISD::CLAMP:
19483 return performClampCombine(
N, DCI);
19486 EVT VT =
N->getValueType(0);
19489 if (VT == MVT::v2i16 || VT == MVT::v2f16 || VT == MVT::v2bf16) {
19492 EVT EltVT = Src.getValueType();
19493 if (EltVT != MVT::i16)
19503 return performExtractVectorEltCombine(
N, DCI);
19505 return performInsertVectorEltCombine(
N, DCI);
19507 return performFPRoundCombine(
N, DCI);
19516 return performMemSDNodeCombine(MemNode, DCI);
19547 unsigned Opcode =
Node->getMachineOpcode();
19550 int D16Idx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::d16) - 1;
19551 if (D16Idx >= 0 &&
Node->getConstantOperandVal(D16Idx))
19554 SDNode *
Users[5] = {
nullptr};
19556 unsigned DmaskIdx =
19557 AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::dmask) - 1;
19558 unsigned OldDmask =
Node->getConstantOperandVal(DmaskIdx);
19559 unsigned NewDmask = 0;
19560 unsigned TFEIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::tfe) - 1;
19561 unsigned LWEIdx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::lwe) - 1;
19562 bool UsesTFC = (int(TFEIdx) >= 0 &&
Node->getConstantOperandVal(TFEIdx)) ||
19563 (
int(LWEIdx) >= 0 &&
Node->getConstantOperandVal(LWEIdx));
19564 unsigned TFCLane = 0;
19565 bool HasChain =
Node->getNumValues() > 1;
19567 if (OldDmask == 0) {
19575 TFCLane = OldBitsSet;
19579 for (SDUse &Use :
Node->uses()) {
19582 if (
Use.getResNo() != 0)
19585 SDNode *
User =
Use.getUser();
19588 if (!
User->isMachineOpcode() ||
19589 User->getMachineOpcode() != TargetOpcode::EXTRACT_SUBREG)
19601 if (UsesTFC && Lane == TFCLane) {
19606 for (
unsigned i = 0, Dmask = OldDmask; (i <= Lane) && (Dmask != 0); i++) {
19608 Dmask &= ~(1 << Comp);
19616 NewDmask |= 1 << Comp;
19621 bool NoChannels = !NewDmask;
19628 if (OldBitsSet == 1)
19634 if (NewDmask == OldDmask)
19643 unsigned NewChannels = BitsSet + UsesTFC;
19647 assert(NewOpcode != -1 &&
19648 NewOpcode !=
static_cast<int>(
Node->getMachineOpcode()) &&
19649 "failed to find equivalent MIMG op");
19657 MVT SVT =
Node->getValueType(0).getVectorElementType().getSimpleVT();
19659 MVT ResultVT = NewChannels == 1
19662 : NewChannels == 5 ? 8
19664 SDVTList NewVTList =
19667 MachineSDNode *NewNode =
19676 if (NewChannels == 1) {
19686 for (
unsigned i = 0, Idx = AMDGPU::sub0; i < 5; ++i) {
19691 if (i || !NoChannels)
19696 if (NewUser != User) {
19706 Idx = AMDGPU::sub1;
19709 Idx = AMDGPU::sub2;
19712 Idx = AMDGPU::sub3;
19715 Idx = AMDGPU::sub4;
19726 Op =
Op.getOperand(0);
19747 MRI.createVirtualRegister(&AMDGPU::VReg_1RegClass), MVT::i1);
19751 Node->getOperand(0), SL, VReg, SrcVal,
19757 return ToResultReg.
getNode();
19762 for (
unsigned i = 0; i <
Node->getNumOperands(); ++i) {
19764 Ops.push_back(
Node->getOperand(i));
19770 Node->getOperand(i).getValueType(),
19771 Node->getOperand(i)),
19783 unsigned Opcode =
Node->getMachineOpcode();
19785 if (
TII->isImage(Opcode) && !
TII->get(Opcode).mayStore() &&
19786 !
TII->isGather4(Opcode) &&
19788 return adjustWritemask(
Node, DAG);
19791 if (Opcode == AMDGPU::INSERT_SUBREG || Opcode == AMDGPU::REG_SEQUENCE) {
19797 case AMDGPU::V_DIV_SCALE_F32_e64:
19798 case AMDGPU::V_DIV_SCALE_F64_e64: {
19806 if ((Src0.isMachineOpcode() &&
19807 Src0.getMachineOpcode() != AMDGPU::IMPLICIT_DEF) &&
19808 (Src0 == Src1 || Src0 == Src2))
19811 MVT VT = Src0.getValueType().getSimpleVT();
19823 if (Src0.isMachineOpcode() &&
19824 Src0.getMachineOpcode() == AMDGPU::IMPLICIT_DEF) {
19825 if (Src1.isMachineOpcode() &&
19826 Src1.getMachineOpcode() != AMDGPU::IMPLICIT_DEF)
19828 else if (Src2.isMachineOpcode() &&
19829 Src2.getMachineOpcode() != AMDGPU::IMPLICIT_DEF)
19832 assert(Src1.getMachineOpcode() == AMDGPU::IMPLICIT_DEF);
19864 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::vdata);
19865 unsigned InitIdx = 0;
19867 if (
TII->isImage(
MI)) {
19875 unsigned TFEVal = TFE ? TFE->
getImm() : 0;
19876 unsigned LWEVal = LWE ? LWE->
getImm() : 0;
19877 unsigned D16Val = D16 ? D16->getImm() : 0;
19879 if (!TFEVal && !LWEVal)
19890 assert(MO_Dmask &&
"Expected dmask operand in instruction");
19892 unsigned dmask = MO_Dmask->
getImm();
19897 bool Packed = !Subtarget->hasUnpackedD16VMem();
19899 InitIdx = D16Val && Packed ? ((ActiveLanes + 1) >> 1) + 1 : ActiveLanes + 1;
19906 uint32_t DstSize =
TRI.getRegSizeInBits(*DstRC) / 32;
19907 if (DstSize < InitIdx)
19911 InitIdx =
TRI.getRegSizeInBits(*DstRC) / 32;
19919 Register PrevDst =
MRI.cloneVirtualRegister(
MI.getOperand(DstIdx).getReg());
19920 unsigned NewDst = 0;
19925 unsigned SizeLeft = Subtarget->usePRTStrictNull() ? InitIdx : 1;
19926 unsigned CurrIdx = Subtarget->usePRTStrictNull() ? 0 : (InitIdx - 1);
19929 for (; SizeLeft; SizeLeft--, CurrIdx++) {
19930 NewDst =
MRI.createVirtualRegister(
TII->getOpRegClass(
MI, DstIdx));
19932 Register SubReg =
MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass);
19950 MI.tieOperands(DstIdx,
MI.getNumOperands() - 1);
19962 if (
TII->isVOP3(
MI.getOpcode())) {
19964 TII->legalizeOperandsVOP3(
MRI,
MI);
19966 if (
TII->isMAI(
MI)) {
19971 int Src0Idx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(),
19972 AMDGPU::OpName::scale_src0);
19973 if (Src0Idx != -1) {
19974 int Src1Idx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(),
19975 AMDGPU::OpName::scale_src1);
19976 if (
TII->usesConstantBus(
MRI,
MI, Src0Idx) &&
19977 TII->usesConstantBus(
MRI,
MI, Src1Idx))
19978 TII->legalizeOpWithMove(
MI, Src1Idx);
19985 if (
TII->isImage(
MI))
19986 TII->enforceOperandRCAlignment(
MI, AMDGPU::OpName::vaddr);
20028 uint64_t RsrcDword2And3)
const {
20058std::pair<unsigned, const TargetRegisterClass *>
20065 if (Constraint.
size() == 1) {
20069 if (VT == MVT::Other)
20072 switch (Constraint[0]) {
20079 RC = &AMDGPU::SReg_32RegClass;
20082 RC = &AMDGPU::SGPR_64RegClass;
20087 return std::pair(0U,
nullptr);
20094 return std::pair(0U,
nullptr);
20096 RC = Subtarget->useRealTrue16Insts() ? &AMDGPU::VGPR_16RegClass
20097 : &AMDGPU::VGPR_32_Lo256RegClass;
20100 RC = Subtarget->hasVGPRMSBs()
20101 ?
TRI->getAlignedLo256VGPRClassForBitWidth(
BitWidth)
20104 return std::pair(0U,
nullptr);
20109 if (!Subtarget->hasMAIInsts())
20113 return std::pair(0U,
nullptr);
20115 RC = &AMDGPU::AGPR_32RegClass;
20120 return std::pair(0U,
nullptr);
20125 }
else if (Constraint ==
"VA" && Subtarget->hasGFX90AInsts()) {
20129 RC = &AMDGPU::AV_32RegClass;
20132 RC =
TRI->getVectorSuperClassForBitWidth(
BitWidth);
20134 return std::pair(0U,
nullptr);
20143 return std::pair(0U, RC);
20146 if (Kind !=
'\0') {
20148 RC = &AMDGPU::VGPR_32_Lo256RegClass;
20149 }
else if (Kind ==
's') {
20150 RC = &AMDGPU::SGPR_32RegClass;
20151 }
else if (Kind ==
'a') {
20152 RC = &AMDGPU::AGPR_32RegClass;
20158 return std::pair(0U,
nullptr);
20164 return std::pair(0U,
nullptr);
20168 RC =
TRI->getVGPRClassForBitWidth(Width);
20170 RC =
TRI->getSGPRClassForBitWidth(Width);
20172 RC =
TRI->getAGPRClassForBitWidth(Width);
20174 Reg =
TRI->getMatchingSuperReg(Reg, AMDGPU::sub0, RC);
20179 return std::pair(0U,
nullptr);
20181 return std::pair(Reg, RC);
20190 return std::pair(0U,
nullptr);
20191 if (RC && Idx < RC->getNumRegs())
20193 return std::pair(0U,
nullptr);
20199 Ret.second =
TRI->getPhysRegBaseClass(Ret.first);
20200 if (!Subtarget->useRealTrue16Insts() &&
20201 TRI->getRegSizeInBits(*Ret.second) == 16)
20202 return std::pair(0U,
nullptr);
20209 if (Constraint.
size() == 1) {
20210 switch (Constraint[0]) {
20220 }
else if (Constraint ==
"DA" || Constraint ==
"DB") {
20228 if (Constraint.
size() == 1) {
20229 switch (Constraint[0]) {
20239 }
else if (Constraint.
size() == 2) {
20240 if (Constraint ==
"VA")
20242 if (Constraint ==
"RF")
20253 if (ConstraintCode ==
"RF")
20268 std::vector<SDValue> &
Ops,
20283 unsigned Size =
Op.getScalarValueSizeInBits();
20287 if (
Size == 16 && !Subtarget->has16BitInsts())
20291 Val =
C->getSExtValue();
20295 Val =
C->getValueAPF().bitcastToAPInt().getSExtValue();
20299 if (
Size != 16 ||
Op.getNumOperands() != 2)
20301 if (
Op.getOperand(0).isUndef() ||
Op.getOperand(1).isUndef())
20304 Val =
C->getSExtValue();
20308 Val =
C->getValueAPF().bitcastToAPInt().getSExtValue();
20317 uint64_t Val)
const {
20318 if (Constraint.
size() == 1) {
20319 switch (Constraint[0]) {
20334 }
else if (Constraint.
size() == 2) {
20335 if (Constraint ==
"DA") {
20336 int64_t HiBits =
static_cast<int32_t
>(Val >> 32);
20337 int64_t LoBits =
static_cast<int32_t
>(Val);
20341 if (Constraint ==
"DB") {
20349 unsigned MaxSize)
const {
20350 unsigned Size = std::min<unsigned>(
Op.getScalarValueSizeInBits(), MaxSize);
20351 bool HasInv2Pi = Subtarget->hasInv2PiInlineImm();
20353 MVT VT =
Op.getSimpleValueType();
20378 switch (UnalignedClassID) {
20379 case AMDGPU::VReg_64RegClassID:
20380 return AMDGPU::VReg_64_Align2RegClassID;
20381 case AMDGPU::VReg_96RegClassID:
20382 return AMDGPU::VReg_96_Align2RegClassID;
20383 case AMDGPU::VReg_128RegClassID:
20384 return AMDGPU::VReg_128_Align2RegClassID;
20385 case AMDGPU::VReg_160RegClassID:
20386 return AMDGPU::VReg_160_Align2RegClassID;
20387 case AMDGPU::VReg_192RegClassID:
20388 return AMDGPU::VReg_192_Align2RegClassID;
20389 case AMDGPU::VReg_224RegClassID:
20390 return AMDGPU::VReg_224_Align2RegClassID;
20391 case AMDGPU::VReg_256RegClassID:
20392 return AMDGPU::VReg_256_Align2RegClassID;
20393 case AMDGPU::VReg_288RegClassID:
20394 return AMDGPU::VReg_288_Align2RegClassID;
20395 case AMDGPU::VReg_320RegClassID:
20396 return AMDGPU::VReg_320_Align2RegClassID;
20397 case AMDGPU::VReg_352RegClassID:
20398 return AMDGPU::VReg_352_Align2RegClassID;
20399 case AMDGPU::VReg_384RegClassID:
20400 return AMDGPU::VReg_384_Align2RegClassID;
20401 case AMDGPU::VReg_512RegClassID:
20402 return AMDGPU::VReg_512_Align2RegClassID;
20403 case AMDGPU::VReg_1024RegClassID:
20404 return AMDGPU::VReg_1024_Align2RegClassID;
20405 case AMDGPU::AReg_64RegClassID:
20406 return AMDGPU::AReg_64_Align2RegClassID;
20407 case AMDGPU::AReg_96RegClassID:
20408 return AMDGPU::AReg_96_Align2RegClassID;
20409 case AMDGPU::AReg_128RegClassID:
20410 return AMDGPU::AReg_128_Align2RegClassID;
20411 case AMDGPU::AReg_160RegClassID:
20412 return AMDGPU::AReg_160_Align2RegClassID;
20413 case AMDGPU::AReg_192RegClassID:
20414 return AMDGPU::AReg_192_Align2RegClassID;
20415 case AMDGPU::AReg_256RegClassID:
20416 return AMDGPU::AReg_256_Align2RegClassID;
20417 case AMDGPU::AReg_512RegClassID:
20418 return AMDGPU::AReg_512_Align2RegClassID;
20419 case AMDGPU::AReg_1024RegClassID:
20420 return AMDGPU::AReg_1024_Align2RegClassID;
20436 if (Info->isEntryFunction()) {
20443 unsigned MaxNumSGPRs = ST.getMaxNumSGPRs(MF);
20445 ? AMDGPU::SGPR_32RegClass.getRegister(MaxNumSGPRs - 1)
20446 :
TRI->getAlignedHighSGPRForRC(MF, 2,
20447 &AMDGPU::SGPR_64RegClass);
20448 Info->setSGPRForEXECCopy(SReg);
20450 assert(!
TRI->isSubRegister(Info->getScratchRSrcReg(),
20451 Info->getStackPtrOffsetReg()));
20452 if (Info->getStackPtrOffsetReg() != AMDGPU::SP_REG)
20453 MRI.replaceRegWith(AMDGPU::SP_REG, Info->getStackPtrOffsetReg());
20457 if (Info->getScratchRSrcReg() != AMDGPU::PRIVATE_RSRC_REG)
20458 MRI.replaceRegWith(AMDGPU::PRIVATE_RSRC_REG, Info->getScratchRSrcReg());
20460 if (Info->getFrameOffsetReg() != AMDGPU::FP_REG)
20461 MRI.replaceRegWith(AMDGPU::FP_REG, Info->getFrameOffsetReg());
20463 Info->limitOccupancy(MF);
20465 if (ST.isWave32() && !MF.
empty()) {
20466 for (
auto &
MBB : MF) {
20467 for (
auto &
MI :
MBB) {
20468 TII->fixImplicitOperands(
MI);
20478 if (ST.needsAlignedVGPRs()) {
20479 for (
unsigned I = 0, E =
MRI.getNumVirtRegs();
I != E; ++
I) {
20485 if (NewClassID != -1)
20486 MRI.setRegClass(Reg,
TRI->getRegClass(NewClassID));
20495 const APInt &DemandedElts,
20497 unsigned Depth)
const {
20499 unsigned Opc =
Op.getOpcode();
20502 unsigned IID =
Op.getConstantOperandVal(0);
20504 case Intrinsic::amdgcn_mbcnt_lo:
20505 case Intrinsic::amdgcn_mbcnt_hi: {
20510 Known.Zero.setBitsFrom(
20511 IID == Intrinsic::amdgcn_mbcnt_lo ? ST.getWavefrontSizeLog2() : 5);
20537 unsigned MaxValue =
20544 unsigned BFEWidth,
bool SExt,
unsigned Depth) {
20548 unsigned Src1Cst = 0;
20549 if (Src1.isImm()) {
20550 Src1Cst = Src1.getImm();
20551 }
else if (Src1.isReg()) {
20555 Src1Cst = Cst->Value.getZExtValue();
20566 if (Width >= BFEWidth)
20583 unsigned Depth)
const {
20586 switch (
MI->getOpcode()) {
20587 case AMDGPU::S_BFE_I32:
20590 case AMDGPU::S_BFE_U32:
20593 case AMDGPU::S_BFE_I64:
20596 case AMDGPU::S_BFE_U64:
20599 case AMDGPU::G_INTRINSIC:
20600 case AMDGPU::G_INTRINSIC_CONVERGENT: {
20603 case Intrinsic::amdgcn_workitem_id_x:
20606 case Intrinsic::amdgcn_workitem_id_y:
20609 case Intrinsic::amdgcn_workitem_id_z:
20612 case Intrinsic::amdgcn_mbcnt_lo:
20613 case Intrinsic::amdgcn_mbcnt_hi: {
20616 Known.Zero.setBitsFrom(IID == Intrinsic::amdgcn_mbcnt_lo
20625 case Intrinsic::amdgcn_groupstaticsize: {
20629 Known.Zero.setHighBits(
20633 case Intrinsic::amdgcn_readfirstlane:
20634 case Intrinsic::amdgcn_readlane: {
20640 case Intrinsic::amdgcn_mul_u24:
20641 case Intrinsic::amdgcn_mul_i24: {
20648 bool SelfMultiply = LHS == RHS;
20654 LHSKnown = RHSKnown;
20662 IID == Intrinsic::amdgcn_mul_i24,
20669 case AMDGPU::G_AMDGPU_BUFFER_LOAD_UBYTE:
20670 Known.Zero.setHighBits(24);
20672 case AMDGPU::G_AMDGPU_BUFFER_LOAD_USHORT:
20673 Known.Zero.setHighBits(16);
20675 case AMDGPU::G_AMDGPU_COPY_SCC_VCC:
20678 Known.Zero.setHighBits(
Known.getBitWidth() - 1);
20680 case AMDGPU::G_AMDGPU_SMED3:
20681 case AMDGPU::G_AMDGPU_UMED3: {
20682 auto [Dst, Src0, Src1, Src2] =
MI->getFirst4Regs();
20709 unsigned Depth)
const {
20718 if (
MaybeAlign RetAlign = Attrs.getRetAlignment())
20739 BlockToAlign =
ML->getHeader();
20743 if (needsFetchWindowAlignment(*BlockToAlign))
20765 if (Header->getAlignment() != PrefAlign)
20766 return Header->getAlignment();
20768 unsigned LoopSize = 0;
20773 LoopSize +=
MBB->getAlignment().value() / 2;
20776 LoopSize +=
TII->getInstSizeInBytes(
MI);
20777 if (LoopSize > 192)
20782 if (LoopSize <= 64)
20785 if (LoopSize <= 128)
20786 return CacheLineAlign;
20792 auto I = Exit->getFirstNonDebugInstr();
20793 if (
I != Exit->end() &&
I->getOpcode() == AMDGPU::S_INST_PREFETCH)
20794 return CacheLineAlign;
20803 if (PreTerm == Pre->
begin() ||
20804 std::prev(PreTerm)->getOpcode() != AMDGPU::S_INST_PREFETCH)
20808 auto ExitHead = Exit->getFirstNonDebugInstr();
20809 if (ExitHead == Exit->end() ||
20810 ExitHead->getOpcode() != AMDGPU::S_INST_PREFETCH)
20815 return CacheLineAlign;
20823 if (needsFetchWindowAlignment(*
MBB))
20828bool SITargetLowering::needsFetchWindowAlignment(
20830 if (!
getSubtarget()->hasLoopHeadInstSplitSensitivity())
20834 if (
MI.isMetaInstruction())
20837 return TII->getInstSizeInBytes(
MI) > 4;
20847 N =
N->getOperand(0).getNode();
20857 switch (
N->getOpcode()) {
20865 if (Reg.isPhysical() ||
MRI.isLiveIn(Reg))
20866 return !
TRI->isSGPRReg(
MRI, Reg);
20872 return !
TRI->isSGPRReg(
MRI, Reg);
20876 unsigned AS = L->getAddressSpace();
20883 case AMDGPUISD::REG_LOAD:
20891 case AMDGPUISD::ATOMIC_CMP_SWAP:
20892 case AMDGPUISD::BUFFER_ATOMIC_SWAP:
20893 case AMDGPUISD::BUFFER_ATOMIC_ADD:
20894 case AMDGPUISD::BUFFER_ATOMIC_SUB:
20895 case AMDGPUISD::BUFFER_ATOMIC_SMIN:
20896 case AMDGPUISD::BUFFER_ATOMIC_UMIN:
20897 case AMDGPUISD::BUFFER_ATOMIC_SMAX:
20898 case AMDGPUISD::BUFFER_ATOMIC_UMAX:
20899 case AMDGPUISD::BUFFER_ATOMIC_AND:
20900 case AMDGPUISD::BUFFER_ATOMIC_OR:
20901 case AMDGPUISD::BUFFER_ATOMIC_XOR:
20902 case AMDGPUISD::BUFFER_ATOMIC_INC:
20903 case AMDGPUISD::BUFFER_ATOMIC_DEC:
20904 case AMDGPUISD::BUFFER_ATOMIC_CMPSWAP:
20905 case AMDGPUISD::BUFFER_ATOMIC_FADD:
20906 case AMDGPUISD::BUFFER_ATOMIC_FMIN:
20907 case AMDGPUISD::BUFFER_ATOMIC_FMAX:
20913 return A->readMem() &&
A->writeMem();
20934 switch (Ty.getScalarSizeInBits()) {
20946 const APInt &DemandedElts,
20949 unsigned Depth)
const {
20950 if (
Op.getOpcode() == AMDGPUISD::CLAMP) {
20954 if (Info->getMode().DX10Clamp)
20967enum class AtomicFlushDenormalReason {
20970 IgnoreDenormalMode,
20971 FunctionFlushesDenormals
20976enum class GlobalFPAtomicLegality {
20978 AgentScopeFineGrainedRemoteMemory,
20979 EmulatedSystemScope,
20981 NoFineGrainedMemory
20988static AtomicFlushDenormalReason
20990 if (RMW->
hasMetadata(LLVMContext::MD_atomic_ignore_denormal_mode))
20991 return AtomicFlushDenormalReason::IgnoreDenormalMode;
20996 ? AtomicFlushDenormalReason::FunctionFlushesDenormals
20997 : AtomicFlushDenormalReason::IEEE;
21002 GlobalFPAtomicLegality MemLegality,
21003 AtomicFlushDenormalReason DenormReason) {
21006 if (MemScope.empty())
21007 MemScope =
"system";
21010 R <<
"hardware instruction generated for atomic "
21012 <<
" at " <<
ore::NV(
"SyncScope", MemScope) <<
" scope since ";
21014 switch (MemLegality) {
21015 case GlobalFPAtomicLegality::AgentScopeFineGrainedRemoteMemory:
21016 R <<
"fine-grained remote memory atomics work below system scope";
21018 case GlobalFPAtomicLegality::EmulatedSystemScope:
21019 R <<
"system scope atomics are emulated in hardware";
21021 case GlobalFPAtomicLegality::NoRemoteMemory:
21022 R <<
"memory is not remote (!amdgpu.no.remote.memory)";
21024 case GlobalFPAtomicLegality::NoFineGrainedMemory:
21025 R <<
"memory is not fine-grained (!amdgpu.no.fine.grained.memory)";
21027 case GlobalFPAtomicLegality::Illegal:
21031 switch (DenormReason) {
21032 case AtomicFlushDenormalReason::Native:
21034 case AtomicFlushDenormalReason::IgnoreDenormalMode:
21035 R <<
", and denormals may be flushed (!atomic.ignore.denormal.mode)";
21037 case AtomicFlushDenormalReason::FunctionFlushesDenormals:
21038 R <<
", and the floating-point environment flushes denormals";
21040 case AtomicFlushDenormalReason::IEEE:
21049 Type *EltTy = VT->getElementType();
21050 return VT->getNumElements() == 2 &&
21070 unsigned BW =
IT->getBitWidth();
21071 return BW == 32 || BW == 64;
21085 unsigned BW =
DL.getPointerSizeInBits(PT->getAddressSpace());
21086 return BW == 32 || BW == 64;
21089 if (Ty->isFloatTy() || Ty->isDoubleTy())
21093 return VT->getNumElements() == 2 &&
21094 VT->getElementType()->getPrimitiveSizeInBits() == 16;
21102static GlobalFPAtomicLegality
21111 if (HasSystemScope) {
21112 if (
Subtarget.hasAgentScopeFineGrainedRemoteMemoryAtomics() &&
21114 return GlobalFPAtomicLegality::NoRemoteMemory;
21115 if (
Subtarget.hasEmulatedSystemScopeAtomics())
21116 return GlobalFPAtomicLegality::EmulatedSystemScope;
21117 }
else if (
Subtarget.hasAgentScopeFineGrainedRemoteMemoryAtomics())
21118 return GlobalFPAtomicLegality::AgentScopeFineGrainedRemoteMemory;
21120 return RMW->
hasMetadata(
"amdgpu.no.fine.grained.memory")
21121 ? GlobalFPAtomicLegality::NoFineGrainedMemory
21122 : GlobalFPAtomicLegality::Illegal;
21135 const MDNode *MD =
I->getMetadata(LLVMContext::MD_noalias_addrspace);
21143 return STI.hasGloballyAddressableScratch()
21166 DL.getTypeSizeInBits(RMW->
getType()) == 64 &&
21170 GlobalFPAtomicLegality MemLegality = GlobalFPAtomicLegality::Illegal;
21171 AtomicFlushDenormalReason DenormReason = AtomicFlushDenormalReason::Native;
21181 bool HasSystemScope =
21213 if (!Subtarget->hasSubClampInsts() ||
21215 !Subtarget->hasAtomicDsCondSubClampInsts()) ||
21217 !Subtarget->hasAtomicCondSubClampFlatInsts()))
21222 if (!
IT ||
IT->getBitWidth() != 32)
21228 if (Subtarget->hasEmulatedSystemScopeAtomics())
21244 if (!HasSystemScope &&
21245 Subtarget->hasAgentScopeFineGrainedRemoteMemoryAtomics())
21257 if (RMW->
hasMetadata(
"amdgpu.no.fine.grained.memory"))
21266 ConstVal && ConstVal->isNullValue() &&
21305 if (Ty->isFloatTy()) {
21310 if (Ty->isDoubleTy()) {
21331 if (Ty->isFloatTy() &&
21332 !Subtarget->hasMemoryAtomicFaddF32DenormalSupport()) {
21334 if (DenormReason == AtomicFlushDenormalReason::IEEE)
21340 if (MemLegality != GlobalFPAtomicLegality::Illegal) {
21347 if (Subtarget->hasAtomicBufferGlobalPkAddF16Insts() &&
isV2F16(Ty))
21351 if (Subtarget->hasAtomicGlobalPkAddBF16Inst() &&
isV2BF16(Ty))
21355 if (Subtarget->hasAtomicBufferGlobalPkAddF16Insts() &&
isV2F16(Ty))
21360 if (Subtarget->hasAtomicBufferPkAddBF16Inst() &&
isV2BF16(Ty))
21365 if (Subtarget->hasFlatBufferGlobalAtomicFaddF64Inst() && Ty->isDoubleTy())
21369 if (Ty->isFloatTy()) {
21372 if (RMW->
use_empty() && Subtarget->hasAtomicFaddNoRtnInsts())
21375 if (!RMW->
use_empty() && Subtarget->hasAtomicFaddRtnInsts())
21380 Subtarget->hasAtomicBufferGlobalPkAddF16NoRtnInsts() &&
21388 if (Subtarget->hasFlatAtomicFaddF32Inst())
21397 if (Subtarget->hasLDSFPAtomicAddF32()) {
21398 if (RMW->
use_empty() && Subtarget->hasAtomicFaddNoRtnInsts())
21400 if (!RMW->
use_empty() && Subtarget->hasAtomicFaddRtnInsts())
21420 if (MemLegality != GlobalFPAtomicLegality::Illegal) {
21430 if (Subtarget->hasAtomicFMinFMaxF32FlatInsts() && Ty->isFloatTy())
21432 if (Subtarget->hasAtomicFMinFMaxF64FlatInsts() && Ty->isDoubleTy())
21436 if (Subtarget->hasAtomicFMinFMaxF32GlobalInsts() && Ty->isFloatTy())
21438 if (Subtarget->hasAtomicFMinFMaxF64GlobalInsts() && Ty->isDoubleTy())
21499 if (RC == &AMDGPU::VReg_1RegClass && !isDivergent)
21500 return Subtarget->isWave64() ? &AMDGPU::SReg_64RegClass
21501 : &AMDGPU::SReg_32RegClass;
21502 if (!
TRI->isSGPRClass(RC) && !isDivergent)
21503 return TRI->getEquivalentSGPRClass(RC);
21504 if (
TRI->isSGPRClass(RC) && isDivergent) {
21505 if (Subtarget->hasGFX90AInsts())
21506 return TRI->getEquivalentAVClass(RC);
21507 return TRI->getEquivalentVGPRClass(RC);
21520 unsigned WaveSize) {
21525 if (!
IT ||
IT->getBitWidth() != WaveSize)
21530 if (!Visited.
insert(
V).second)
21532 bool Result =
false;
21533 for (
const auto *U :
V->users()) {
21535 if (
V == U->getOperand(1)) {
21540 case Intrinsic::amdgcn_if_break:
21541 case Intrinsic::amdgcn_if:
21542 case Intrinsic::amdgcn_else:
21547 if (
V == U->getOperand(0)) {
21552 case Intrinsic::amdgcn_end_cf:
21553 case Intrinsic::amdgcn_loop:
21559 Result =
hasCFUser(U, Visited, WaveSize);
21568 const Value *V)
const {
21570 if (CI->isInlineAsm()) {
21579 for (
auto &TC : TargetConstraints) {
21593 return hasCFUser(V, Visited, Subtarget->getWavefrontSize());
21621 return MRI.hasOneNonDBGUse(N0);
21628 if (
I.getMetadata(
"amdgpu.noclobber"))
21630 if (
I.getMetadata(
"amdgpu.last.use"))
21632 if (
MDNode *
N =
I.getMetadata(
"amdgpu.cfs")) {
21637 "MOCFSB0 and MOCFSB1 are not adjacent bits");
21702 Alignment = RMW->getAlign();
21715 bool FullFlatEmulation =
21717 ((Subtarget->hasAtomicFaddInsts() && RMW->getType()->isFloatTy()) ||
21718 (Subtarget->hasFlatBufferGlobalAtomicFaddF64Inst() &&
21719 RMW->getType()->isDoubleTy()));
21722 bool ReturnValueIsUsed = !AI->
use_empty();
21731 if (FullFlatEmulation) {
21742 std::prev(BB->
end())->eraseFromParent();
21743 Builder.SetInsertPoint(BB);
21745 Value *LoadedShared =
nullptr;
21746 if (FullFlatEmulation) {
21747 Value *IsShared = Builder.CreateIntrinsic(Intrinsic::amdgcn_is_shared,
21748 {Addr},
nullptr,
"is.shared");
21749 Builder.CreateCondBr(IsShared, SharedBB, CheckPrivateBB);
21750 Builder.SetInsertPoint(SharedBB);
21751 Value *CastToLocal = Builder.CreateAddrSpaceCast(
21757 LoadedShared = Clone;
21759 Builder.CreateBr(PhiBB);
21760 Builder.SetInsertPoint(CheckPrivateBB);
21763 Value *IsPrivate = Builder.CreateIntrinsic(Intrinsic::amdgcn_is_private,
21764 {Addr},
nullptr,
"is.private");
21765 Builder.CreateCondBr(IsPrivate, PrivateBB, GlobalBB);
21767 Builder.SetInsertPoint(PrivateBB);
21769 Value *CastToPrivate = Builder.CreateAddrSpaceCast(
21772 Value *LoadedPrivate;
21774 LoadedPrivate = Builder.CreateAlignedLoad(
21775 RMW->getType(), CastToPrivate, RMW->getAlign(), RMW->isVolatile(),
21779 LoadedPrivate, RMW->getValOperand());
21781 Builder.CreateAlignedStore(NewVal, CastToPrivate, RMW->getAlign(),
21782 RMW->isVolatile());
21790 LoadedPrivate = Builder.CreateInsertValue(Insert, Equal, 1);
21793 Builder.CreateBr(PhiBB);
21795 Builder.SetInsertPoint(GlobalBB);
21799 if (FullFlatEmulation) {
21800 Value *CastToGlobal = Builder.CreateAddrSpaceCast(
21809 if (!FullFlatEmulation) {
21814 MDNode *RangeNotPrivate =
21817 LoadedGlobal->
setMetadata(LLVMContext::MD_noalias_addrspace,
21821 Builder.CreateBr(PhiBB);
21823 Builder.SetInsertPoint(PhiBB);
21825 if (ReturnValueIsUsed) {
21828 if (FullFlatEmulation)
21829 Loaded->addIncoming(LoadedShared, SharedBB);
21830 Loaded->addIncoming(LoadedPrivate, PrivateBB);
21831 Loaded->addIncoming(LoadedGlobal, GlobalBB);
21832 Loaded->takeName(AI);
21835 Builder.CreateBr(ExitBB);
21839 unsigned PtrOpIdx) {
21840 Value *PtrOp =
I->getOperand(PtrOpIdx);
21847 I->setOperand(PtrOpIdx, ASCast);
21859 ConstVal && ConstVal->isNullValue() &&
21890 "Expand Atomic Load only handles SCRATCH -> FLAT conversion");
21898 "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
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
Function Alias Analysis Results
static 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[]
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
MachineBasicBlock * Folded
SmallVector< MachineOperand, 4 > Cond
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 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 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 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 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)
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
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.
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. Should be passed by value.
LLVM_ABI MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
const MDOperand & getOperand(unsigned I) const
Helper class for constructing bundles of MachineInstrs.
MachineBasicBlock::instr_iterator begin() const
Return an iterator to the first bundled instruction.
uint64_t getScalarSizeInBits() const
bool bitsLE(MVT VT) const
Return true if this has no more bits than VT.
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool isScalableVector() const
Return true if this is a vector value type where the runtime length is machine dependent.
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.
AtomicExpansionKind shouldExpandAtomicStoreInIR(StoreInst *SI) const override
Returns how the given (atomic) store should be expanded by the IR-level AtomicExpand pass into.
void bundleInstWithWaitcnt(MachineInstr &MI) const
Insert MI into a BUNDLE with an S_WAITCNT 0 immediately following it.
SDValue lowerROTR(SDValue Op, SelectionDAG &DAG) const
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
Return the type to use for a scalar shift opcode, given the shifted amount type.
SDValue LowerCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
MVT getPointerTy(const DataLayout &DL, unsigned AS) const override
Map address space 7 to MVT::amdgpuBufferFatPointer because that's its in-memory representation.
bool denormalsEnabledForType(const SelectionDAG &DAG, EVT VT) const
void insertCopiesSplitCSR(MachineBasicBlock *Entry, const SmallVectorImpl< MachineBasicBlock * > &Exits) const override
Insert explicit copies in entry and exit blocks.
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the ValueType of the result of SETCC operations.
SDNode * legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const
Legalize target independent instructions (e.g.
bool allowsMisalignedMemoryAccessesImpl(unsigned Size, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *IsFast=nullptr) const
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
SDValue lowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const
const GCNSubtarget * getSubtarget() const
bool enableAggressiveFMAFusion(EVT VT) const override
Return true if target always benefits from combining into FMA for a given value type.
bool shouldEmitGOTReloc(const GlobalValue *GV) const
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.
AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override
Returns how the given (atomic) load should be expanded by the IR-level AtomicExpand pass.
Align computeKnownAlignForTargetInstr(GISelValueTracking &Analysis, Register R, const MachineRegisterInfo &MRI, unsigned Depth=0) const override
Determine the known alignment for the pointer value R.
bool getAsmOperandConstVal(SDValue Op, uint64_t &Val) const
bool isShuffleMaskLegal(ArrayRef< int >, EVT) const override
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations,...
void emitExpandAtomicLoad(LoadInst *LI) const override
Perform a atomic load using a target-specific way.
EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op, const AttributeList &FuncAttributes) const override
Returns the target specific optimal type for load and store operations as a result of memset,...
void 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.
void passSpecialInputs(CallLoweringInfo &CLI, CCState &CCInfo, const SIMachineFunctionInfo &Info, SmallVectorImpl< std::pair< unsigned, SDValue > > &RegsToPass, SmallVectorImpl< SDValue > &MemOpChains, SDValue Chain) const
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
bool checkAsmConstraintVal(SDValue Op, StringRef Constraint, uint64_t Val) const
bool isKnownNeverNaNForTargetNode(SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, bool SNaN=false, unsigned Depth=0) const override
If SNaN is false,.
void emitExpandAtomicRMW(AtomicRMWInst *AI) const override
Perform a atomicrmw expansion using a target-specific way.
static bool shouldExpandVectorDynExt(unsigned EltSize, unsigned NumElem, bool IsDivergentIdx, const GCNSubtarget *Subtarget)
Check if EXTRACT_VECTOR_ELT/INSERT_VECTOR_ELT (<n x e>, var-idx) should be expanded into a set of cmp...
bool shouldUseLDSConstAddress(const GlobalValue *GV) const
bool supportSplitCSR(MachineFunction *MF) const override
Return true if the target supports that a subset of CSRs for the given machine function is handled ex...
bool isExtractVecEltCheap(EVT VT, unsigned Index) const override
Return true if extraction of a scalar element from the given vector type at the given index is cheap.
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
bool allowsMisalignedMemoryAccesses(LLT Ty, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *IsFast=nullptr) const override
LLT handling variant.
bool 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.
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