From 3b3da4d94dbdb69ac1cee62cb367b4618f3d110d Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 5 Feb 2026 22:09:34 +0100 Subject: [PATCH] JIT: Run liveness + DCE in tier0 --- src/coreclr/jit/compiler.cpp | 4 +++ src/coreclr/jit/compiler.h | 1 + src/coreclr/jit/liveness.cpp | 49 ++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 379c33ab5a5042..499fadf633b627 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -4857,6 +4857,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl opts.optRepeatActive = false; } } + else if (opts.Tier0OptimizationEnabled()) + { + fgTier0Liveness(); + } optLoopsCanonical = false; diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 7932debc22a854..cac43825f24649 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -6698,6 +6698,7 @@ class Compiler } void fgSsaLiveness(); + void fgTier0Liveness(); void fgAsyncLiveness(); void fgPostLowerLiveness(); PhaseStatus fgEarlyLiveness(); diff --git a/src/coreclr/jit/liveness.cpp b/src/coreclr/jit/liveness.cpp index 971a65cbb9c29e..a8ab06df45d1ae 100644 --- a/src/coreclr/jit/liveness.cpp +++ b/src/coreclr/jit/liveness.cpp @@ -2828,6 +2828,55 @@ void Compiler::fgSsaLiveness() liveness.Run(); } +//------------------------------------------------------------------------ +// fgSsaLiveness: Run SSA liveness. +// +void Compiler::fgTier0Liveness() +{ + struct Tier0Liveness : public Liveness + { + enum + { + SsaLiveness = false, + ComputeMemoryLiveness = false, + IsLIR = false, + IsEarly = false, + }; + + Tier0Liveness(Compiler* comp) + : Liveness(comp) + { + } + }; + + if (m_dfsTree == nullptr) + { + m_dfsTree = fgComputeDfs(); + } + + Tier0Liveness liveness(this); + liveness.Run(); + + // Rest of the compiler does not expect that we started tracking locals, so reset that state. + for (unsigned i = 0; i < lvaTrackedCount; i++) + { + lvaGetDesc(lvaTrackedToVarNum[i])->lvTracked = false; + } + + lvaCurEpoch++; + lvaTrackedCount = 0; + lvaTrackedCountInSizeTUnits = 0; + + for (BasicBlock* block : Blocks()) + { + block->bbLiveIn = VarSetOps::UninitVal(); + block->bbLiveOut = VarSetOps::UninitVal(); + block->bbVarUse = VarSetOps::UninitVal(); + block->bbVarDef = VarSetOps::UninitVal(); + } + fgBBVarSetsInited = false; +} + //------------------------------------------------------------------------ // fgAsyncLiveness: Run async liveness. //