diff --git a/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test --- a/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test +++ b/llvm/test/tools/llvm-profgen/inline-cs-pseudoprobe.test @@ -11,8 +11,8 @@ ; CHECK-NEXT: !CFGChecksum: 138950591924 ; CHECK-NEXT:[main:2 @ foo:8 @ bar]:56:14 ; CHECK-NEXT: 1: 14 -; CHECK-NEXT: 2: 14 -; CHECK-NEXT: 3: 14 +; CHECK-NEXT: 2: 18446744073709551615 +; CHECK-NEXT: 3: 18446744073709551615 ; CHECK-NEXT: 4: 14 ; CHECK-NEXT: !CFGChecksum: 72617220756 diff --git a/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test b/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test --- a/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test +++ b/llvm/test/tools/llvm-profgen/noinline-cs-pseudoprobe.test @@ -10,8 +10,8 @@ ; CHECK-NEXT: !CFGChecksum: 138950591924 ; CHECK-NEXT:[main:2 @ foo:8 @ bar]:60:15 ; CHECK-NEXT: 1: 15 -; CHECK-NEXT: 2: 15 -; CHECK-NEXT: 3: 15 +; CHECK-NEXT: 2: 18446744073709551615 +; CHECK-NEXT: 3: 18446744073709551615 ; CHECK-NEXT: 4: 15 ; CHECK-NEXT: !CFGChecksum: 72617220756 diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -492,7 +492,16 @@ FunctionSamples &FunctionProfile = getFunctionProfileForLeafProbe(ContextStrStack, Probe, Binary); - FunctionProfile.addBodySamples(Probe->Index, 0, Count); + // Use UINT64_MAX to mark sample count for a dangling probe + // Dangling probes are the probes associated to an empty block. With this + // place holder, sample count on dangling probe will not be trusted by the + // compiler and it will rely on the counts inference algorithm to get the + // probe a reasonable count. + if (Probe->isDangling()) + FunctionProfile.addBodySamples(Probe->Index, 0, UINT64_MAX); + else + FunctionProfile.addBodySamples(Probe->Index, 0, Count); + FunctionProfile.addTotalSamples(Count); if (Probe->isEntry()) { FunctionProfile.addHeadSamples(Count);