Skip to content

Commit

Permalink
Lots of metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbotsch committed May 29, 2024
1 parent d0f8fd2 commit af98790
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/coreclr/jit/inductionvariableopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,13 +884,15 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
// With multiple exits we generally can only compute an upper bound on
// the trip count.
JITDUMP(" No; has multiple exits\n");
Metrics.TripCountMultipleExits++;
return false;
}

BasicBlock* exiting = loop->ExitEdge(0)->getSourceBlock();
if (!exiting->KindIs(BBJ_COND))
{
JITDUMP(" No; exit is not BBJ_COND\n");
Metrics.TripCountExitNotCond++;
return false;
}

Expand All @@ -905,6 +907,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
// transform; otherwise we could. TODO-CQ: Make this determination and
// extract side effects from the jtrue to make this work.
JITDUMP(" No; exit node has side effects\n");
Metrics.TripCountExitSideEffects++;
return false;
}

Expand All @@ -914,6 +917,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
(cond->gtGetOp1()->IsIntegralConst(0) || cond->gtGetOp2()->IsIntegralConst(0)))
{
JITDUMP(" No; operand of condition [%06u] is already 0\n", dspTreeID(cond));
Metrics.TripCountExitAlreadyHas0++;
return false;
}

Expand Down Expand Up @@ -970,18 +974,21 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
if (!rootNode->OperIsLocalStore())
{
// Cannot reason about this use of the local, cannot remove
Metrics.TripCountNonStoreUse++;
return false;
}

if (rootNode->AsLclVarCommon()->GetLclNum() != candidateLclNum)
{
// Used to compute a value stored to some other local, cannot remove
Metrics.TripCountStoredFrom++;
return false;
}

if ((rootNode->AsLclVarCommon()->Data()->gtFlags & GTF_SIDE_EFFECT) != 0)
{
// May be used inside the data node for something that has side effects, cannot remove
Metrics.TripCountStoreMayHaveSideEffect++;
return false;
}

Expand All @@ -1007,6 +1014,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,

if (checkProfitability && (removableLocals.Height() <= 0))
{
Metrics.TripCountNoRemovableLocals++;
JITDUMP(" Found no potentially removable locals when making this loop downwards counted\n");
return false;
}
Expand All @@ -1031,6 +1039,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
{
JITDUMP(" No; exiting block " FMT_BB " is not an ancestor of backedge source " FMT_BB "\n",
exiting->bbNum, backedge->getSourceBlock()->bbNum);
Metrics.TripCountBackedgesNotDominated++;
return false;
}

Expand All @@ -1043,6 +1052,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
{
JITDUMP(" No; exiting block " FMT_BB " does not dominate backedge source " FMT_BB "\n", exiting->bbNum,
backedge->getSourceBlock()->bbNum);
Metrics.TripCountBackedgesNotDominated++;
return false;
}
}
Expand All @@ -1055,6 +1065,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
if (tripCount == nullptr)
{
JITDUMP(" Could not compute trip count -- not a counted loop\n");
Metrics.TripCountCouldNotCompute++;
return false;
}

Expand All @@ -1070,6 +1081,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
if (decCountNode == nullptr)
{
JITDUMP(" Could not materialize trip count into IR\n");
Metrics.TripCountCouldNotMaterialize++;
return false;
}

