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: Port loop unrolling to new loop representation #96454

Merged
Merged
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
1 change: 0 additions & 1 deletion src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ bool BasicBlock::CloneBlockState(
assert(to->bbStmtList == nullptr);
to->CopyFlags(from);
to->bbWeight = from->bbWeight;
BlockSetOps::AssignAllowUninitRhs(compiler, to->bbReach, from->bbReach);
to->copyEHRegion(from);
to->bbCatchTyp = from->bbCatchTyp;
to->bbStkTempsIn = from->bbStkTempsIn;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4914,6 +4914,8 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

while (iterations > 0)
{
fgModified = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be set to false by fgComputeDoms at the end of loop unrolling. It seems better to explicitly do it here, given the comment below on PHASE_OPT_UPDATE_FLOW_GRAPH.

(It seems a bit questionable not to run the phase if we loop cloned/unrolled -- I saw some beneficial diffs when I originally didn't have this.)


if (doSsa)
{
// Build up SSA form for the IR
Expand Down Expand Up @@ -5006,8 +5008,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
{
// update the flowgraph if we modified it during the optimization phase
//
// Note: this invalidates loops, dominators and reachability
//
DoPhase(this, PHASE_OPT_UPDATE_FLOW_GRAPH, &Compiler::fgUpdateFlowGraphPhase);

// Recompute the edge weight if we have modified the flow graph
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2029,12 +2029,15 @@ struct NaturalLoopIterInfo
int ConstInitValue = 0;

// Block outside the loop that initializes the induction variable. Only
// value if HasConstInit is true.
// valid if HasConstInit is true.
BasicBlock* InitBlock = nullptr;

// Tree that has the loop test for the induction variable.
GenTree* TestTree = nullptr;

// Block that has the loop test.
BasicBlock* TestBlock = nullptr;

// Tree that mutates the induction variable.
GenTree* IterTree = nullptr;

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 @@ -48,6 +48,7 @@ CompMemKindMacro(DebugOnly)
CompMemKindMacro(Codegen)
CompMemKindMacro(LoopOpt)
CompMemKindMacro(LoopClone)
CompMemKindMacro(LoopUnroll)
CompMemKindMacro(LoopHoist)
CompMemKindMacro(Unknown)
CompMemKindMacro(RangeCheck)
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/fgdiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,10 @@ void Compiler::fgDumpBlockMemorySsaIn(BasicBlock* block)
{
printf(" = m:%u\n", block->bbMemorySsaNumIn[memoryKind]);
}
else if (block->bbMemorySsaPhiFunc[memoryKind] == BasicBlock::EmptyMemoryPhiDef)
{
printf(" = phi([not filled])\n");
}
Comment on lines +2576 to +2579
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've hit crashes here a few times during JITDUMP when I've messed up the flow graph.

else
{
printf(" = phi(");
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5008,7 +5008,8 @@ bool FlowGraphNaturalLoop::AnalyzeIteration(NaturalLoopIterInfo* info)
return false;
}

info->IterVar = comp->optIsLoopIncrTree(info->IterTree);
info->TestBlock = cond;
info->IterVar = comp->optIsLoopIncrTree(info->IterTree);

assert(info->IterVar != BAD_VAR_NUM);
LclVarDsc* const iterVarDsc = comp->lvaGetDesc(info->IterVar);
Expand Down
Loading
Loading