Skip to content

Commit a05d34b

Browse files
authored
JIT: move second pass of EH opts earlier (#111364)
to avoid messing up loop exit canonicalization (which is sensitive to loops with internal EH flow). Fixed #110959. Also, remove some of the ceremony around `fgModified` -- seems like this is no longer useful/needed. Defer deciding if we need a PSPSym until we create funclets. This removes unused PSPSym allocations in some cases. Also, there is no benefit to tracking the PSPSym, so stop doing that.
1 parent 9fea441 commit a05d34b

File tree

6 files changed

+31
-45
lines changed

6 files changed

+31
-45
lines changed

src/coreclr/jit/compiler.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4825,6 +4825,18 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
48254825
//
48264826
DoPhase(this, PHASE_COMPUTE_BLOCK_WEIGHTS, &Compiler::fgComputeBlockWeights);
48274827

4828+
// Try again to remove empty try finally/fault clauses
4829+
//
4830+
DoPhase(this, PHASE_EMPTY_FINALLY_2, &Compiler::fgRemoveEmptyFinally);
4831+
4832+
// Remove empty try regions (try/finally)
4833+
//
4834+
DoPhase(this, PHASE_EMPTY_TRY_2, &Compiler::fgRemoveEmptyTry);
4835+
4836+
// Remove empty try regions (try/catch/fault)
4837+
//
4838+
DoPhase(this, PHASE_EMPTY_TRY_CATCH_FAULT_2, &Compiler::fgRemoveEmptyTryCatchOrTryFault);
4839+
48284840
// Invert loops
48294841
//
48304842
DoPhase(this, PHASE_INVERT_LOOPS, &Compiler::optInvertLoops);
@@ -4860,18 +4872,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
48604872
//
48614873
DoPhase(this, PHASE_UNROLL_LOOPS, &Compiler::optUnrollLoops);
48624874

4863-
// Try again to remove empty try finally/fault clauses
4864-
//
4865-
DoPhase(this, PHASE_EMPTY_FINALLY_2, &Compiler::fgRemoveEmptyFinally);
4866-
4867-
// Remove empty try regions (try/finally)
4868-
//
4869-
DoPhase(this, PHASE_EMPTY_TRY_2, &Compiler::fgRemoveEmptyTry);
4870-
4871-
// Remove empty try regions (try/catch/fault)
4872-
//
4873-
DoPhase(this, PHASE_EMPTY_TRY_CATCH_FAULT_2, &Compiler::fgRemoveEmptyTryCatchOrTryFault);
4874-
48754875
// Compute dominators and exceptional entry blocks
48764876
//
48774877
DoPhase(this, PHASE_COMPUTE_DOMINATORS, &Compiler::fgComputeDominators);

src/coreclr/jit/fgehopt.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,12 +2458,6 @@ PhaseStatus Compiler::fgTailMergeThrows()
24582458
assert(numCandidates < optNoReturnCallCount);
24592459
optNoReturnCallCount -= numCandidates;
24602460

2461-
// If we altered flow, reset fgModified. Given where we sit in the
2462-
// phase list, flow-dependent side data hasn't been built yet, so
2463-
// nothing needs invalidation.
2464-
//
2465-
assert(fgModified);
2466-
fgModified = false;
24672461
return PhaseStatus::MODIFIED_EVERYTHING;
24682462
}
24692463

src/coreclr/jit/fgopt.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6780,12 +6780,6 @@ PhaseStatus Compiler::fgHeadTailMerge(bool early)
67806780
madeChanges |= fgHeadMerge(block, early);
67816781
}
67826782

6783-
// If we altered flow, reset fgModified. Given where we sit in the
6784-
// phase list, flow-dependent side data hasn't been built yet, so
6785-
// nothing needs invalidation.
6786-
//
6787-
fgModified = false;
6788-
67896783
return madeChanges ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING;
67906784
}
67916785

