[llvm] CodeGen: Use getOneNonDBGUser in PeepholeOptimizer (PR #219526)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 09:53:23 PDT 2026


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

Use getOneNonDBGUser instead of the parent of the first non-debug use operand,
so this no longer depends on MachineOperand::getParent().

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

>From b68d27c2d19b9e027293ec33c4e4b222e338f4d6 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 28 Aug 2026 18:51:04 +0200
Subject: [PATCH] CodeGen: Use getOneNonDBGUser in PeepholeOptimizer

Use getOneNonDBGUser instead of the parent of the first non-debug use operand,
so this no longer depends on MachineOperand::getParent().

Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
 llvm/lib/CodeGen/PeepholeOptimizer.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
index 4845b715f512d..c32d6864a4a8f 100644
--- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
@@ -968,8 +968,8 @@ bool PeepholeOptimizer::optimizeCmpInstr(
 
   // The eliminated compare may have been the extra use preventing a
   // load from being folded into the flag-setting instruction.
-  if (SrcReg.isVirtual() && MRI->hasOneNonDBGUser(SrcReg)) {
-    MachineInstr *FlagProducer = MRI->use_nodbg_begin(SrcReg)->getParent();
+  if (MachineInstr *FlagProducer =
+          SrcReg.isVirtual() ? MRI->getOneNonDBGUser(SrcReg) : nullptr) {
     MachineInstr *LoadMI = MRI->getVRegDef(SrcReg);
     // No store between LoadMI and FlagProducer that could change the value.
     if (LocalMIs.count(FlagProducer) && LoadMI && LoadMI->canFoldAsLoad() &&



More information about the llvm-commits mailing list