diff --git a/src/coreclr/jit/runtimelookup.cpp b/src/coreclr/jit/runtimelookup.cpp index 325ca9956a2171..e2209b54e1d4dd 100644 --- a/src/coreclr/jit/runtimelookup.cpp +++ b/src/coreclr/jit/runtimelookup.cpp @@ -224,7 +224,6 @@ PhaseStatus Compiler::fgExpandRuntimeLookups() } GenTree* ctxTree = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* sigNode = call->gtArgs.GetArgByIndex(1)->GetNode(); // Prepare slotPtr tree (TODO: consider sharing this part with impRuntimeLookup) GenTree* slotPtrTree = gtCloneExpr(ctxTree); @@ -275,11 +274,11 @@ PhaseStatus Compiler::fgExpandRuntimeLookups() // if (*fastPathValue == null) // goto fallbackBb; // - // fastPathBb(BBJ_ALWAYS): [weight: 0.8] + // fastPathBb(BBJ_ALWAYS): [weight: 1.0] // rtLookupLcl = *fastPathValue; // goto block; // - // fallbackBb(BBJ_NONE): [weight: 0.2] + // fallbackBb(BBJ_NONE): [weight: 0.0] // rtLookupLcl = HelperCall(); // // block(...): [weight: 1.0] @@ -320,15 +319,15 @@ PhaseStatus Compiler::fgExpandRuntimeLookups() // goto fallbackBb; // ... // - // nullcheckBb(BBJ_COND): [weight: 0.8] + // nullcheckBb(BBJ_COND): [weight: 1.0] // if (*fastPathValue == null) // goto fallbackBb; // - // fastPathBb(BBJ_ALWAYS): [weight: 0.64] + // fastPathBb(BBJ_ALWAYS): [weight: 1.0] // rtLookupLcl = *fastPathValue; // goto block; // - // fallbackBb(BBJ_NONE): [weight: 0.36] + // fallbackBb(BBJ_NONE): [weight: 0.0] // rtLookupLcl = HelperCall(); // // block(...): [weight: 1.0] @@ -387,27 +386,15 @@ PhaseStatus Compiler::fgExpandRuntimeLookups() // // Re-distribute weights (see '[weight: X]' on the diagrams above) - // TODO: consider marking fallbackBb as rarely-taken // block->inheritWeight(prevBb); if (needsSizeCheck) { sizeCheckBb->inheritWeight(prevBb); - // 80% chance we pass nullcheck - nullcheckBb->inheritWeightPercentage(sizeCheckBb, 80); - // 64% (0.8 * 0.8) chance we pass both nullcheck and sizecheck - fastPathBb->inheritWeightPercentage(nullcheckBb, 80); - // 100-64=36% chance we fail either nullcheck or sizecheck - fallbackBb->inheritWeightPercentage(sizeCheckBb, 36); - } - else - { - nullcheckBb->inheritWeight(prevBb); - // 80% chance we pass nullcheck - fastPathBb->inheritWeightPercentage(nullcheckBb, 80); - // 20% chance we fail nullcheck (TODO: Consider making it cold (0%)) - fallbackBb->inheritWeightPercentage(nullcheckBb, 20); } + nullcheckBb->inheritWeight(prevBb); + fastPathBb->inheritWeight(prevBb); + fallbackBb->bbSetRunRarely(); // // Update loop info if loop table is known to be valid @@ -437,6 +424,12 @@ PhaseStatus Compiler::fgExpandRuntimeLookups() assert(BasicBlock::sameEHRegion(prevBb, sizeCheckBb)); } + // Merge prevBb with nullcheckBb (or sizeBb) if possible to simplify layout + if (fgCanCompactBlocks(prevBb, prevBb->GetUniqueSucc())) + { + fgCompactBlocks(prevBb, prevBb->GetUniqueSucc()); + } + // Scan current block again, the current call will be ignored because of ClearExpRuntimeLookup. // We don't try to re-use expansions for the same lookups in the current block here - CSE is responsible // for that @@ -447,14 +440,5 @@ PhaseStatus Compiler::fgExpandRuntimeLookups() } } } - - if (result == PhaseStatus::MODIFIED_EVERYTHING) - { - if (opts.OptimizationEnabled()) - { - fgReorderBlocks(/* useProfileData */ false); - fgUpdateChangedFlowGraph(FlowGraphUpdates::COMPUTE_BASICS); - } - } return result; }