[llvm] 14371a7 - [AMDGPU] Simplify check for packed fp32/64 opsel bits. NFCI (#211374)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 23 01:08:38 PDT 2026
Author: Stanislav Mekhanoshin
Date: 2026-07-23T01:08:33-07:00
New Revision: 14371a71392de5c1426a5dd98a98deb2a5d26fbe
URL: https://github.com/llvm/llvm-project/commit/14371a71392de5c1426a5dd98a98deb2a5d26fbe
DIFF: https://github.com/llvm/llvm-project/commit/14371a71392de5c1426a5dd98a98deb2a5d26fbe.diff
LOG: [AMDGPU] Simplify check for packed fp32/64 opsel bits. NFCI (#211374)
Call isLegalGFX12PlusPackedMathFP32or64BitOperand directly instead
of the whole isLegalOperand.
Added:
Modified:
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 3ae46a0fe7bde..28914d598a72d 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -6266,6 +6266,20 @@ const TargetRegisterClass *SIInstrInfo::getOpRegClass(const MachineInstr &MI,
return RegClass < 0 ? nullptr : RI.getRegClass(RegClass);
}
+// Convert VOP3 operand index to source number.
+static unsigned VOP3OpIdxToSrcN(const MachineInstr &MI, unsigned OpIdx) {
+ constexpr AMDGPU::OpName OpNames[] = {
+ AMDGPU::OpName::src0, AMDGPU::OpName::src1, AMDGPU::OpName::src2};
+
+ for (auto [I, OpName] : enumerate(OpNames)) {
+ int SrcIdx = AMDGPU::getNamedOperandIdx(MI.getOpcode(), OpNames[I]);
+ if (static_cast<unsigned>(SrcIdx) == OpIdx)
+ return I;
+ }
+
+ return UINT_MAX;
+}
+
void SIInstrInfo::legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const {
MachineBasicBlock::iterator I = MI;
MachineBasicBlock *MBB = MI.getParent();
@@ -6287,15 +6301,17 @@ void SIInstrInfo::legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const {
DebugLoc DL = MBB->findDebugLoc(I);
if (Size == 128 && AMDGPU::isPacked64BitInst(MI.getOpcode()) &&
- isLegalRegOperand(MI, OpIdx, MO)) {
+ isLegalGFX12PlusPackedMathFP32or64BitOperand(
+ 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 isLegalRegOperand() sent here
- // specifically to fix a non-splat SGPR and shall perform a full copy.
+ // Operands which are not legal as per
+ // isLegalGFX12PlusPackedMathFP32or64BitOperand() 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);
@@ -6391,17 +6407,10 @@ bool SIInstrInfo::isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
// See SIInstrInfo::isLegalGFX12PlusPackedMathFP32or64BitOperand for more
// information.
if (AMDGPU::isPackedFP32or64BitInst(MI.getOpcode()) &&
- AMDGPU::isGFX12Plus(ST) && MO.isReg() && RI.isSGPRReg(MRI, MO.getReg())) {
- constexpr AMDGPU::OpName OpNames[] = {
- AMDGPU::OpName::src0, AMDGPU::OpName::src1, AMDGPU::OpName::src2};
-
- for (auto [I, OpName] : enumerate(OpNames)) {
- int SrcIdx = AMDGPU::getNamedOperandIdx(MI.getOpcode(), OpNames[I]);
- if (static_cast<unsigned>(SrcIdx) == OpIdx &&
- !isLegalGFX12PlusPackedMathFP32or64BitOperand(MRI, MI, I, &MO))
- return false;
- }
- }
+ AMDGPU::isGFX12Plus(ST) && MO.isReg() && RI.isSGPRReg(MRI, MO.getReg()) &&
+ !isLegalGFX12PlusPackedMathFP32or64BitOperand(
+ MRI, MI, VOP3OpIdxToSrcN(MI, OpIdx), &MO))
+ return false;
if (!isLegalRegOperand(MRI, OpInfo, MO))
return false;
More information about the llvm-commits
mailing list