The liveness pass attempts to remove dead stores that it encounters
during its liveness computation. Successfully removing a dead store,
however, may invalidate the results of the computation. Therefore, the
pass operates as a fixed-point algorithm: it recomputes liveness until
either the contents of the function do not change or the removed code
does not change the results.
When running liveness on LIR, the correct flag--`fgStmtRemoved`--was not
being set if a dead store was succesfully removed. This caused the
liveness pass to terminate early and produce invalid results in certain
cases. This fix sets `fgStmtRemoved` when a dead store is successfully
removed in an LIR block.
Commit migrated from https://github.com/dotnet/coreclr/commit/
318945fdff3670103f97d05c317123c7ab2ef0d6
else if (node->OperIsNonPhiLocal() || node->OperIsLocalAddr())
{
bool isDeadStore = fgComputeLifeLocal(life, keepAliveVars, node, node);
- if (isDeadStore)
+ if (isDeadStore && fgTryRemoveDeadLIRStore(blockRange, node, &next))
{
- fgTryRemoveDeadLIRStore(blockRange, node, &next);
+ fgStmtRemoved = true;
}
}
}