[llvm] CodeGen: Use getDefBlock in MachineLoop::isLoopInvariant (PR #217018)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 05:57:19 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/217018
Look up the defining block of an operand's register directly with
getDefBlock() instead of calling getVRegDef() twice and relying on
contains() to walk to the instruction's parent. NFC.
Co-Authored-By: Claude <noreply at anthropic.com> claude-opus-4.8
>From 37d9b726ab69e6245ca9e931182f5f5e8db60010 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 18 Aug 2026 14:55:06 +0200
Subject: [PATCH] CodeGen: Use getDefBlock in MachineLoop::isLoopInvariant
Look up the defining block of an operand's register directly with
getDefBlock() instead of calling getVRegDef() twice and relying on
contains() to walk to the instruction's parent. NFC.
Co-Authored-By: Claude <noreply at anthropic.com> claude-opus-4.8
---
llvm/lib/CodeGen/MachineLoopInfo.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineLoopInfo.cpp b/llvm/lib/CodeGen/MachineLoopInfo.cpp
index 3fb0d043b01a1..a6daa5adfaeaa 100644
--- a/llvm/lib/CodeGen/MachineLoopInfo.cpp
+++ b/llvm/lib/CodeGen/MachineLoopInfo.cpp
@@ -286,12 +286,12 @@ bool MachineLoop::isLoopInvariant(MachineInstr &I,
if (!MO.readsReg())
continue;
- assert(MRI->getVRegDef(Reg) &&
- "Machine instr not mapped for this vreg?!");
+ MachineBasicBlock *DefBlock = MRI->getDefBlock(Reg);
+ assert(DefBlock && "Machine instr not mapped for this vreg?!");
// If the loop contains the definition of an operand, then the instruction
// isn't loop invariant.
- if (contains(MRI->getVRegDef(Reg)))
+ if (contains(DefBlock))
return false;
}
More information about the llvm-commits
mailing list