Expand Down
20 changes: 20 additions & 0 deletions src/coreclr/jit/jitmetadatalist.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ JITMETADATAMETRIC(ProfileInconsistentInlineeScale, int, 0)
JITMETADATAMETRIC(ProfileInconsistentInlinee, int, 0)
JITMETADATAMETRIC(ProfileInconsistentNoReturnInlinee, int, 0)
JITMETADATAMETRIC(ProfileInconsistentMayThrowInlinee, int, 0)
JITMETADATAMETRIC(TripCountMultipleExits, int, 0)
JITMETADATAMETRIC(TripCountExitNotCond, int, 0)
JITMETADATAMETRIC(TripCountExitSideEffects, int, 0)
JITMETADATAMETRIC(TripCountExitAlreadyHas0, int, 0)
JITMETADATAMETRIC(TripCountNonStoreUse, int, 0)
JITMETADATAMETRIC(TripCountStoredFrom, int, 0)
JITMETADATAMETRIC(TripCountStoreMayHaveSideEffect, int, 0)
JITMETADATAMETRIC(TripCountNoRemovableLocals, int, 0)
JITMETADATAMETRIC(TripCountBackedgesNotDominated, int, 0)
JITMETADATAMETRIC(TripCountCouldNotCompute, int, 0)
JITMETADATAMETRIC(TripCountCouldNotMaterialize, int, 0)
JITMETADATAMETRIC(TripCountUnsupportedCondOper, int, 0)
JITMETADATAMETRIC(TripCountNotIntegral, int, 0)
JITMETADATAMETRIC(TripCountCouldNotAnalyzeOperands, int, 0)
JITMETADATAMETRIC(TripCountGCOperand, int, 0)
JITMETADATAMETRIC(TripCountNoAddRec, int, 0)
JITMETADATAMETRIC(TripCountOperandVarianceMatch, int, 0)
JITMETADATAMETRIC(TripCountOverflowBeforeExit, int, 0)
JITMETADATAMETRIC(TripCountCouldNotProveLowerBound, int, 0)
JITMETADATAMETRIC(TripCountStepNotOne, int, 0)

#undef JITMETADATA
#undef JITMETADATAINFO
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/jit/scev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,11 +1563,13 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)
if (!cond->OperIs(GT_LT, GT_LE, GT_GT, GT_GE))
{
// TODO-CQ: We can handle EQ/NE with divisibility checks.
m_comp->Metrics.TripCountUnsupportedCondOper++;
return nullptr;
}

if (!varTypeIsIntegralOrI(cond->gtGetOp1()))
{
m_comp->Metrics.TripCountNotIntegral++;
return nullptr;
}

Expand All @@ -1576,12 +1578,14 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)

if ((op1 == nullptr) || (op2 == nullptr))
{
m_comp->Metrics.TripCountCouldNotAnalyzeOperands++;
return nullptr;
}

if (varTypeIsGC(op1->Type) || varTypeIsGC(op2->Type))
{
// TODO-CQ: Add SUB operator
m_comp->Metrics.TripCountGCOperand++;
return nullptr;
}

Expand All @@ -1600,6 +1604,7 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)
{
// If both are invariant we could still handle some cases here (it will
// be 0 or infinite). Probably uncommon.
m_comp->Metrics.TripCountNoAddRec++;
return nullptr;
}

Expand All @@ -1610,6 +1615,7 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)
{
// Both variant. Here we could also prove also try to prove some cases,
// but again this is expected to be uncommon.
m_comp->Metrics.TripCountOperandVarianceMatch++;
return nullptr;
}

Expand Down Expand Up @@ -1654,6 +1660,7 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)
if (MayOverflowBeforeExit((ScevAddRec*)lhs, rhs, exitOpVNF))
{
JITDUMP(" May overflow, cannot determine trip count\n");
m_comp->Metrics.TripCountOverflowBeforeExit++;
return nullptr;
}

Expand Down Expand Up @@ -1732,6 +1739,7 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)

if (result != RelopEvaluationResult::True)
{
m_comp->Metrics.TripCountCouldNotProveLowerBound++;
return nullptr;
}

Expand All @@ -1740,6 +1748,7 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)
if (!divisor->GetConstantValue(m_comp, &divisorVal) || ((divisorVal != 1) && (divisorVal != -1)))
{
// TODO-CQ: Enable. Likely need to add a division operator to SCEV.
m_comp->Metrics.TripCountStepNotOne++;
return nullptr;
}

Expand Down

0 comments on commit af98790

Please sign in to comment.