[llvm-branch-commits] [llvm] GlobalISel: Use MIPatternMatch in GIMatchTableExecutor (PR #216601)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Aug 16 13:21:06 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/216601

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 at anthropic.com>

>From 1d257523fbcc2d1a56f7243abf5f0d947b0ff32e Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sat, 15 Aug 2026 14:40:36 +0200
Subject: [PATCH] GlobalISel: Use MIPatternMatch in GIMatchTableExecutor

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 at anthropic.com>
---
 .../CodeGen/GlobalISel/GIMatchTableExecutor.cpp    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

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,



More information about the llvm-branch-commits mailing list