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: Make loop inversion graph based #109346

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4869,10 +4869,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

if (opts.OptimizationEnabled())
{
// Invert loops
//
DoPhase(this, PHASE_INVERT_LOOPS, &Compiler::optInvertLoops);

// Run some flow graph optimizations (but don't reorder)
//
DoPhase(this, PHASE_OPTIMIZE_FLOW, &Compiler::optOptimizeFlow);
Expand Down Expand Up @@ -4900,6 +4896,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
//
DoPhase(this, PHASE_SET_BLOCK_WEIGHTS, &Compiler::optSetBlockWeights);

// Invert loops
//
DoPhase(this, PHASE_INVERT_LOOPS, &Compiler::optInvertLoops);

// Clone loops with optimization opportunities, and choose one based on dynamic condition evaluation.
//
DoPhase(this, PHASE_CLONE_LOOPS, &Compiler::optCloneLoops);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7145,7 +7145,7 @@ class Compiler

OptInvertCountTreeInfoType optInvertCountTreeInfo(GenTree* tree);

bool optInvertWhileLoop(BasicBlock* block);
bool optTryInvertWhileLoop(FlowGraphNaturalLoop* loop);
bool optIfConvert(BasicBlock* block);

private:
Expand Down
7 changes: 6 additions & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4714,7 +4714,12 @@ void Compiler::fgDebugCheckLoops()
loop->VisitRegularExitBlocks([=](BasicBlock* exit) {
for (BasicBlock* pred : exit->PredBlocks())
{
assert(loop->ContainsBlock(pred));
if (!loop->ContainsBlock(pred))
{
JITDUMP("Loop " FMT_LP " exit " FMT_BB " has non-loop predecessor " FMT_BB "\n",
loop->GetIndex(), exit->bbNum, pred->bbNum);
assert(!"Loop exit has non-loop predecessor");
}
}
return BasicBlockVisit::Continue;
});
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/jitmetadatalist.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ JITMETADATAMETRIC(GCInfoBytes, int, JIT_M
JITMETADATAMETRIC(EHClauseCount, int, 0)
JITMETADATAMETRIC(PhysicallyPromotedFields, int, 0)
JITMETADATAMETRIC(LoopsFoundDuringOpts, int, 0)
JITMETADATAMETRIC(LoopsInverted, int, 0)
JITMETADATAMETRIC(LoopsCloned, int, 0)
JITMETADATAMETRIC(LoopsUnrolled, int, 0)
JITMETADATAMETRIC(LoopAlignmentCandidates, int, 0)
Expand Down
Loading
Loading