Skip to content

Commit

Permalink
Skip FP registers processing if method don't have floating points use (
Browse files Browse the repository at this point in the history
…#85744)

* skip processing floating point registers if method doesn't have one

* Rename to needNonIntegerRegisters

* jit format
  • Loading branch information
kunalspathak authored May 6, 2023
1 parent e61e022 commit 8854509
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ void Compiler::impPushOnStack(GenTree* tree, typeInfo ti)
verCurrentState.esStack[verCurrentState.esStackDepth].seTypeInfo = ti;
verCurrentState.esStack[verCurrentState.esStackDepth++].val = tree;

if ((tree->gtType == TYP_LONG) && (compLongUsed == false))
if (tree->gtType == TYP_LONG)
{
compLongUsed = true;
}
else if (((tree->gtType == TYP_FLOAT) || (tree->gtType == TYP_DOUBLE)) && (compFloatingPointUsed == false))
else if ((tree->gtType == TYP_FLOAT) || (tree->gtType == TYP_DOUBLE))
{
compFloatingPointUsed = true;
}
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ void LinearScan::updateRegsFreeBusyState(RefPosition& refPosition,

regMaskTP LinearScan::internalFloatRegCandidates()
{
needNonIntegerRegisters = true;

if (compiler->compFloatingPointUsed)
{
return availableFloatRegs;
Expand Down Expand Up @@ -686,13 +688,15 @@ LinearScan::LinearScan(Compiler* theCompiler)
, refPositions(theCompiler->getAllocator(CMK_LSRA_RefPosition))
, listNodePool(theCompiler)
{
availableRegCount = ACTUAL_REG_COUNT;
needNonIntegerRegisters = false;

#if defined(TARGET_XARCH)
availableRegCount = ACTUAL_REG_COUNT;

#if defined(TARGET_AMD64)
rbmAllFloat = compiler->rbmAllFloat;
rbmFltCalleeTrash = compiler->rbmFltCalleeTrash;
#endif
#endif // TARGET_AMD64

if (!compiler->canUseEvexEncoding())
{
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/lsra.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ class LinearScan : public LinearScanInterface
unsigned int currentSpill[TYP_COUNT];
bool needFloatTmpForFPCall;
bool needDoubleTmpForFPCall;
bool needNonIntegerRegisters;

#ifdef DEBUG
private:
Expand Down Expand Up @@ -2041,13 +2042,14 @@ class LinearScan : public LinearScanInterface
}
#endif // TARGET_AMD64

#endif // TARGET_XARCH

unsigned availableRegCount;

unsigned get_AVAILABLE_REG_COUNT() const
{
return this->availableRegCount;
}
#endif // TARGET_XARCH

//------------------------------------------------------------------------
// calleeSaveRegs: Get the set of callee-save registers of the given RegisterType
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,14 @@ void LinearScan::buildPhysRegRecords()
RegRecord* curr = &physRegs[reg];
curr->regOrder = (unsigned char)i;
}

// TODO-CQ: We build physRegRecords before building intervals
// and refpositions. During building intervals/refposition, we
// would know if there are floating points used. If we can know
// that information before we build intervals, we can skip
// initializing the floating registers.
// For that `compFloatingPointUsed` should be set accurately
// before invoking allocator.
for (unsigned int i = 0; i < lsraRegOrderFltSize; i++)
{
regNumber reg = lsraRegOrderFlt[i];
Expand Down Expand Up @@ -2727,6 +2735,12 @@ void LinearScan::buildIntervals()
RefPosition* pos = newRefPosition((Interval*)nullptr, currentLoc, RefTypeBB, nullptr, RBM_NONE);
}

needNonIntegerRegisters |= compiler->compFloatingPointUsed;
if (!needNonIntegerRegisters)
{
availableRegCount = REG_INT_COUNT;
}

#ifdef DEBUG
// Make sure we don't have any blocks that were not visited
for (BasicBlock* const block : compiler->Blocks())
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/jit/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,7 @@ enum _regMask_enum : unsigned
#error Unsupported target architecture
#endif

#if defined(TARGET_XARCH)
// AVAILABLE_REG_COUNT is defined to be dynamic, based on whether AVX-512 high registers are available.
#define AVAILABLE_REG_COUNT get_AVAILABLE_REG_COUNT()
#else
#define AVAILABLE_REG_COUNT ACTUAL_REG_COUNT
#endif

/*****************************************************************************/

Expand Down

0 comments on commit 8854509

Please sign in to comment.