[llvm] GlobalISel: Use m_GImplicitDef instead of getVRegDef opcode checks (PR #216513)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 15 15:07:45 PDT 2026


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

Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>

>From d4c023015b9b68607b82e202e22e5b65670cf58d Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sat, 15 Aug 2026 14:46:10 +0200
Subject: [PATCH] GlobalISel: Use m_GImplicitDef instead of getVRegDef opcode
 checks

Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
---
 llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | 3 +--
 llvm/lib/CodeGen/GlobalISel/Utils.cpp           | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 914993a581085..6f85390fd4ede 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -9731,8 +9731,7 @@ LegalizerHelper::lowerVECTOR_COMPRESS(llvm::MachineInstr &MI) {
 
   auto OutPos = MIRBuilder.buildConstant(IdxTy, 0);
 
-  bool HasPassthru =
-      MRI.getVRegDef(Passthru)->getOpcode() != TargetOpcode::G_IMPLICIT_DEF;
+  bool HasPassthru = !mi_match(Passthru, MRI, m_GImplicitDef());
 
   if (HasPassthru)
     MIRBuilder.buildStore(Passthru, StackPtr, PtrInfo, VecAlign);
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index c555b67d9198c..36e427188c0b5 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -1331,7 +1331,7 @@ std::optional<ValueAndVReg> getAnyConstantSplat(Register VReg,
 
     // If AllowUndef, treat undef as value that will result in a constant splat.
     if (!ElementValAndReg) {
-      if (AllowUndef && isa<GImplicitDef>(MRI.getVRegDef(Element)))
+      if (AllowUndef && mi_match(Element, MRI, m_GImplicitDef()))
         continue;
       return std::nullopt;
     }



More information about the llvm-commits mailing list