[llvm-branch-commits] [llvm] AMDGPU: Add version of isImmOperandLegal for MCInstrDesc (PR #155560)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 26 23:20:29 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
This avoids the need for a pre-constructed instruction, at least
for the first argument.
---
Full diff: https://github.com/llvm/llvm-project/pull/155560.diff
2 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/SIInstrInfo.cpp (+5-6)
- (modified) llvm/lib/Target/AMDGPU/SIInstrInfo.h (+16-11)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index e62a69a4146a7..ac60dc19aa974 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -4572,9 +4572,8 @@ static bool compareMachineOp(const MachineOperand &Op0,
}
}
-bool SIInstrInfo::isImmOperandLegal(const MachineInstr &MI, unsigned OpNo,
+bool SIInstrInfo::isImmOperandLegal(const MCInstrDesc &InstDesc, unsigned OpNo,
const MachineOperand &MO) const {
- const MCInstrDesc &InstDesc = MI.getDesc();
const MCOperandInfo &OpInfo = InstDesc.operands()[OpNo];
assert(MO.isImm() || MO.isTargetIndex() || MO.isFI() || MO.isGlobal());
@@ -4586,9 +4585,9 @@ bool SIInstrInfo::isImmOperandLegal(const MachineInstr &MI, unsigned OpNo,
return false;
if (MO.isImm() && isInlineConstant(MO, OpInfo)) {
- if (isMAI(MI) && ST.hasMFMAInlineLiteralBug() &&
- OpNo ==(unsigned)AMDGPU::getNamedOperandIdx(MI.getOpcode(),
- AMDGPU::OpName::src2))
+ if (isMAI(InstDesc) && ST.hasMFMAInlineLiteralBug() &&
+ OpNo == (unsigned)AMDGPU::getNamedOperandIdx(InstDesc.getOpcode(),
+ AMDGPU::OpName::src2))
return false;
return RI.opCanUseInlineConstant(OpInfo.OperandType);
}
@@ -4596,7 +4595,7 @@ bool SIInstrInfo::isImmOperandLegal(const MachineInstr &MI, unsigned OpNo,
if (!RI.opCanUseLiteralConstant(OpInfo.OperandType))
return false;
- if (!isVOP3(MI) || !AMDGPU::isSISrcOperand(InstDesc, OpNo))
+ if (!isVOP3(InstDesc) || !AMDGPU::isSISrcOperand(InstDesc, OpNo))
return true;
return ST.hasVOP3Literal();
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index fdbd9ce4a66bf..7552ead12570f 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -533,13 +533,13 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
return get(Opcode).TSFlags & SIInstrFlags::VOP2;
}
- static bool isVOP3(const MachineInstr &MI) {
- return MI.getDesc().TSFlags & SIInstrFlags::VOP3;
+ static bool isVOP3(const MCInstrDesc &Desc) {
+ return Desc.TSFlags & SIInstrFlags::VOP3;
}
- bool isVOP3(uint16_t Opcode) const {
- return get(Opcode).TSFlags & SIInstrFlags::VOP3;
- }
+ static bool isVOP3(const MachineInstr &MI) { return isVOP3(MI.getDesc()); }
+
+ bool isVOP3(uint16_t Opcode) const { return isVOP3(get(Opcode)); }
static bool isSDWA(const MachineInstr &MI) {
return MI.getDesc().TSFlags & SIInstrFlags::SDWA;
@@ -841,13 +841,13 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
return get(Opcode).TSFlags & SIInstrFlags::VINTRP;
}
- static bool isMAI(const MachineInstr &MI) {
- return MI.getDesc().TSFlags & SIInstrFlags::IsMAI;
+ static bool isMAI(const MCInstrDesc &Desc) {
+ return Desc.TSFlags & SIInstrFlags::IsMAI;
}
- bool isMAI(uint16_t Opcode) const {
- return get(Opcode).TSFlags & SIInstrFlags::IsMAI;
- }
+ static bool isMAI(const MachineInstr &MI) { return isMAI(MI.getDesc()); }
+
+ bool isMAI(uint16_t Opcode) const { return isMAI(get(Opcode)); }
static bool isMFMA(const MachineInstr &MI) {
return isMAI(MI) && MI.getOpcode() != AMDGPU::V_ACCVGPR_WRITE_B32_e64 &&
@@ -1174,9 +1174,14 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
return isInlineConstant(*MO.getParent(), MO.getOperandNo());
}
- bool isImmOperandLegal(const MachineInstr &MI, unsigned OpNo,
+ bool isImmOperandLegal(const MCInstrDesc &InstDesc, unsigned OpNo,
const MachineOperand &MO) const;
+ bool isImmOperandLegal(const MachineInstr &MI, unsigned OpNo,
+ const MachineOperand &MO) const {
+ return isImmOperandLegal(MI.getDesc(), OpNo, MO);
+ }
+
/// Check if this immediate value can be used for AV_MOV_B64_IMM_PSEUDO.
bool isLegalAV64PseudoImm(uint64_t Imm) const;
``````````
</details>
https://github.com/llvm/llvm-project/pull/155560
More information about the llvm-branch-commits
mailing list