diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -530,13 +530,10 @@ for (uint32_t S = 0; S < NS; S++) { uint32_t ND = Func.getNumValueDataForSite(VK, S); std::unique_ptr VD = Func.getValueForSite(VK, S); - bool WasZero = false; + DenseSet SeenValues; for (uint32_t I = 0; I < ND; I++) - if ((VK != IPVK_IndirectCallTarget) && (VD[I].Value == 0)) { - if (WasZero) - return make_error(instrprof_error::invalid_prof); - WasZero = true; - } + if ((VK != IPVK_IndirectCallTarget) && !SeenValues.insert(VD[I].Value).second) + return make_error(instrprof_error::invalid_prof); } } diff --git a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp --- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp @@ -291,9 +291,9 @@ uint64_t SavedRemainCount = SavedTotalCount; SmallVector SizeIds; SmallVector CaseCounts; + SmallDenseSet SeenSizeId; uint64_t MaxCount = 0; unsigned Version = 0; - int64_t LastV = -1; // Default case is in the front -- save the slot here. CaseCounts.push_back(0); SmallVector RemainingVDs; @@ -316,15 +316,12 @@ break; } - if (V == LastV) { - LLVM_DEBUG(dbgs() << "Invalid Profile Data in Function " << Func.getName() - << ": Two consecutive, identical values in MemOp value" - "counts.\n"); + if (!SeenSizeId.insert(V).second) { + errs() << "Invalid Profile Data in Function " << Func.getName() + << ": Two identical values in MemOp value counts.\n"; return false; } - LastV = V; - SizeIds.push_back(V); CaseCounts.push_back(C); if (C > MaxCount) diff --git a/llvm/test/Transforms/PGOProfile/consecutive-zeros.ll b/llvm/test/Transforms/PGOProfile/consecutive-zeros.ll --- a/llvm/test/Transforms/PGOProfile/consecutive-zeros.ll +++ b/llvm/test/Transforms/PGOProfile/consecutive-zeros.ll @@ -1,6 +1,5 @@ -; REQUIRES: asserts ; RUN: llvm-profdata merge %S/Inputs/consecutive-zeros.proftext -o %t.profdata -; RUN: opt < %s -debug -passes=pgo-instr-use,pgo-memop-opt -pgo-memop-count-threshold=0 -pgo-memop-percent-threshold=0 -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s +; RUN: opt < %s -passes=pgo-instr-use,pgo-memop-opt -pgo-memop-count-threshold=0 -pgo-memop-percent-threshold=0 -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu"