Skip to content

Commit 8f3d1ef

Browse files
lewingCopilot
andcommitted
JIT: never skip prolog zeroing for untracked GC locals
Instead of extending the safe-point scan with throwing trees, don't mark GC locals reported as untracked slots as explicitly initialized at all. They are reported whenever their frame is, and optRemoveRedundantZeroInits runs before later phases (helper expansion, lowering) that can still introduce calls, so it can't rule out every gc-safe point before the store. Tracked GC locals are only reported where they're live and keep the optimization. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 45f42362-f012-4030-8643-26f4c1fbf2e1
1 parent e8083cd commit 8f3d1ef

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎src/coreclr/jit/optimizer.cpp‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5695,9 +5695,8 @@ typedef JitHashTable<unsigned, JitSmallPrimitiveKeyFuncs<unsigned>, unsigned> Lc
56955695
// 2. If the following conditions are true:
56965696
// the store is to a local (and not a field),
56975697
// the local is not lvLiveInOutOfHndlr or no exceptions can be thrown between the prolog and the store,
5698-
// either the local has no gc pointers or there are no gc-safe points between the prolog and the store,
5699-
// and, if the local is reported as an untracked gc slot, no exceptions can be thrown between the prolog
5700-
// and the store,
5698+
// either the local has no gc pointers or it is not reported as an untracked gc slot and there are no
5699+
// gc-safe points between the prolog and the store,
57015700
// then the local is marked with lvHasExplicitInit which tells the codegen not to insert zero initialization
57025701
// for this local in the prolog.
57035702
//
@@ -5716,7 +5715,6 @@ void Compiler::optRemoveRedundantZeroInits()
57165715
BitVec zeroInitLocals = BitVecOps::MakeEmpty(&bitVecTraits);
57175716
bool hasGCSafePoint = false;
57185717
bool hasImplicitControlFlow = false;
5719-
bool mayThrow = false;
57205718

57215719
assert(fgNodeThreading == NodeThreading::AllTrees);
57225720

@@ -5767,9 +5765,7 @@ void Compiler::optRemoveRedundantZeroInits()
57675765
Statement* next = stmt->GetNextStmt();
57685766
for (GenTree* const tree : stmt->TreeList())
57695767
{
5770-
const bool treeMayThrow = (tree->gtFlags & GTF_EXCEPT) != 0;
5771-
hasImplicitControlFlow |= hasEHSuccs && treeMayThrow;
5772-
mayThrow |= treeMayThrow;
5768+
hasImplicitControlFlow |= hasEHSuccs && ((tree->gtFlags & GTF_EXCEPT) != 0);
57735769
hasGCSafePoint |= IsPotentialGCSafePoint(tree);
57745770

57755771
switch (tree->gtOper)
@@ -5933,10 +5929,9 @@ void Compiler::optRemoveRedundantZeroInits()
59335929
#else
59345930
const bool reportedAsUntracked = !lclDsc->lvTracked;
59355931
#endif
5936-
// An untracked gc slot is reported whenever its frame is, including from
5937-
// a throw helper that a tree before this store may call.
5938-
if (!lclDsc->HasGCPtr() ||
5939-
(!GetInterruptible() && !hasGCSafePoint && !(mayThrow && reportedAsUntracked)))
5932+
// An untracked gc slot is reported whenever its frame is, and this phase can't
5933+
// rule out every gc-safe point before the store, so it keeps its prolog zeroing.
5934+
if (!lclDsc->HasGCPtr() || (!reportedAsUntracked && !GetInterruptible() && !hasGCSafePoint))
59405935
{
59415936
// The local hasn't been used and won't be reported to the gc between
59425937
// the prolog and this explicit initialization. Therefore, it doesn't

0 commit comments

Comments
 (0)