[llvm-branch-commits] [llvm] [CodeGen] Enhance createFrom for sub-reg aware cloning (PR #174999)
Christudasan Devadasan via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 12 07:29:14 PST 2026
https://github.com/cdevadas updated https://github.com/llvm/llvm-project/pull/174999
>From acb9b345b91f56a7bc7fe41a80c1661699bb7e05 Mon Sep 17 00:00:00 2001
From: Christudasan Devadasan <Christudasan.Devadasan at amd.com>
Date: Wed, 7 Jan 2026 12:42:45 +0000
Subject: [PATCH] [CodeGen] Enhance createFrom for sub-reg aware cloning
Instead of just cloning the virtual register, this
function now creates a new virtual register derived
from a subregister class of the original value.
---
llvm/include/llvm/CodeGen/LiveRangeEdit.h | 7 +++++--
llvm/lib/CodeGen/LiveRangeEdit.cpp | 10 +++++++++-
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/LiveRangeEdit.h b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
index d0ed3ff660d9b..4db5e8008e671 100644
--- a/llvm/include/llvm/CodeGen/LiveRangeEdit.h
+++ b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
@@ -154,8 +154,11 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
ArrayRef<Register> regs() const { return ArrayRef(NewRegs).slice(FirstNew); }
- /// createFrom - Create a new virtual register based on OldReg.
- Register createFrom(Register OldReg);
+ /// createFrom - Create a new virtual register based on OldReg. If \p RC is
+ /// non-null, constrain the register class of the new vreg. Partial reloads
+ /// of tuple regclasses will feed-in a subregclass derived from the regclass
+ /// of OldReg.
+ Register createFrom(Register OldReg, const TargetRegisterClass *RC = nullptr);
/// create - Create a new register with the same class and original slot as
/// parent.
diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp
index 6fe11704a9137..d8a2ad47568b4 100644
--- a/llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -52,8 +52,16 @@ LiveInterval &LiveRangeEdit::createEmptyIntervalFrom(Register OldReg,
return LI;
}
-Register LiveRangeEdit::createFrom(Register OldReg) {
+Register LiveRangeEdit::createFrom(Register OldReg,
+ const TargetRegisterClass *RC) {
Register VReg = MRI.cloneVirtualRegister(OldReg);
+
+ // If RC is given, set it now. This is needed for cloning a new VReg with a
+ // smaller RC from its original virtual register, mainly used for subreg
+ // reload. The cloning is done first to ensure the vreg flags are preserved.
+ if (RC)
+ MRI.setRegClass(VReg, RC);
+
if (VRM) {
VRM->setIsSplitFromReg(VReg, VRM->getOriginal(OldReg));
}
More information about the llvm-branch-commits
mailing list