Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4857,6 +4857,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
opts.optRepeatActive = false;
}
}
else if (opts.Tier0OptimizationEnabled())
{
fgTier0Liveness();
}

optLoopsCanonical = false;

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6698,6 +6698,7 @@ class Compiler
}

void fgSsaLiveness();
void fgTier0Liveness();
void fgAsyncLiveness();
void fgPostLowerLiveness();
PhaseStatus fgEarlyLiveness();
Expand Down
49 changes: 49 additions & 0 deletions src/coreclr/jit/liveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2828,6 +2828,55 @@ void Compiler::fgSsaLiveness()
liveness.Run();
}

//------------------------------------------------------------------------
// fgSsaLiveness: Run SSA liveness.
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly states "Run SSA liveness" which is a copy-paste error from the fgSsaLiveness function above. This should say something like "Run tier0 liveness" or "Run liveness for tier0 optimization" to accurately describe what this function does.

Suggested change
// fgSsaLiveness: Run SSA liveness.
// fgTier0Liveness: Run tier0 liveness.

Copilot uses AI. Check for mistakes.
//
void Compiler::fgTier0Liveness()
{
struct Tier0Liveness : public Liveness<Tier0Liveness>
{
enum
{
SsaLiveness = false,
ComputeMemoryLiveness = false,
IsLIR = false,
IsEarly = false,
};
Comment on lines +2836 to +2844
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title states "Run liveness + DCE in tier0", but dead code elimination (DCE) will not actually run with this configuration. DCE only runs when IsEarly=true, which causes the compiler to use the TryRemoveDeadStoreEarly path during liveness analysis. The Tier0Liveness struct sets IsEarly=false, so it will follow the standard liveness path without DCE.

At the call site, fgNodeThreading is NodeThreading::AllTrees, and with IsEarly=false, the liveness analysis follows the code path at lines 1265-1313 in liveness.cpp which does not perform dead store removal. The DCE path at lines 1314-1387 only executes when IsEarly=true.

If the intent is to run DCE in tier0, IsEarly should be set to true. If DCE is not intended, the PR title and description should be updated to remove the mention of DCE.

Copilot uses AI. Check for mistakes.

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.
//
Expand Down
Loading