Skip to content

Commit af98790

Browse files
committed
Lots of metrics
1 parent d0f8fd2 commit af98790

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/coreclr/jit/inductionvariableopts.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -884,13 +884,15 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
884884
// With multiple exits we generally can only compute an upper bound on
885885
// the trip count.
886886
JITDUMP(" No; has multiple exits\n");
887+
Metrics.TripCountMultipleExits++;
887888
return false;
888889
}
889890

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

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

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

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

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

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

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

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

@@ -1043,6 +1052,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
10431052
{
10441053
JITDUMP(" No; exiting block " FMT_BB " does not dominate backedge source " FMT_BB "\n", exiting->bbNum,
10451054
backedge->getSourceBlock()->bbNum);
1055+
Metrics.TripCountBackedgesNotDominated++;
10461056
return false;
10471057
}
10481058
}
@@ -1055,6 +1065,7 @@ bool Compiler::optMakeLoopDownwardsCounted(ScalarEvolutionContext& scevContext,
10551065
if (tripCount == nullptr)
10561066
{
10571067
JITDUMP(" Could not compute trip count -- not a counted loop\n");
1068+
Metrics.TripCountCouldNotCompute++;
10581069
return false;
10591070
}
10601071

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

src/coreclr/jit/jitmetadatalist.h

+20
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ JITMETADATAMETRIC(ProfileInconsistentInlineeScale, int, 0)
7171
JITMETADATAMETRIC(ProfileInconsistentInlinee, int, 0)
7272
JITMETADATAMETRIC(ProfileInconsistentNoReturnInlinee, int, 0)
7373
JITMETADATAMETRIC(ProfileInconsistentMayThrowInlinee, int, 0)
74+
JITMETADATAMETRIC(TripCountMultipleExits, int, 0)
75+
JITMETADATAMETRIC(TripCountExitNotCond, int, 0)
76+
JITMETADATAMETRIC(TripCountExitSideEffects, int, 0)
77+
JITMETADATAMETRIC(TripCountExitAlreadyHas0, int, 0)
78+
JITMETADATAMETRIC(TripCountNonStoreUse, int, 0)
79+
JITMETADATAMETRIC(TripCountStoredFrom, int, 0)
80+
JITMETADATAMETRIC(TripCountStoreMayHaveSideEffect, int, 0)
81+
JITMETADATAMETRIC(TripCountNoRemovableLocals, int, 0)
82+
JITMETADATAMETRIC(TripCountBackedgesNotDominated, int, 0)
83+
JITMETADATAMETRIC(TripCountCouldNotCompute, int, 0)
84+
JITMETADATAMETRIC(TripCountCouldNotMaterialize, int, 0)
85+
JITMETADATAMETRIC(TripCountUnsupportedCondOper, int, 0)
86+
JITMETADATAMETRIC(TripCountNotIntegral, int, 0)
87+
JITMETADATAMETRIC(TripCountCouldNotAnalyzeOperands, int, 0)
88+
JITMETADATAMETRIC(TripCountGCOperand, int, 0)
89+
JITMETADATAMETRIC(TripCountNoAddRec, int, 0)
90+
JITMETADATAMETRIC(TripCountOperandVarianceMatch, int, 0)
91+
JITMETADATAMETRIC(TripCountOverflowBeforeExit, int, 0)
92+
JITMETADATAMETRIC(TripCountCouldNotProveLowerBound, int, 0)
93+
JITMETADATAMETRIC(TripCountStepNotOne, int, 0)
7494

7595
#undef JITMETADATA
7696
#undef JITMETADATAINFO

src/coreclr/jit/scev.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1563,11 +1563,13 @@ Scev* ScalarEvolutionContext::ComputeExitNotTakenCount(BasicBlock* exiting)
15631563
if (!cond->OperIs(GT_LT, GT_LE, GT_GT, GT_GE))
15641564
{
15651565
// TODO-CQ: We can handle EQ/NE with divisibility checks.
1566+
m_comp->Metrics.TripCountUnsupportedCondOper++;
15661567
return nullptr;
15671568
}
15681569

15691570
if (!varTypeIsIntegralOrI(cond->gtGetOp1()))
15701571
{
1572+
m_comp->Metrics.TripCountNotIntegral++;
15711573
return nullptr;
15721574
}
15731575

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

15771579
if ((op1 == nullptr) || (op2 == nullptr))
15781580
{
1581+
m_comp->Metrics.TripCountCouldNotAnalyzeOperands++;
15791582
return nullptr;
15801583
}
15811584

15821585
if (varTypeIsGC(op1->Type) || varTypeIsGC(op2->Type))
15831586
{
15841587
// TODO-CQ: Add SUB operator
1588+
m_comp->Metrics.TripCountGCOperand++;
15851589
return nullptr;
15861590
}
15871591

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

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

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

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

17331740
if (result != RelopEvaluationResult::True)
17341741
{
1742+
m_comp->Metrics.TripCountCouldNotProveLowerBound++;
17351743
return nullptr;
17361744
}
17371745

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

0 commit comments

Comments
 (0)