From fb9274a2dd65261d5358db353a95a2d2315f9ce0 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Mon, 17 Apr 2017 16:00:51 -0700 Subject: [PATCH] Hoist calls to NumSucc() out of loops Should be a minor throughput improvement. Commit migrated from https://github.com/dotnet/coreclr/commit/f503a568fd54d423510323921bb9065e398471e2 --- src/coreclr/src/jit/importer.cpp | 15 ++++++++++----- src/coreclr/src/jit/lsra.cpp | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 989130a..80fa143 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -15426,7 +15426,8 @@ inline void Compiler::impReimportMarkBlock(BasicBlock* block) void Compiler::impReimportMarkSuccessors(BasicBlock* block) { - for (unsigned i = 0; i < block->NumSucc(); i++) + const unsigned numSuccs = block->NumSucc(); + for (unsigned i = 0; i < numSuccs; i++) { impReimportMarkBlock(block->GetSucc(i)); } @@ -15601,7 +15602,8 @@ void Compiler::impImportBlock(BasicBlock* block) JITDUMP("Marking BBF_INTERNAL block BB%02u as BBF_IMPORTED\n", block->bbNum); block->bbFlags |= BBF_IMPORTED; - for (unsigned i = 0; i < block->NumSucc(); i++) + const unsigned numSuccs = block->NumSucc(); + for (unsigned i = 0; i < numSuccs; i++) { impImportBlockPending(block->GetSucc(i)); } @@ -16028,7 +16030,8 @@ SPILLSTACK: impReimportSpillClique(block); // For blocks that haven't been imported yet, we still need to mark them as pending import. - for (unsigned i = 0; i < block->NumSucc(); i++) + const unsigned numSuccs = block->NumSucc(); + for (unsigned i = 0; i < numSuccs; i++) { BasicBlock* succ = block->GetSucc(i); if ((succ->bbFlags & BBF_IMPORTED) == 0) @@ -16042,7 +16045,8 @@ SPILLSTACK: // otherwise just import the successors of block /* Does this block jump to any other blocks? */ - for (unsigned i = 0; i < block->NumSucc(); i++) + const unsigned numSuccs = block->NumSucc(); + for (unsigned i = 0; i < numSuccs; i++) { impImportBlockPending(block->GetSucc(i)); } @@ -16299,7 +16303,8 @@ void Compiler::impWalkSpillCliqueFromPred(BasicBlock* block, SpillCliqueWalker* BasicBlock* blk = node->m_blk; FreeBlockListNode(node); - for (unsigned succNum = 0; succNum < blk->NumSucc(); succNum++) + const unsigned numSuccs = blk->NumSucc(); + for (unsigned succNum = 0; succNum < numSuccs; succNum++) { BasicBlock* succ = blk->GetSucc(succNum); // If it's not already in the clique, add it, and also add it diff --git a/src/coreclr/src/jit/lsra.cpp b/src/coreclr/src/jit/lsra.cpp index e7c1c83..5576140 100644 --- a/src/coreclr/src/jit/lsra.cpp +++ b/src/coreclr/src/jit/lsra.cpp @@ -1378,7 +1378,8 @@ void LinearScan::setBlockSequence() assert(!"Switch with single successor"); } - for (unsigned succIndex = 0; succIndex < block->NumSucc(compiler); succIndex++) + const unsigned numSuccs = block->NumSucc(compiler); + for (unsigned succIndex = 0; succIndex < numSuccs; succIndex++) { BasicBlock* succ = block->GetSucc(succIndex, compiler); if (checkForCriticalOutEdge && succ->GetUniquePred(compiler) == nullptr) -- 2.7.4