[llvm] AMDGPU: Use mi_match for selector vector-source instruction lookups (PR #216792)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 10:50:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Co-authored-by: Claude (Opus 4.8) <noreply@<!-- -->anthropic.com>
---
Full diff: https://github.com/llvm/llvm-project/pull/216792.diff
1 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp (+11-8)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
index 0a5dbca02fea2..1695b2a8d86c2 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
@@ -2920,7 +2920,8 @@ static bool isExtractHiElt(MachineRegisterInfo &MRI, Register In,
// use an extract hi instruction for the upper 16 bits. We only need to check
// the size of `In` as all defs are guaranteed to be the same type for
// GUnmerge.
- if (auto *Unmerge = dyn_cast<GUnmerge>(MRI.getVRegDef(In))) {
+ GUnmerge *Unmerge;
+ if (mi_match(In, MRI, m_GUnmerge(Unmerge))) {
if (Unmerge->getNumDefs() == 2 && Unmerge->getOperand(1).getReg() == In &&
MRI.getType(In).getSizeInBits() == 16) {
Out = Unmerge->getSourceReg();
@@ -5370,10 +5371,9 @@ std::pair<Register, unsigned> AMDGPUInstructionSelector::selectVOP3PModsImpl(
return {Stat.first, Mods};
}
- MachineInstr *MI = MRI.getVRegDef(Stat.first);
-
- if (MI->getOpcode() != AMDGPU::G_BUILD_VECTOR || MI->getNumOperands() != 3 ||
- (IsDOT && Subtarget->hasDOTOpSelHazard())) {
+ GBuildVector *MI;
+ if (!mi_match(Stat.first, MRI, m_GBuildVector(MI)) ||
+ MI->getNumOperands() != 3 || (IsDOT && Subtarget->hasDOTOpSelHazard())) {
Mods |= SISrcMods::OP_SEL_1;
return {Stat.first, Mods};
}
@@ -5594,7 +5594,8 @@ AMDGPUInstructionSelector::selectWMMAModsF32NegAbs(MachineOperand &Root) const {
unsigned Mods = SISrcMods::OP_SEL_1;
SmallVector<Register, 8> EltsF32;
- if (GBuildVector *BV = dyn_cast<GBuildVector>(MRI->getVRegDef(Src))) {
+ GBuildVector *BV;
+ if (mi_match(Src, *MRI, m_GBuildVector(BV))) {
assert(BV->getNumSources() > 0);
// Based on first element decide which mod we match, neg or abs
MachineInstr *ElF32 = MRI->getVRegDef(BV->getSourceReg(0));
@@ -5625,7 +5626,8 @@ AMDGPUInstructionSelector::selectWMMAModsF16Neg(MachineOperand &Root) const {
unsigned Mods = SISrcMods::OP_SEL_1;
SmallVector<Register, 8> EltsV2F16;
- if (GConcatVectors *CV = dyn_cast<GConcatVectors>(MRI->getVRegDef(Src))) {
+ GConcatVectors *CV;
+ if (mi_match(Src, *MRI, m_GConcatVectors(CV))) {
for (unsigned i = 0; i < CV->getNumSources(); ++i) {
Register FNegSrc;
if (!mi_match(CV->getSourceReg(i), *MRI, m_GFNeg(m_Reg(FNegSrc))))
@@ -5651,7 +5653,8 @@ AMDGPUInstructionSelector::selectWMMAModsF16NegAbs(MachineOperand &Root) const {
unsigned Mods = SISrcMods::OP_SEL_1;
SmallVector<Register, 8> EltsV2F16;
- if (GConcatVectors *CV = dyn_cast<GConcatVectors>(MRI->getVRegDef(Src))) {
+ GConcatVectors *CV;
+ if (mi_match(Src, *MRI, m_GConcatVectors(CV))) {
assert(CV->getNumSources() > 0);
MachineInstr *ElV2F16 = MRI->getVRegDef(CV->getSourceReg(0));
// Based on first element decide which mod we match, neg or abs
``````````
</details>
https://github.com/llvm/llvm-project/pull/216792
More information about the llvm-commits
mailing list