Skip to content

Commit 99dcf5b

Browse files
authored
JIT: simple forward substitution pass (#63720)
Extend ref counting done by local morph so that we can determine single-def single-use locals. Add a phase that runs just after local morph that will attempt to forward single-def single-use local defs to uses when they are in adjacent statements. Fix or work around issues uncovered elsewhere: * `gtFoldExprCompare` might fold "identical" volatile subtrees * `fgGetStubAddrArg` cannot handle complex trees * some simd/hw operations can lose struct handles * some calls cannot handle struct local args * morph expects args not to interfere * fix arm; don't forward sub no return calls * update debuginfo test (we may want to revisit this) * handle subbing past normalize on store assignment * clean up nullcheck of new helper Addresses #6973 and related issues. Still sorting through exactly which ones are fixed, so list below may need revising. Fixes #48605. Fixes #51599. Fixes #55472. Improves some but not all cases in #12280 and #62064. Does not fix #33002, #47082, or #63116; these require handling multiple uses or bypassing statements.
1 parent 0c3a6ee commit 99dcf5b

File tree

16 files changed

+1102
-25
lines changed

16 files changed

+1102
-25
lines changed

src/coreclr/jit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ set( JIT_SOURCES
104104
fgprofile.cpp
105105
fgstmt.cpp
106106
flowgraph.cpp
107+
forwardsub.cpp
107108
gcdecode.cpp
108109
gcencode.cpp
109110
gcinfo.cpp

src/coreclr/jit/compiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,6 +4657,9 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
46574657
// Figure out what locals are address-taken.
46584658
//
46594659
DoPhase(this, PHASE_STR_ADRLCL, &Compiler::fgMarkAddressExposedLocals);
4660+
// Run a simple forward substitution pass.
4661+
//
4662+
DoPhase(this, PHASE_FWD_SUB, &Compiler::fgForwardSub);
46604663

46614664
// Apply the type update to implicit byref parameters; also choose (based on address-exposed
46624665
// analysis) which implicit byref promotions to keep (requires copy to initialize) or discard.

src/coreclr/jit/compiler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6423,7 +6423,7 @@ class Compiler
64236423

64246424
bool fgMorphCanUseLclFldForCopy(unsigned lclNum1, unsigned lclNum2);
64256425

6426-
GenTreeLclVar* fgMorphTryFoldObjAsLclVar(GenTreeObj* obj);
6426+
GenTreeLclVar* fgMorphTryFoldObjAsLclVar(GenTreeObj* obj, bool destroyNodes = true);
64276427
GenTreeOp* fgMorphCommutative(GenTreeOp* tree);
64286428
GenTree* fgMorphCastedBitwiseOp(GenTreeOp* tree);
64296429

@@ -6562,6 +6562,10 @@ class Compiler
65626562
void fgMarkAddressExposedLocals();
65636563
void fgMarkAddressExposedLocals(Statement* stmt);
65646564

6565+
PhaseStatus fgForwardSub();
6566+
bool fgForwardSubBlock(BasicBlock* block);
6567+
bool fgForwardSubStatement(Statement* statement);
6568+
65656569
static fgWalkPreFn fgUpdateSideEffectsPre;
65666570
static fgWalkPostFn fgUpdateSideEffectsPost;
65676571

src/coreclr/jit/compphases.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CompPhaseNameMacro(PHASE_UPDATE_FINALLY_FLAGS, "Update finally target flags",
4343
CompPhaseNameMacro(PHASE_COMPUTE_PREDS, "Compute preds", "PREDS", false, -1, false)
4444
CompPhaseNameMacro(PHASE_EARLY_UPDATE_FLOW_GRAPH,"Update flow graph early pass", "UPD-FG-E", false, -1, false)
4545
CompPhaseNameMacro(PHASE_STR_ADRLCL, "Morph - Structs/AddrExp", "MOR-STRAL",false, -1, false)
46+
CompPhaseNameMacro(PHASE_FWD_SUB, "Forward Substitution", "FWD-SUB", false, -1, false)
4647
CompPhaseNameMacro(PHASE_MORPH_IMPBYREF, "Morph - ByRefs", "MOR-BYREF",false, -1, false)
4748
CompPhaseNameMacro(PHASE_PROMOTE_STRUCTS, "Morph - Promote Structs", "PROMOTER" ,false, -1, false)
4849
CompPhaseNameMacro(PHASE_MORPH_GLOBAL, "Morph - Global", "MOR-GLOB", false, -1, false)

0 commit comments

Comments
 (0)