From 8854509eac45da4fe3f7843599133aa2a6d1beaf Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 5 May 2023 20:37:52 -0700 Subject: [PATCH] Skip FP registers processing if method don't have floating points use (#85744) * skip processing floating point registers if method doesn't have one * Rename to needNonIntegerRegisters * jit format --- src/coreclr/jit/importer.cpp | 4 ++-- src/coreclr/jit/lsra.cpp | 8 ++++++-- src/coreclr/jit/lsra.h | 4 +++- src/coreclr/jit/lsrabuild.cpp | 14 ++++++++++++++ src/coreclr/jit/target.h | 5 ----- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 1c3fb163d1987..e212041d1bba6 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -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; } diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index d803ae8fcaff5..617c6016bc5a5 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -418,6 +418,8 @@ void LinearScan::updateRegsFreeBusyState(RefPosition& refPosition, regMaskTP LinearScan::internalFloatRegCandidates() { + needNonIntegerRegisters = true; + if (compiler->compFloatingPointUsed) { return availableFloatRegs; @@ -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()) { diff --git a/src/coreclr/jit/lsra.h b/src/coreclr/jit/lsra.h index d869f8f8a126c..a5e79ebfab51c 100644 --- a/src/coreclr/jit/lsra.h +++ b/src/coreclr/jit/lsra.h @@ -733,6 +733,7 @@ class LinearScan : public LinearScanInterface unsigned int currentSpill[TYP_COUNT]; bool needFloatTmpForFPCall; bool needDoubleTmpForFPCall; + bool needNonIntegerRegisters; #ifdef DEBUG private: @@ -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 diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index 0f11acdadb701..2e97c8c4bc7da 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -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]; @@ -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()) diff --git a/src/coreclr/jit/target.h b/src/coreclr/jit/target.h index ad7e5be605199..4e385d323a7d8 100644 --- a/src/coreclr/jit/target.h +++ b/src/coreclr/jit/target.h @@ -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 /*****************************************************************************/