[llvm] [AMDGPU][NFC] Add SingleSGPRReadFromTuple feature and rename related functions (PR #211933)
Changpeng Fang via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 24 19:29:46 PDT 2026
https://github.com/changpeng updated https://github.com/llvm/llvm-project/pull/211933
>From 4666017f0eb293a25b0d044eec173f91092f11a2 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <changpeng.fang at amd.com>
Date: Fri, 24 Jul 2026 14:43:09 -0700
Subject: [PATCH 1/7] [AMDGPU][NFC] Add SingleSGPRReadFromTuple feature and
rename related functions
Refactors 64-bit and wider packed instruction handling by introducing
the SingleSGPRReadFromTuple subtarget feature and renaming related helper
functions. This replaces GFX12+-specific checks with a feature flag that
more accurately captures the hardware behavior where a single SGPR is read
from a tuple.
Changes:
- Renames isPackedFP32or64BitInst to isWidePackedInst for clarity
- Renames isLegalGFX12PlusPackedMathFP32or64BitOperand to
isLegalWidePackedInstOperand to reflect the generalized functionality
- Adds SingleSGPRReadFromTuple subtarget feature
- Enables the feature for ISA versions 12, 12.50, and 13
- Updates verification and legalization logic to use the feature flag
instead of hardcoded GFX12+ checks
---
llvm/lib/Target/AMDGPU/AMDGPU.td | 10 +++++-
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 33 +++++++++----------
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 2 +-
.../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp | 3 +-
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 2 +-
5 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index bdc9acaa2f6bb..6bee942866443 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -1160,6 +1160,11 @@ defm WMMACoexecutionHazards : AMDGPUSubtargetFeature<"wmma-coexecution-hazards",
/*GenPredicate=*/0
>;
+defm SingleSGPRReadFromTuple : AMDGPUSubtargetFeature<"single-sgpr-read-from-tuple",
+ "Read a single sgpr from a tuple for wide packed instructions",
+ /*GenPredicate=*/0
+>;
+
defm SALUFloatInsts : AMDGPUSubtargetFeature<"salu-float",
"Has SALU floating point instructions"
>;
@@ -2184,7 +2189,8 @@ def FeatureISAVersion12 : FeatureSet<
FeatureRealTrue16Insts,
FeatureMTBUFInsts,
FeatureFormattedMUBUFInsts,
- FeatureDataCacheLineSize128
+ FeatureDataCacheLineSize128,
+ FeatureSingleSGPRReadFromTuple
]>;
def FeatureISAVersion12_50_Common : FeatureSet<
@@ -2272,6 +2278,7 @@ def FeatureISAVersion12_50_Common : FeatureSet<
FeatureRealTrue16Insts,
FeatureVMovB64Inst,
FeatureVMulU64Inst,
+ FeatureSingleSGPRReadFromTuple
]>;
def FeatureISAVersion12_50 : FeatureSet<
@@ -2408,6 +2415,7 @@ def FeatureISAVersion13 : FeatureSet<
FeatureCvtPkNormVOP3Insts,
FeatureSmemPrefetchInsts,
FeatureAsyncLoadToLDSInsts,
+ FeatureSingleSGPRReadFromTuple
]>;
def FeatureISAVersion13_Generic: FeatureSet<
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 28914d598a72d..24884c3a4216b 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -5939,11 +5939,10 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
}
}
- // See SIInstrInfo::isLegalGFX12PlusPackedMathFP32or64BitOperand for more
- // information.
- if (AMDGPU::isPackedFP32or64BitInst(Opcode) && AMDGPU::isGFX12Plus(ST)) {
+ // See SIInstrInfo::isLegalWidePackedInstOperand for more information.
+ if (ST.hasSingleSGPRReadFromTuple() && AMDGPU::isWidePackedInst(Opcode)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalGFX12PlusPackedMathFP32or64BitOperand(MRI, MI, I))
+ if (!isLegalWidePackedInstOperand(MRI, MI, I))
return false;
}
}
@@ -6301,8 +6300,7 @@ void SIInstrInfo::legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const {
DebugLoc DL = MBB->findDebugLoc(I);
if (Size == 128 && AMDGPU::isPacked64BitInst(MI.getOpcode()) &&
- isLegalGFX12PlusPackedMathFP32or64BitOperand(
- MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
+ isLegalWidePackedInstOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
// Special case for V_PK_*64 instructions: these do not have OPSEL but SGPR
// sources behave like OPSEL is set replicating low 64-bits into high. VGPR
// sources in turn read actual 4 registers. To move operand from an SGPR to
@@ -6404,12 +6402,11 @@ bool SIInstrInfo::isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
const MCOperandInfo OpInfo = MI.getDesc().operands()[OpIdx];
unsigned Opc = MI.getOpcode();
- // See SIInstrInfo::isLegalGFX12PlusPackedMathFP32or64BitOperand for more
- // information.
- if (AMDGPU::isPackedFP32or64BitInst(MI.getOpcode()) &&
- AMDGPU::isGFX12Plus(ST) && MO.isReg() && RI.isSGPRReg(MRI, MO.getReg()) &&
- !isLegalGFX12PlusPackedMathFP32or64BitOperand(
- MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
+ // See SIInstrInfo::isLegalWidePackdInstOperand for more information.
+ if (ST.hasSingleSGPRReadFromTuple() && MO.isReg() &&
+ RI.isSGPRReg(MRI, MO.getReg()) &&
+ AMDGPU::isWidePackedInst(MI.getOpcode()) &&
+ !isLegalWidePackedInstOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
return false;
if (!isLegalRegOperand(MRI, OpInfo, MO))
@@ -6475,7 +6472,7 @@ bool SIInstrInfo::isLegalVSrcOperand(const MachineRegisterInfo &MRI,
return true;
}
-bool SIInstrInfo::isLegalGFX12PlusPackedMathFP32or64BitOperand(
+bool SIInstrInfo::isLegalWidePackedInstOperand(
const MachineRegisterInfo &MRI, const MachineInstr &MI, unsigned SrcN,
const MachineOperand *MO) const {
constexpr unsigned NumOps = 3;
@@ -6896,12 +6893,12 @@ void SIInstrInfo::legalizeOperandsVOP3(MachineRegisterInfo &MRI,
!RI.isVGPR(MRI, MI.getOperand(VOP3Idx[2]).getReg()))
legalizeOpWithMove(MI, VOP3Idx[2]);
- // Fix the register class of packed FP32 instructions on gfx12+. See
- // SIInstrInfo::isLegalGFX12PlusPackedMathFP32or64BitOperand for more
- // information.
- if (AMDGPU::isPackedFP32or64BitInst(Opc) && AMDGPU::isGFX12Plus(ST)) {
+ // Fix the register class of 64-bit or wider packed instructions on target
+ // that reads a sigle sgpr from a tuple.
+ // Ser SIInstrInfo::isLegalWidePackedInstOperand for more information.
+ if (ST.hasSingleSGPRReadFromTuple() && AMDGPU::isWidePackedInst(Opc)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalGFX12PlusPackedMathFP32or64BitOperand(MRI, MI, /*SrcN=*/I))
+ if (!isLegalWidePackedInstOperand(MRI, MI, /*SrcN=*/I))
legalizeOpWithMove(MI, VOP3Idx[I]);
}
}
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 8e15b7b45b609..02a0db6a9810f 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1490,7 +1490,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
/// \p SrcN can be 0, 1, or 2, representing src0, src1, and src2,
/// respectively. If \p MO is nullptr, the operand corresponding to SrcN will
/// be used.
- bool isLegalGFX12PlusPackedMathFP32or64BitOperand(
+ bool isLegalWidePackedInstOperand(
const MachineRegisterInfo &MRI, const MachineInstr &MI, unsigned SrcN,
const MachineOperand *MO = nullptr) const;
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 6c847107db593..16307a613aad0 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -3766,7 +3766,8 @@ bool isPacked64BitInst(unsigned Opc) {
}
}
-bool isPackedFP32or64BitInst(unsigned Opc) {
+// Wide means operand size is equal to or larger than 64-bit
+bool isWidePackedInst(unsigned Opc) {
return isPackedFP32Inst(Opc) || isPacked64BitInst(Opc);
}
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
index 9dcd1ed9d1441..d12e46e55cfda 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
@@ -1695,7 +1695,7 @@ LLVM_READONLY bool isPackedFP32Inst(unsigned Opc);
LLVM_READONLY bool isPacked64BitInst(unsigned Opc);
-LLVM_READONLY bool isPackedFP32or64BitInst(unsigned Opc);
+LLVM_READONLY bool isWidePackedInst(unsigned Opc);
LLVM_READONLY
bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST,
>From 3fa86c341943e46f05f0bcc6008b7e3a17f44f44 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <changpeng.fang at amd.com>
Date: Fri, 24 Jul 2026 15:03:34 -0700
Subject: [PATCH 2/7] [AMDGPU] Fix clang-format
---
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 02a0db6a9810f..8567f9c5c00cc 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1490,9 +1490,9 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
/// \p SrcN can be 0, 1, or 2, representing src0, src1, and src2,
/// respectively. If \p MO is nullptr, the operand corresponding to SrcN will
/// be used.
- bool isLegalWidePackedInstOperand(
- const MachineRegisterInfo &MRI, const MachineInstr &MI, unsigned SrcN,
- const MachineOperand *MO = nullptr) const;
+ bool isLegalWidePackedInstOperand(const MachineRegisterInfo &MRI,
+ const MachineInstr &MI, unsigned SrcN,
+ const MachineOperand *MO = nullptr) const;
/// Legalize operands in \p MI by either commuting it or inserting a
/// copy of src1.
>From a40a88317af822b83dd52b66a8717a2a220b8c90 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <changpeng.fang at amd.com>
Date: Fri, 24 Jul 2026 15:09:47 -0700
Subject: [PATCH 3/7] [AMDGPU] Fix a comment related to function name
---
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 24884c3a4216b..30ddd7205882b 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -6307,9 +6307,8 @@ void SIInstrInfo::legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const {
// a VGPR we need to replicate low half.
// We also do not select immediates for these instructions so it always has
// to be an SGPR register here.
- // Operands which are not legal as per
- // isLegalGFX12PlusPackedMathFP32or64BitOperand() sent here specifically to
- // fix a non-splat SGPR and shall perform a full copy.
+ // Operands which are not legal as per isLegalWidePackedInstOperand() sent
+ // here specifically to fix a non-splat SGPR and shall perform a full copy.
const TargetRegisterClass *VRC64 = RI.getVGPRClassForBitWidth(64);
Register Low64 = MRI.createVirtualRegister(VRC64);
>From 4671ae7fbfa3c04efefdd281f86ede097f3fd504 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <changpeng.fang at amd.com>
Date: Fri, 24 Jul 2026 16:42:01 -0700
Subject: [PATCH 4/7] [AMDGPU] Remove the feature definition based on agreement
Will update commit message later.
---
llvm/lib/Target/AMDGPU/AMDGPU.td | 10 +-----
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 32 +++++++++----------
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 2 +-
.../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp | 3 +-
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 4 ++-
5 files changed, 22 insertions(+), 29 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index 6bee942866443..bdc9acaa2f6bb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -1160,11 +1160,6 @@ defm WMMACoexecutionHazards : AMDGPUSubtargetFeature<"wmma-coexecution-hazards",
/*GenPredicate=*/0
>;
-defm SingleSGPRReadFromTuple : AMDGPUSubtargetFeature<"single-sgpr-read-from-tuple",
- "Read a single sgpr from a tuple for wide packed instructions",
- /*GenPredicate=*/0
->;
-
defm SALUFloatInsts : AMDGPUSubtargetFeature<"salu-float",
"Has SALU floating point instructions"
>;
@@ -2189,8 +2184,7 @@ def FeatureISAVersion12 : FeatureSet<
FeatureRealTrue16Insts,
FeatureMTBUFInsts,
FeatureFormattedMUBUFInsts,
- FeatureDataCacheLineSize128,
- FeatureSingleSGPRReadFromTuple
+ FeatureDataCacheLineSize128
]>;
def FeatureISAVersion12_50_Common : FeatureSet<
@@ -2278,7 +2272,6 @@ def FeatureISAVersion12_50_Common : FeatureSet<
FeatureRealTrue16Insts,
FeatureVMovB64Inst,
FeatureVMulU64Inst,
- FeatureSingleSGPRReadFromTuple
]>;
def FeatureISAVersion12_50 : FeatureSet<
@@ -2415,7 +2408,6 @@ def FeatureISAVersion13 : FeatureSet<
FeatureCvtPkNormVOP3Insts,
FeatureSmemPrefetchInsts,
FeatureAsyncLoadToLDSInsts,
- FeatureSingleSGPRReadFromTuple
]>;
def FeatureISAVersion13_Generic: FeatureSet<
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 30ddd7205882b..07bb7b3d5a8b5 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -5939,10 +5939,10 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
}
}
- // See SIInstrInfo::isLegalWidePackedInstOperand for more information.
- if (ST.hasSingleSGPRReadFromTuple() && AMDGPU::isWidePackedInst(Opcode)) {
+ // See SIInstrInfo::isLegalSingleSGPRReadOperand for more information.
+ if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isSingleSGPRReadInst(Opcode)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalWidePackedInstOperand(MRI, MI, I))
+ if (!isLegalSingleSGPRReadOperand(MRI, MI, I))
return false;
}
}
@@ -6300,14 +6300,14 @@ void SIInstrInfo::legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const {
DebugLoc DL = MBB->findDebugLoc(I);
if (Size == 128 && AMDGPU::isPacked64BitInst(MI.getOpcode()) &&
- isLegalWidePackedInstOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
+ isLegalSingleSGPRReadOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
// Special case for V_PK_*64 instructions: these do not have OPSEL but SGPR
// sources behave like OPSEL is set replicating low 64-bits into high. VGPR
// sources in turn read actual 4 registers. To move operand from an SGPR to
// a VGPR we need to replicate low half.
// We also do not select immediates for these instructions so it always has
// to be an SGPR register here.
- // Operands which are not legal as per isLegalWidePackedInstOperand() sent
+ // Operands which are not legal as per isLegalSingleSGPRReadOperand() sent
// here specifically to fix a non-splat SGPR and shall perform a full copy.
const TargetRegisterClass *VRC64 = RI.getVGPRClassForBitWidth(64);
@@ -6401,11 +6401,10 @@ bool SIInstrInfo::isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
const MCOperandInfo OpInfo = MI.getDesc().operands()[OpIdx];
unsigned Opc = MI.getOpcode();
- // See SIInstrInfo::isLegalWidePackdInstOperand for more information.
- if (ST.hasSingleSGPRReadFromTuple() && MO.isReg() &&
- RI.isSGPRReg(MRI, MO.getReg()) &&
- AMDGPU::isWidePackedInst(MI.getOpcode()) &&
- !isLegalWidePackedInstOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
+ // See SIInstrInfo::isLegalSingleSGPRReadOperand for more information.
+ if (AMDGPU::isGFX12Plus(ST) && MO.isReg() && RI.isSGPRReg(MRI, MO.getReg()) &&
+ AMDGPU::isSingleSGPRReadInst(MI.getOpcode()) &&
+ !isLegalSingleSGPRReadOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
return false;
if (!isLegalRegOperand(MRI, OpInfo, MO))
@@ -6471,9 +6470,10 @@ bool SIInstrInfo::isLegalVSrcOperand(const MachineRegisterInfo &MRI,
return true;
}
-bool SIInstrInfo::isLegalWidePackedInstOperand(
- const MachineRegisterInfo &MRI, const MachineInstr &MI, unsigned SrcN,
- const MachineOperand *MO) const {
+bool SIInstrInfo::isLegalSingleSGPRReadOperand(const MachineRegisterInfo &MRI,
+ const MachineInstr &MI,
+ unsigned SrcN,
+ const MachineOperand *MO) const {
constexpr unsigned NumOps = 3;
constexpr AMDGPU::OpName OpNames[NumOps * 2] = {
AMDGPU::OpName::src0, AMDGPU::OpName::src1,
@@ -6894,10 +6894,10 @@ void SIInstrInfo::legalizeOperandsVOP3(MachineRegisterInfo &MRI,
// Fix the register class of 64-bit or wider packed instructions on target
// that reads a sigle sgpr from a tuple.
- // Ser SIInstrInfo::isLegalWidePackedInstOperand for more information.
- if (ST.hasSingleSGPRReadFromTuple() && AMDGPU::isWidePackedInst(Opc)) {
+ // Ser SIInstrInfo::isLegalSingleSGPRReadOperand for more information.
+ if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isSingleSGPRReadInst(Opc)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalWidePackedInstOperand(MRI, MI, /*SrcN=*/I))
+ if (!isLegalSingleSGPRReadOperand(MRI, MI, /*SrcN=*/I))
legalizeOpWithMove(MI, VOP3Idx[I]);
}
}
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 8567f9c5c00cc..11e648bd7717d 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1490,7 +1490,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
/// \p SrcN can be 0, 1, or 2, representing src0, src1, and src2,
/// respectively. If \p MO is nullptr, the operand corresponding to SrcN will
/// be used.
- bool isLegalWidePackedInstOperand(const MachineRegisterInfo &MRI,
+ bool isLegalSingleSGPRReadOperand(const MachineRegisterInfo &MRI,
const MachineInstr &MI, unsigned SrcN,
const MachineOperand *MO = nullptr) const;
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 16307a613aad0..25b36d99960a1 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -3766,8 +3766,7 @@ bool isPacked64BitInst(unsigned Opc) {
}
}
-// Wide means operand size is equal to or larger than 64-bit
-bool isWidePackedInst(unsigned Opc) {
+bool isSingleSGPRReadInst(unsigned Opc) {
return isPackedFP32Inst(Opc) || isPacked64BitInst(Opc);
}
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
index d12e46e55cfda..eeed59e514215 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
@@ -1695,7 +1695,9 @@ LLVM_READONLY bool isPackedFP32Inst(unsigned Opc);
LLVM_READONLY bool isPacked64BitInst(unsigned Opc);
-LLVM_READONLY bool isWidePackedInst(unsigned Opc);
+/// Packed instrucion that only a single SGPR is read when the operand
+/// is a SGPR tuple.
+LLVM_READONLY bool isSingleSGPRReadInst(unsigned Opc);
LLVM_READONLY
bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST,
>From 6b9c6f1894fc1b8f93b69d1c04a0e134cbf843ef Mon Sep 17 00:00:00 2001
From: Changpeng Fang <changpeng.fang at amd.com>
Date: Fri, 24 Jul 2026 17:09:56 -0700
Subject: [PATCH 5/7] [AMDGPU] Use isWidePackedInst instead of
isSingleSGPRReadInst
---
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 30 +++++++++----------
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 6 ++--
.../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp | 2 +-
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 5 ++--
4 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 07bb7b3d5a8b5..122b1445c156e 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -5939,10 +5939,10 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
}
}
- // See SIInstrInfo::isLegalSingleSGPRReadOperand for more information.
- if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isSingleSGPRReadInst(Opcode)) {
+ // See SIInstrInfo::isLegalWidePackedOperand for more information.
+ if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isWidePackedInst(Opcode)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalSingleSGPRReadOperand(MRI, MI, I))
+ if (!isLegalWidePackedOperand(MRI, MI, I))
return false;
}
}
@@ -6300,14 +6300,14 @@ void SIInstrInfo::legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const {
DebugLoc DL = MBB->findDebugLoc(I);
if (Size == 128 && AMDGPU::isPacked64BitInst(MI.getOpcode()) &&
- isLegalSingleSGPRReadOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
+ isLegalWidePackedOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
// Special case for V_PK_*64 instructions: these do not have OPSEL but SGPR
// sources behave like OPSEL is set replicating low 64-bits into high. VGPR
// sources in turn read actual 4 registers. To move operand from an SGPR to
// a VGPR we need to replicate low half.
// We also do not select immediates for these instructions so it always has
// to be an SGPR register here.
- // Operands which are not legal as per isLegalSingleSGPRReadOperand() sent
+ // Operands which are not legal as per isLegalWidePackedOperand() sent
// here specifically to fix a non-splat SGPR and shall perform a full copy.
const TargetRegisterClass *VRC64 = RI.getVGPRClassForBitWidth(64);
@@ -6401,10 +6401,10 @@ bool SIInstrInfo::isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
const MCOperandInfo OpInfo = MI.getDesc().operands()[OpIdx];
unsigned Opc = MI.getOpcode();
- // See SIInstrInfo::isLegalSingleSGPRReadOperand for more information.
+ // See SIInstrInfo::isLegalWidePackedOperand for more information.
if (AMDGPU::isGFX12Plus(ST) && MO.isReg() && RI.isSGPRReg(MRI, MO.getReg()) &&
- AMDGPU::isSingleSGPRReadInst(MI.getOpcode()) &&
- !isLegalSingleSGPRReadOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
+ AMDGPU::isWidePackedInst(MI.getOpcode()) &&
+ !isLegalWidePackedOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
return false;
if (!isLegalRegOperand(MRI, OpInfo, MO))
@@ -6470,10 +6470,10 @@ bool SIInstrInfo::isLegalVSrcOperand(const MachineRegisterInfo &MRI,
return true;
}
-bool SIInstrInfo::isLegalSingleSGPRReadOperand(const MachineRegisterInfo &MRI,
- const MachineInstr &MI,
- unsigned SrcN,
- const MachineOperand *MO) const {
+bool SIInstrInfo::isLegalWidePackedOperand(const MachineRegisterInfo &MRI,
+ const MachineInstr &MI,
+ unsigned SrcN,
+ const MachineOperand *MO) const {
constexpr unsigned NumOps = 3;
constexpr AMDGPU::OpName OpNames[NumOps * 2] = {
AMDGPU::OpName::src0, AMDGPU::OpName::src1,
@@ -6894,10 +6894,10 @@ void SIInstrInfo::legalizeOperandsVOP3(MachineRegisterInfo &MRI,
// Fix the register class of 64-bit or wider packed instructions on target
// that reads a sigle sgpr from a tuple.
- // Ser SIInstrInfo::isLegalSingleSGPRReadOperand for more information.
- if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isSingleSGPRReadInst(Opc)) {
+ // Ser SIInstrInfo::isLegalWidePackedOperand for more information.
+ if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isWidePackedInst(Opc)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalSingleSGPRReadOperand(MRI, MI, /*SrcN=*/I))
+ if (!isLegalWidePackedOperand(MRI, MI, /*SrcN=*/I))
legalizeOpWithMove(MI, VOP3Idx[I]);
}
}
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 11e648bd7717d..d88c33dc826a1 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1490,9 +1490,9 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
/// \p SrcN can be 0, 1, or 2, representing src0, src1, and src2,
/// respectively. If \p MO is nullptr, the operand corresponding to SrcN will
/// be used.
- bool isLegalSingleSGPRReadOperand(const MachineRegisterInfo &MRI,
- const MachineInstr &MI, unsigned SrcN,
- const MachineOperand *MO = nullptr) const;
+ bool isLegalWidePackedOperand(const MachineRegisterInfo &MRI,
+ const MachineInstr &MI, unsigned SrcN,
+ const MachineOperand *MO = nullptr) const;
/// Legalize operands in \p MI by either commuting it or inserting a
/// copy of src1.
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 25b36d99960a1..f0aa02e461205 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -3766,7 +3766,7 @@ bool isPacked64BitInst(unsigned Opc) {
}
}
-bool isSingleSGPRReadInst(unsigned Opc) {
+bool isWidePackedInst(unsigned Opc) {
return isPackedFP32Inst(Opc) || isPacked64BitInst(Opc);
}
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
index eeed59e514215..da4bca69d5d6f 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
@@ -1695,9 +1695,8 @@ LLVM_READONLY bool isPackedFP32Inst(unsigned Opc);
LLVM_READONLY bool isPacked64BitInst(unsigned Opc);
-/// Packed instrucion that only a single SGPR is read when the operand
-/// is a SGPR tuple.
-LLVM_READONLY bool isSingleSGPRReadInst(unsigned Opc);
+/// Packed instrucion with operand 64-bit or larger.
+LLVM_READONLY bool isWidePackedInst(unsigned Opc);
LLVM_READONLY
bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST,
>From 4d51cb08bfa9186e799ffd2a41a5145a9a68ddf2 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <changpeng.fang at amd.com>
Date: Fri, 24 Jul 2026 17:22:50 -0700
Subject: [PATCH 6/7] [AMDGPU] Rename isLegalWidePackedOperand to
isLegalGFX12PlusWidePackedOperand
---
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 24 ++++++++++++------------
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 6 +++---
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 122b1445c156e..e73e6a1af711b 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -5939,10 +5939,10 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
}
}
- // See SIInstrInfo::isLegalWidePackedOperand for more information.
+ // See SIInstrInfo::isLegalGFX12PlusWidePackedOperand for more information.
if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isWidePackedInst(Opcode)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalWidePackedOperand(MRI, MI, I))
+ if (!isLegalGFX12PlusWidePackedOperand(MRI, MI, I))
return false;
}
}
@@ -6300,14 +6300,14 @@ void SIInstrInfo::legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const {
DebugLoc DL = MBB->findDebugLoc(I);
if (Size == 128 && AMDGPU::isPacked64BitInst(MI.getOpcode()) &&
- isLegalWidePackedOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
+ isLegalGFX12PlusWidePackedOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx))) {
// Special case for V_PK_*64 instructions: these do not have OPSEL but SGPR
// sources behave like OPSEL is set replicating low 64-bits into high. VGPR
// sources in turn read actual 4 registers. To move operand from an SGPR to
// a VGPR we need to replicate low half.
// We also do not select immediates for these instructions so it always has
// to be an SGPR register here.
- // Operands which are not legal as per isLegalWidePackedOperand() sent
+ // Operands which are not legal as per isLegalGFX12PlusWidePackedOperand() sent
// here specifically to fix a non-splat SGPR and shall perform a full copy.
const TargetRegisterClass *VRC64 = RI.getVGPRClassForBitWidth(64);
@@ -6401,10 +6401,10 @@ bool SIInstrInfo::isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
const MCOperandInfo OpInfo = MI.getDesc().operands()[OpIdx];
unsigned Opc = MI.getOpcode();
- // See SIInstrInfo::isLegalWidePackedOperand for more information.
+ // See SIInstrInfo::isLegalGFX12PlusWidePackedOperand for more information.
if (AMDGPU::isGFX12Plus(ST) && MO.isReg() && RI.isSGPRReg(MRI, MO.getReg()) &&
AMDGPU::isWidePackedInst(MI.getOpcode()) &&
- !isLegalWidePackedOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
+ !isLegalGFX12PlusWidePackedOperand(MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
return false;
if (!isLegalRegOperand(MRI, OpInfo, MO))
@@ -6470,10 +6470,10 @@ bool SIInstrInfo::isLegalVSrcOperand(const MachineRegisterInfo &MRI,
return true;
}
-bool SIInstrInfo::isLegalWidePackedOperand(const MachineRegisterInfo &MRI,
- const MachineInstr &MI,
- unsigned SrcN,
- const MachineOperand *MO) const {
+bool SIInstrInfo::isLegalGFX12PlusWidePackedOperand(const MachineRegisterInfo &MRI,
+ const MachineInstr &MI,
+ unsigned SrcN,
+ const MachineOperand *MO) const {
constexpr unsigned NumOps = 3;
constexpr AMDGPU::OpName OpNames[NumOps * 2] = {
AMDGPU::OpName::src0, AMDGPU::OpName::src1,
@@ -6894,10 +6894,10 @@ void SIInstrInfo::legalizeOperandsVOP3(MachineRegisterInfo &MRI,
// Fix the register class of 64-bit or wider packed instructions on target
// that reads a sigle sgpr from a tuple.
- // Ser SIInstrInfo::isLegalWidePackedOperand for more information.
+ // Ser SIInstrInfo::isLegalGFX12PlusWidePackedOperand for more information.
if (AMDGPU::isGFX12Plus(ST) && AMDGPU::isWidePackedInst(Opc)) {
for (unsigned I = 0; I < 3; ++I) {
- if (!isLegalWidePackedOperand(MRI, MI, /*SrcN=*/I))
+ if (!isLegalGFX12PlusWidePackedOperand(MRI, MI, /*SrcN=*/I))
legalizeOpWithMove(MI, VOP3Idx[I]);
}
}
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index d88c33dc826a1..1a30df44820c2 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1490,9 +1490,9 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
/// \p SrcN can be 0, 1, or 2, representing src0, src1, and src2,
/// respectively. If \p MO is nullptr, the operand corresponding to SrcN will
/// be used.
- bool isLegalWidePackedOperand(const MachineRegisterInfo &MRI,
- const MachineInstr &MI, unsigned SrcN,
- const MachineOperand *MO = nullptr) const;
+ bool isLegalGFX12PlusWidePackedOperand(const MachineRegisterInfo &MRI,
+ const MachineInstr &MI, unsigned SrcN,
+ const MachineOperand *MO = nullptr) const;
/// Legalize operands in \p MI by either commuting it or inserting a
/// copy of src1.
>From 3f0049b8350f44b4e818de592d5991e10f1a7565 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <changpeng.fang at amd.com>
Date: Fri, 24 Jul 2026 19:29:09 -0700
Subject: [PATCH 7/7] [AMDGPU] clang-format again
---
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 1a30df44820c2..970afb41e095e 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1490,9 +1490,10 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
/// \p SrcN can be 0, 1, or 2, representing src0, src1, and src2,
/// respectively. If \p MO is nullptr, the operand corresponding to SrcN will
/// be used.
- bool isLegalGFX12PlusWidePackedOperand(const MachineRegisterInfo &MRI,
- const MachineInstr &MI, unsigned SrcN,
- const MachineOperand *MO = nullptr) const;
+ bool
+ isLegalGFX12PlusWidePackedOperand(const MachineRegisterInfo &MRI,
+ const MachineInstr &MI, unsigned SrcN,
+ const MachineOperand *MO = nullptr) const;
/// Legalize operands in \p MI by either commuting it or inserting a
/// copy of src1.
More information about the llvm-commits
mailing list