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

Refactor computing lvaLongVars/lvaFloatVars #82331

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
3 changes: 3 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6138,6 +6138,9 @@ class Compiler
// written to, and SZ-array element type equivalence classes updated.
void optComputeLoopSideEffects();

// Compute the sets of long and float vars (lvaLongVars, lvaFloatVars).
void optComputeInterestingVarSets();

#ifdef DEBUG
bool optAnyChildNotRemoved(unsigned loopNum);
#endif // DEBUG
Expand Down
14 changes: 8 additions & 6 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6670,6 +6670,8 @@ PhaseStatus Compiler::optHoistLoopCode()
}
#endif

optComputeInterestingVarSets();

// Consider all the loop nests, in inner-to-outer order
//
bool modified = false;
Expand Down Expand Up @@ -6824,9 +6826,8 @@ bool Compiler::optHoistThisLoop(unsigned lnum, LoopHoistContext* hoistCtxt, Basi
pLoopDsc->lpHoistAddedPreheader = false;

#ifndef TARGET_64BIT
unsigned longVarsCount = VarSetOps::Count(this, lvaLongVars);

if (longVarsCount > 0)
if (!VarSetOps::IsEmpty(this, lvaLongVars))
{
// Since 64-bit variables take up two registers on 32-bit targets, we increase
// the Counts such that each TYP_LONG variable counts twice.
Expand Down Expand Up @@ -6861,9 +6862,7 @@ bool Compiler::optHoistThisLoop(unsigned lnum, LoopHoistContext* hoistCtxt, Basi
}
#endif

unsigned floatVarsCount = VarSetOps::Count(this, lvaFloatVars);

if (floatVarsCount > 0)
if (!VarSetOps::IsEmpty(this, lvaFloatVars))
Copy link
Member

Choose a reason for hiding this comment

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

It looks like lvaFloatVars doesn't account for SIMD variables (which end up in the same registers and I'd imagine have similar considerations). Is that expected and/or should they be tracked separately?

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 PR is simply a refactoring of existing code. I've opened #82351 to track this issue. It looks like SIMD type trees get treated as using int registers instead of float registers for the purpose of loop hoisting profitability.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Definitely not something I thought should be handled here, more just an observation/question of the code that was being refactored

{
VARSET_TP loopFPVars(VarSetOps::Intersection(this, loopVars, lvaFloatVars));
VARSET_TP inOutFPVars(VarSetOps::Intersection(this, pLoopDsc->lpVarInOut, lvaFloatVars));
Expand All @@ -6888,7 +6887,7 @@ bool Compiler::optHoistThisLoop(unsigned lnum, LoopHoistContext* hoistCtxt, Basi
}
#endif
}
else // (floatVarsCount == 0)
else // lvaFloatVars is empty
{
pLoopDsc->lpLoopVarFPCount = 0;
pLoopDsc->lpVarInOutFPCount = 0;
Expand Down Expand Up @@ -8489,7 +8488,10 @@ void Compiler::optComputeLoopSideEffects()
optComputeLoopNestSideEffects(lnum);
}
}
}

void Compiler::optComputeInterestingVarSets()
{
VarSetOps::AssignNoCopy(this, lvaFloatVars, VarSetOps::MakeEmpty(this));
#ifndef TARGET_64BIT
VarSetOps::AssignNoCopy(this, lvaLongVars, VarSetOps::MakeEmpty(this));
Expand Down