diff --git a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test --- a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test +++ b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test @@ -10,13 +10,14 @@ ; CHECK: 1: 14 ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Range Counter: -; CHECK-UNWINDER: main:1 @ foo:3.2 @ bar -; CHECK-UNWINDER: (6af, 6bb): 14 ; CHECK-UNWINDER: main:1 @ foo ; CHECK-UNWINDER: (670, 6ad): 1 ; CHECK-UNWINDER: (67e, 69b): 1 ; CHECK-UNWINDER: (67e, 6ad): 13 ; CHECK-UNWINDER: (6bd, 6c8): 14 +; CHECK-UNWINDER: main:1 @ foo:3.2 @ bar +; CHECK-UNWINDER: (6af, 6bb): 14 + ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Branch Counter: ; CHECK-UNWINDER: main:1 @ foo diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -199,7 +199,10 @@ } static void printSampleCounter(ContextRangeCounter &Counter) { - for (auto Range : Counter) { + // Use ordered map to make the output deterministic + std::map OrderedCounter(Counter.begin(), + Counter.end()); + for (auto Range : OrderedCounter) { outs() << Range.first << "\n"; for (auto I : Range.second) { outs() << " (" << format("%" PRIx64, I.first.first) << ", "