-
Notifications
You must be signed in to change notification settings - Fork 15.2k
AMDGPU: Add version of isImmOperandLegal for MCInstrDesc #155560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arsenm
merged 4 commits into
main
from
users/arsenm/amdgpu/add-version-isImmOperandLegal-MCInstrDesc
Sep 2, 2025
Merged
AMDGPU: Add version of isImmOperandLegal for MCInstrDesc #155560
arsenm
merged 4 commits into
main
from
users/arsenm/amdgpu/add-version-isImmOperandLegal-MCInstrDesc
Sep 2, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
Member
|
@llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesThis avoids the need for a pre-constructed instruction, at least Full diff: https://github.com/llvm/llvm-project/pull/155560.diff 2 Files Affected:
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;
|
This was referenced Aug 27, 2025
shiltian
approved these changes
Aug 27, 2025
Contributor
shiltian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more like an NFCI.
Sisyph
approved these changes
Aug 27, 2025
Perform a register class constraint check when performing the fold
a96f1c9 to
f5a6c57
Compare
9dc68dd to
493b502
Compare
This avoids the need for a pre-constructed instruction, at least for the first argument.
493b502 to
f127217
Compare
Base automatically changed from
users/arsenm/amdgpu/stop-special-casing-aligned-vgpr-targets
to
main
September 2, 2025 16:15
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

This avoids the need for a pre-constructed instruction, at least
for the first argument.