src/coreclr/jit/flowgraph.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,6 +2989,18 @@ PhaseStatus Compiler::fgCreateFunclets()
29892989
assert(UsesFunclets());
29902990
assert(!fgFuncletsCreated);
29912991

2992+
// Allocate the PSPSym, if needed. PSPSym is not used by the NativeAOT ABI
2993+
if (!IsTargetAbi(CORINFO_NATIVEAOT_ABI))
2994+
{
2995+
if (ehNeedsPSPSym())
2996+
{
2997+
lvaPSPSym = lvaGrabTempWithImplicitUse(false DEBUGARG("PSPSym"));
2998+
LclVarDsc* lclPSPSym = lvaGetDesc(lvaPSPSym);
2999+
lclPSPSym->lvType = TYP_I_IMPL;
3000+
lvaSetVarDoNotEnregister(lvaPSPSym DEBUGARG(DoNotEnregisterReason::VMNeedsStackAddr));
3001+
}
3002+
}
3003+
29923004
fgCreateFuncletPrologBlocks();
29933005

29943006
unsigned XTnum;

src/coreclr/jit/lclvars.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4073,6 +4073,13 @@ void Compiler::lvaSortByRefCount()
40734073
}
40744074
#endif
40754075

4076+
// No benefit in tracking the PSPSym (if any)
4077+
//
4078+
if (lclNum == lvaPSPSym)
4079+
{
4080+
varDsc->lvTracked = 0;
4081+
}
4082+
40764083
// Are we not optimizing and we have exception handlers?
40774084
// if so mark all args and locals "do not enregister".
40784085
//
@@ -4747,18 +4754,6 @@ PhaseStatus Compiler::lvaMarkLocalVars()
47474754

47484755
#endif // FEATURE_EH_WINDOWS_X86
47494756

4750-
// PSPSym is not used by the NativeAOT ABI
4751-
if (!IsTargetAbi(CORINFO_NATIVEAOT_ABI))
4752-
{
4753-
if (UsesFunclets() && ehNeedsPSPSym())
4754-
{
4755-
lvaPSPSym = lvaGrabTempWithImplicitUse(false DEBUGARG("PSPSym"));
4756-
LclVarDsc* lclPSPSym = lvaGetDesc(lvaPSPSym);
4757-
lclPSPSym->lvType = TYP_I_IMPL;
4758-
lvaSetVarDoNotEnregister(lvaPSPSym DEBUGARG(DoNotEnregisterReason::VMNeedsStackAddr));
4759-
}
4760-
}
4761-
47624757
#ifdef JIT32_GCENCODER
47634758
// LocAllocSPvar is only required by the implicit frame layout expected by the VM on x86. Whether
47644759
// a function contains a Localloc is conveyed in the GC information, in the InfoHdrSmall.localloc

src/coreclr/jit/optimizer.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,6 @@ bool Compiler::optInvertWhileLoop(BasicBlock* block)
23512351
PhaseStatus Compiler::optInvertLoops()
23522352
{
23532353
noway_assert(opts.OptimizationEnabled());
2354-
noway_assert(fgModified == false);
23552354

23562355
#if defined(OPT_CONFIG)
23572356
if (!JitConfig.JitDoLoopInversion())
@@ -2387,13 +2386,6 @@ PhaseStatus Compiler::optInvertLoops()
23872386
}
23882387
}
23892388

2390-
if (fgModified)
2391-
{
2392-
// Reset fgModified here as we've done a consistent set of edits.
2393-
//
2394-
fgModified = false;
2395-
}
2396-
23972389
return madeChanges ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING;
23982390
}
23992391

@@ -2410,7 +2402,6 @@ PhaseStatus Compiler::optInvertLoops()
24102402
PhaseStatus Compiler::optOptimizeFlow()
24112403
{
24122404
noway_assert(opts.OptimizationEnabled());
2413-
noway_assert(fgModified == false);
24142405

24152406
fgUpdateFlowGraph(/* doTailDuplication */ true);
24162407
fgReorderBlocks(/* useProfile */ false);

0 commit comments

Comments
 (0)