[llvm-branch-commits] [llvm] [CodeGen] Enhance createFrom for sub-reg aware cloning (PR #174999)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jul 31 02:20:53 PDT 2026
https://github.com/easyonaadit updated https://github.com/llvm/llvm-project/pull/174999
>From bb5f7a2a89e2662aaaef38717ab3a0352e77518a 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 7f884dcbd9e8b..81e854d298089 100644
--- a/llvm/include/llvm/CodeGen/LiveRangeEdit.h
+++ b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
@@ -154,8 +154,11 @@ class LLVM_ABI 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 09152cafab668..a6df2262a613e 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