Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Add scalar evolution analysis and do IV widening based on it #97865

Merged
merged 73 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c86effc
WIP
jakobbotsch Jan 30, 2024
f8f899e
WIP
jakobbotsch Feb 1, 2024
e2bca3a
Check invariance on IR instead of on SCEV to avoid cycles
jakobbotsch Feb 1, 2024
f400f03
Some work on recursive scevs
jakobbotsch Feb 1, 2024
05562bb
Simplify for now
jakobbotsch Feb 1, 2024
3036826
IV widening, fix bugs
jakobbotsch Feb 2, 2024
8f0230e
Merge branch 'main' of github.com:dotnet/runtime into simplify-ivs
jakobbotsch Feb 2, 2024
974e7f9
Bail for non-integer constants
jakobbotsch Feb 2, 2024
c510054
Add costing
jakobbotsch Feb 2, 2024
96d5bec
Run jit-format
jakobbotsch Feb 2, 2024
0592111
Clean up
jakobbotsch Feb 2, 2024
2a02a48
Fix linux build
jakobbotsch Feb 2, 2024
99cca89
Clean up
jakobbotsch Feb 2, 2024
1dc2673
Merge branch 'main' of github.com:dotnet/runtime into simplify-ivs
jakobbotsch Feb 2, 2024
0df9a03
Do not swap addrecs unnecessarily when folding
jakobbotsch Feb 3, 2024
cf31ff6
Add some todos
jakobbotsch Feb 3, 2024
c498884
JIT: Support more scaled addressing modes on arm64
jakobbotsch Feb 3, 2024
39b2a6d
Move phase later; compute loops; address some TODOs
jakobbotsch Feb 5, 2024
6f11425
Add docs, enhance optIsIVWideningProfitable when zero extensions are …
jakobbotsch Feb 5, 2024
04c3652
Run jit-format
jakobbotsch Feb 5, 2024
b16aa2e
Remove unnecessary config var
jakobbotsch Feb 5, 2024
66d28d5
Merge branch 'main' into simplify-ivs
jakobbotsch Feb 5, 2024
666bcf3
JIT: Canonicalize loop exits
jakobbotsch Feb 7, 2024
30bbdd8
Remove some manual canonicalization code
jakobbotsch Feb 7, 2024
1bb370c
Remove unused declaration
jakobbotsch Feb 7, 2024
bb7462d
Clean up
jakobbotsch Feb 7, 2024
5af1195
Fix function header
jakobbotsch Feb 7, 2024
58ebfb8
Handle x86; skip regular exit blocks that are handlers
jakobbotsch Feb 7, 2024
3304ae3
Set proper weight of exit
jakobbotsch Feb 9, 2024
056a56a
Add stats
jakobbotsch Feb 9, 2024
9be9ae5
Merge remote-tracking branch 'origin/canonicalize-loop-exits' into si…
jakobbotsch Feb 9, 2024
bdab205
Remove stats
jakobbotsch Feb 12, 2024
f106659
Only do IV widening on x64
jakobbotsch Feb 12, 2024
35813bf
Clean up
jakobbotsch Feb 12, 2024
0453ee6
Run jit-format
jakobbotsch Feb 12, 2024
cde78a6
Merge branch 'main' of github.com:dotnet/runtime into simplify-ivs
jakobbotsch Feb 13, 2024
1fc2f42
Only look at regular exits
jakobbotsch Feb 14, 2024
ed8d668
Merge branch 'main' of github.com:dotnet/runtime into simplify-ivs
jakobbotsch Feb 14, 2024
b2e201c
Add depth limit; small clean ups
jakobbotsch Feb 14, 2024
c63baf0
Revert unnecessary change
jakobbotsch Feb 14, 2024
d946974
Remove counter
jakobbotsch Feb 14, 2024
64bad73
Add more info for LclVarDsc reason
jakobbotsch Feb 14, 2024
fa71a22
Merge branch 'main' of github.com:dotnet/runtime into simplify-ivs
jakobbotsch Feb 15, 2024
de391a6
Share widened IVs with same reaching def from outside the loop
jakobbotsch Feb 15, 2024
6febef6
Revert regressions only change
jakobbotsch Feb 15, 2024
2577046
Also try replacing uses before the loop
jakobbotsch Feb 16, 2024
5d7e15f
Skip cases where the same local is the IV in multiple loops
jakobbotsch Feb 16, 2024
251a754
More experimenting
jakobbotsch Feb 16, 2024
e0905f7
Improve
jakobbotsch Feb 16, 2024
5a6f2f8
Run jit-format
jakobbotsch Feb 16, 2024
2836ef1
Clean up
jakobbotsch Feb 16, 2024
41c2503
Clean up
jakobbotsch Feb 16, 2024
a3f4a2e
Run jit-format
jakobbotsch Feb 16, 2024
6812397
Insert after phis correctly
jakobbotsch Feb 20, 2024
439acda
Squashed
jakobbotsch Feb 20, 2024
0de3484
Merge remote-tracking branch 'origin/jit-metrics-squashed' into simpl…
jakobbotsch Feb 20, 2024
b600ffc
Fix
jakobbotsch Feb 20, 2024
d99c2f7
Print PerfScore geomeans
jakobbotsch Feb 20, 2024
f4e853b
Add to report
jakobbotsch Feb 20, 2024
bc38b0e
Clean up
jakobbotsch Feb 20, 2024
8b511bb
Move overall perfscore change to details
jakobbotsch Feb 20, 2024
e64b95b
Merge branch 'main' of github.com:dotnet/runtime into simplify-ivs
jakobbotsch Feb 21, 2024
212ef84
Fixes after merge
jakobbotsch Feb 21, 2024
1c4b20d
Run jit-format
jakobbotsch Feb 21, 2024
3ba71fc
Do not pick start BB for parameters
jakobbotsch Feb 22, 2024
6a70c29
Optimize throughput
jakobbotsch Feb 23, 2024
410c5c2
Clean up, address some feedback
jakobbotsch Feb 23, 2024
f6efa21
More feedback
jakobbotsch Feb 23, 2024
054ad94
Split out into multiple files
jakobbotsch Feb 27, 2024
2700cda
Address some feedback
jakobbotsch Feb 27, 2024
0f8d2b2
Add some docs
jakobbotsch Feb 27, 2024
3e3759e
More remarks
jakobbotsch Feb 27, 2024
3ec083f
Expand ryujit markdown docs with new phase
jakobbotsch Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ set( JIT_SOURCES
bitset.cpp
block.cpp
buildstring.cpp
layout.cpp
codegencommon.cpp
codegenlinear.cpp
compiler.cpp
Expand Down Expand Up @@ -123,21 +122,23 @@ set( JIT_SOURCES
gentree.cpp
gschecks.cpp
hashbv.cpp
hwintrinsic.cpp
helperexpansion.cpp
hostallocator.cpp
hwintrinsic.cpp
ifconversion.cpp
helperexpansion.cpp
indirectcalltransformer.cpp
importercalls.cpp
importer.cpp
importercalls.cpp
importervectorization.cpp
indirectcalltransformer.cpp
inductionvariableopts.cpp
inline.cpp
inlinepolicy.cpp
instr.cpp
jitconfig.cpp
jiteh.cpp
jithashtable.cpp
jitmetadata.cpp
layout.cpp
lclmorph.cpp
lclvars.cpp
likelyclass.cpp
Expand All @@ -152,7 +153,6 @@ set( JIT_SOURCES
objectalloc.cpp
optcse.cpp
optimizebools.cpp
switchrecognition.cpp
optimizer.cpp
patchpoint.cpp
phase.cpp
Expand All @@ -173,6 +173,7 @@ set( JIT_SOURCES
ssabuilder.cpp
ssarenamestate.cpp
stacklevelsetter.cpp
switchrecognition.cpp
treelifeupdater.cpp
unwind.cpp
utils.cpp
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
bool doValueNum = true;
bool doLoopHoisting = true;
bool doCopyProp = true;
bool doOptimizeIVs = true;
bool doBranchOpt = true;
bool doCse = true;
bool doAssertionProp = true;
Expand All @@ -4905,6 +4906,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
doSsa = (JitConfig.JitDoSsa() != 0);
doEarlyProp = doSsa && (JitConfig.JitDoEarlyProp() != 0);
doValueNum = doSsa && (JitConfig.JitDoValueNumber() != 0);
doOptimizeIVs = doSsa && (JitConfig.JitDoOptimizeIVs() != 0);
doLoopHoisting = doValueNum && (JitConfig.JitDoLoopHoisting() != 0);
doCopyProp = doValueNum && (JitConfig.JitDoCopyProp() != 0);
doBranchOpt = doValueNum && (JitConfig.JitDoRedundantBranchOpts() != 0);
Expand Down Expand Up @@ -5005,6 +5007,13 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
DoPhase(this, PHASE_OPTIMIZE_INDEX_CHECKS, &Compiler::rangeCheckPhase);
}

if (doOptimizeIVs)
{
// Simplify and optimize induction variables used in natural loops
//
DoPhase(this, PHASE_OPTIMIZE_INDUCTION_VARIABLES, &Compiler::optInductionVariables);
}

if (doVNBasedDeadStoreRemoval)
{
// Note: this invalidates SSA and value numbers on tree nodes.
Expand Down
14 changes: 13 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4972,7 +4972,7 @@ class Compiler
#ifdef DEBUG
jitstd::vector<BasicBlock*>* fgBBOrder; // ordered vector of BBs
#endif
// Used as a quick check for whether loop alignment should look for natural loops.
// Used as a quick check for whether phases downstream of loop finding should look for natural loops.
// If true: there may or may not be any natural loops in the flow graph, so try to find them
// If false: there's definitely not any natural loops in the flow graph
bool fgMightHaveNaturalLoops;
Expand Down Expand Up @@ -7411,6 +7411,18 @@ class Compiler
BasicBlock* basicBlock);
#endif

PhaseStatus optInductionVariables();
bool optCanSinkWidenedIV(unsigned lclNum, FlowGraphNaturalLoop* loop);
bool optIsIVWideningProfitable(unsigned lclNum,
BasicBlock* initBlock,
bool initedToConstant,
FlowGraphNaturalLoop* loop,
ArrayStack<Statement*>& ivUses);
void optBestEffortReplaceNarrowIVUsesWith(
unsigned lclNum, unsigned ssaNum, unsigned newLclNum, BasicBlock* block, Statement* firstStmt);
void optReplaceWidenedIV(unsigned lclNum, unsigned ssaNum, unsigned newLclNum, Statement* stmt);
void optSinkWidenedIV(unsigned lclNum, unsigned newLclNum, FlowGraphNaturalLoop* loop);

// Redundant branch opts
//
PhaseStatus optRedundantBranches();
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compmemkind.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CompMemKindMacro(LoopOpt)
CompMemKindMacro(LoopClone)
CompMemKindMacro(LoopUnroll)
CompMemKindMacro(LoopHoist)
CompMemKindMacro(LoopIVOpts)
CompMemKindMacro(Unknown)
CompMemKindMacro(RangeCheck)
CompMemKindMacro(CopyProp)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ CompPhaseNameMacro(PHASE_BUILD_SSA_DF, "SSA: DF",
CompPhaseNameMacro(PHASE_BUILD_SSA_INSERT_PHIS, "SSA: insert phis", false, PHASE_BUILD_SSA, false)
CompPhaseNameMacro(PHASE_BUILD_SSA_RENAME, "SSA: rename", false, PHASE_BUILD_SSA, false)
CompPhaseNameMacro(PHASE_EARLY_PROP, "Early Value Propagation", false, -1, false)
CompPhaseNameMacro(PHASE_OPTIMIZE_INDUCTION_VARIABLES, "Optimize Induction Variables", false, -1, false)
CompPhaseNameMacro(PHASE_VALUE_NUMBER, "Do value numbering", false, -1, false)
CompPhaseNameMacro(PHASE_OPTIMIZE_INDEX_CHECKS, "Optimize index checks", false, -1, false)
CompPhaseNameMacro(PHASE_OPTIMIZE_VALNUM_CSES, "Optimize Valnum CSEs", false, -1, false)
Expand Down
Loading