[llvm-branch-commits] [llvm] GlobalISel: Use MIPatternMatch in GIMatchTableExecutor (PR #216601)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Aug 16 13:22:10 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Replace the getVRegDef + opcode-check idiom in isBaseWithConstantOffset with
mi_match using m_GPtrAdd and m_GConstant.
Co-authored-by: Claude (Opus 4.8) <noreply@<!-- -->anthropic.com>
---
Full diff: https://github.com/llvm/llvm-project/pull/216601.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp (+6-8)
``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp b/llvm/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
index 1edfc09310554..d06f64a72922a 100644
--- a/llvm/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h"
+#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
#include "llvm/CodeGen/GlobalISel/Utils.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineOperand.h"
@@ -20,6 +21,7 @@
#define DEBUG_TYPE "gi-match-table-executor"
using namespace llvm;
+using namespace MIPatternMatch;
GIMatchTableExecutor::MatcherState::MatcherState(unsigned MaxRenderers)
: Renderers(MaxRenderers) {}
@@ -47,16 +49,12 @@ bool GIMatchTableExecutor::isBaseWithConstantOffset(
if (!Root.isReg())
return false;
- MachineInstr *RootI = MRI.getVRegDef(Root.getReg());
- if (RootI->getOpcode() != TargetOpcode::G_PTR_ADD)
+ GPtrAdd *RootI;
+ if (!mi_match(Root.getReg(), MRI, m_GPtrAdd(RootI)))
return false;
- MachineOperand &RHS = RootI->getOperand(2);
- MachineInstr *RHSI = MRI.getVRegDef(RHS.getReg());
- if (RHSI->getOpcode() != TargetOpcode::G_CONSTANT)
- return false;
-
- return true;
+ GConstant *RHSI;
+ return mi_match(RootI->getOffsetReg(), MRI, m_GConstant(RHSI));
}
bool GIMatchTableExecutor::isObviouslySafeToFold(MachineInstr &MI,
``````````
</details>
https://github.com/llvm/llvm-project/pull/216601
More information about the llvm-branch-commits
mailing list