From 4676fefe48cc15cf7c0751c194600f34bb0556fb Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Wed, 29 Oct 2025 15:43:59 -0700 Subject: [PATCH 1/2] [RegAlloc] Add a flag to toggle non-trivial rematerialization --- llvm/lib/CodeGen/TargetInstrInfo.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index 3c41bbeb4b327..54026d205168d 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -56,6 +56,10 @@ static cl::opt MaxAccumulatorWidth( "acc-max-width", cl::Hidden, cl::init(3), cl::desc("Maximum number of branches in the accumulator tree")); +static cl::opt AllowNTRemat( + "allow-none-trival-remat", cl::init(true), cl::Hidden, + cl::desc("Allow non-trivial rematerialization by default")); + TargetInstrInfo::~TargetInstrInfo() = default; const TargetRegisterClass * @@ -1657,6 +1661,14 @@ bool TargetInstrInfo::isReMaterializableImpl( // same virtual register, though. if (MO.isDef() && Reg != DefReg) return false; + + // Don't allow any virtual-register uses. Rematting an instruction with + // virtual register uses would length the live ranges of the uses, which + // is not necessarily a good idea, certainly not "trivial". + if (!AllowNTRemat) { + if (MO.isUse()) + return false; + } } // Everything checked out. From 50cf8b4300be0a7677c42e905ebb90389a0de465 Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Wed, 29 Oct 2025 15:52:02 -0700 Subject: [PATCH 2/2] format --- llvm/lib/CodeGen/TargetInstrInfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index 54026d205168d..ed28064510e67 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -56,9 +56,9 @@ static cl::opt MaxAccumulatorWidth( "acc-max-width", cl::Hidden, cl::init(3), cl::desc("Maximum number of branches in the accumulator tree")); -static cl::opt AllowNTRemat( - "allow-none-trival-remat", cl::init(true), cl::Hidden, - cl::desc("Allow non-trivial rematerialization by default")); +static cl::opt + AllowNTRemat("allow-none-trival-remat", cl::init(true), cl::Hidden, + cl::desc("Allow non-trivial rematerialization by default")); TargetInstrInfo::~TargetInstrInfo() = default;