Skip to content

Commit

Permalink
JIT: Add missing lvTracked check in optLocalHasNonLoopUses (dotne…
Browse files Browse the repository at this point in the history
…t#109505)

`optLocalHasNonLoopUses` checks if a local might be used after a loop by
making use of its liveness information, but it does not check
`lvTracked` before doing so. This is generally not a problem as there
are other checks that the local is in SSA, and normally SSA implies
lvTracked, but that's not the case for locals put into SSA by CSE.

Since it is possible to have CSE defs in a loop with uses outside the
loop, this check is necessary for correctness. It is expected to regress
a bunch of IV opts cases, but in the future we can get those back by
computing the necessary liveness when we insert into SSA.
  • Loading branch information
jakobbotsch authored Nov 5, 2024
1 parent 302e0d4 commit 73e1976
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/coreclr/jit/inductionvariableopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,11 @@ bool Compiler::optLocalHasNonLoopUses(unsigned lclNum, FlowGraphNaturalLoop* loo
return true;
}

if (!varDsc->lvTracked)
{
return true;
}

BasicBlockVisit visitResult = loop->VisitRegularExitBlocks([=](BasicBlock* block) {
if (VarSetOps::IsMember(this, block->bbLiveIn, varDsc->lvVarIndex))
{
Expand Down

0 comments on commit 73e1976

Please sign in to comment.