Index: llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext =================================================================== --- /dev/null +++ llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext @@ -0,0 +1,18 @@ +:ir +foo +7 +1 +0 + +goo +5 +3 +0 +0 +0 + +moo +9 +1 +0 + Index: llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test =================================================================== --- llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test +++ llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test @@ -64,21 +64,21 @@ RUN: llvm-profdata merge \ RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \ RUN: -suppl-min-size-threshold=2 -zero-counter-threshold=0.7 \ -RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr.proftext -o %t +RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr_small.proftext -o %t RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=MIX4 MIX4: foo: MIX4-NEXT: Hash: 0x0000000000000007 -MIX4-NEXT: Counters: 5 -MIX4-NEXT: Block counts: [12, 13, 0, 0, 0] +MIX4-NEXT: Counters: 1 +MIX4-NEXT: Block counts: [0] MIX4: goo: MIX4-NEXT: Hash: 0x0000000000000005 MIX4-NEXT: Counters: 3 MIX4-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615] MIX4: moo: MIX4-NEXT: Hash: 0x0000000000000009 -MIX4-NEXT: Counters: 4 -MIX4-NEXT: Block counts: [3000, 1000, 2000, 500] +MIX4-NEXT: Counters: 1 +MIX4-NEXT: Block counts: [0] Test profile summary won't be affected by -1 counter. RUN: llvm-profdata merge \ Index: llvm/tools/llvm-profdata/llvm-profdata.cpp =================================================================== --- llvm/tools/llvm-profdata/llvm-profdata.cpp +++ llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -461,6 +461,7 @@ /// The profile entry for a function in instrumentation profile. struct InstrProfileEntry { uint64_t MaxCount = 0; + uint64_t NumEdgeCounters = 0; float ZeroCounterRatio = 0.0; InstrProfRecord *ProfRecord; InstrProfileEntry(InstrProfRecord *Record); @@ -476,6 +477,7 @@ ZeroCntNum += !Record->Counts[I]; } ZeroCounterRatio = (float)ZeroCntNum / CntNum; + NumEdgeCounters = CntNum; } /// Either set all the counters in the instr profile entry \p IFE to -1 @@ -584,10 +586,10 @@ auto &FContext = PD.first; const sampleprof::FunctionSamples &FS = PD.second; auto It = InstrProfileMap.find(FContext.toString()); - if (FS.getHeadSamples() > ColdSampleThreshold && + if (FS.getMaxCountInside() > ColdSampleThreshold && It != InstrProfileMap.end() && It->second.MaxCount <= ColdInstrThreshold && - FS.getBodySamples().size() >= SupplMinSizeThreshold) { + It->second.NumEdgeCounters >= SupplMinSizeThreshold) { updateInstrProfileEntry(It->second, HotInstrThreshold, ZeroCounterThreshold); }