Index: clang/test/CodeGenCXX/Inputs/profile-remap_entry.proftext =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/Inputs/profile-remap_entry.proftext @@ -0,0 +1,8 @@ +:ir +:entry_first +_ZN3Foo8functionENS_1XE +29667547796 +2 +100 +90 + Index: clang/test/CodeGenCXX/profile-remap.cpp =================================================================== --- clang/test/CodeGenCXX/profile-remap.cpp +++ clang/test/CodeGenCXX/profile-remap.cpp @@ -3,6 +3,8 @@ // RUN: %clang_cc1 -triple x86_64-linux-gnu -fprofile-sample-use=%S/Inputs/profile-remap.samples -fprofile-remapping-file=%S/Inputs/profile-remap.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-SAMPLES // RUN: llvm-profdata merge -output %T.profdata %S/Inputs/profile-remap.proftext // RUN: %clang_cc1 -triple x86_64-linux-gnu -fprofile-instrument-use-path=%T.profdata -fprofile-remapping-file=%S/Inputs/profile-remap.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-INSTR +// RUN: llvm-profdata merge -output %T.profdata %S/Inputs/profile-remap_entry.proftext +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fprofile-instrument-use-path=%T.profdata -fprofile-remapping-file=%S/Inputs/profile-remap.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-INSTR namespace Foo { struct X {}; Index: clang/test/Profile/Inputs/gcc-flag-compatibility_IR_entry.proftext =================================================================== --- /dev/null +++ clang/test/Profile/Inputs/gcc-flag-compatibility_IR_entry.proftext @@ -0,0 +1,12 @@ +# IR level Instrumentation Flag +:ir +:entry_first +main +# Func Hash: +34137660316 +# Num Counters: +2 +# Counter Values: +1 +100 + Index: clang/test/Profile/gcc-flag-compatibility.c =================================================================== --- clang/test/Profile/gcc-flag-compatibility.c +++ clang/test/Profile/gcc-flag-compatibility.c @@ -49,6 +49,10 @@ // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility_IR.proftext -o %t.dir/some/path/file.prof // RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE-IR %s // RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE-IR %s +// +// RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility_IR_entry.proftext -o %t.dir/some/path/file.prof +// RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE-IR %s +// RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE-IR %s // PROFILE-USE-IR: = !{!"branch_weights", i32 100, i32 1} Index: llvm/include/llvm/ProfileData/InstrProf.h =================================================================== --- llvm/include/llvm/ProfileData/InstrProf.h +++ llvm/include/llvm/ProfileData/InstrProf.h @@ -1146,7 +1146,8 @@ // Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime // aware this is an ir_level profile so it can set the version flag. -void createIRLevelProfileFlagVar(Module &M, bool IsCS); +void createIRLevelProfileFlagVar(Module &M, bool IsCS, + bool InstrEntryBBEnabled); // Create the variable for the profile file name. void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput); Index: llvm/include/llvm/ProfileData/InstrProfData.inc =================================================================== --- llvm/include/llvm/ProfileData/InstrProfData.inc +++ llvm/include/llvm/ProfileData/InstrProfData.inc @@ -673,6 +673,7 @@ #define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL) #define VARIANT_MASK_IR_PROF (0x1ULL << 56) #define VARIANT_MASK_CSIR_PROF (0x1ULL << 57) +#define VARIANT_MASK_INSTR_ENTRY (0x1ULL << 58) #define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version #define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime Index: llvm/include/llvm/ProfileData/InstrProfReader.h =================================================================== --- llvm/include/llvm/ProfileData/InstrProfReader.h +++ llvm/include/llvm/ProfileData/InstrProfReader.h @@ -79,6 +79,8 @@ virtual bool hasCSIRLevelProfile() const = 0; + virtual bool instrEntryBBEnabled() const = 0; + /// Return the PGO symtab. There are three different readers: /// Raw, Text, and Indexed profile readers. The first two types /// of readers are used only by llvm-profdata tool, while the indexed @@ -148,6 +150,7 @@ line_iterator Line; bool IsIRLevelProfile = false; bool HasCSIRLevelProfile = false; + bool InstrEntryBBEnabled = false; Error readValueProfileData(InstrProfRecord &Record); @@ -164,6 +167,8 @@ bool hasCSIRLevelProfile() const override { return HasCSIRLevelProfile; } + bool instrEntryBBEnabled() const override { return InstrEntryBBEnabled; } + /// Read the header. Error readHeader() override; @@ -224,6 +229,10 @@ return (Version & VARIANT_MASK_CSIR_PROF) != 0; } + bool instrEntryBBEnabled() const override { + return (Version & VARIANT_MASK_INSTR_ENTRY) != 0; + } + InstrProfSymtab &getSymtab() override { assert(Symtab.get()); return *Symtab.get(); @@ -360,6 +369,7 @@ virtual uint64_t getVersion() const = 0; virtual bool isIRLevelProfile() const = 0; virtual bool hasCSIRLevelProfile() const = 0; + virtual bool instrEntryBBEnabled() const = 0; virtual Error populateSymtab(InstrProfSymtab &) = 0; }; @@ -408,6 +418,10 @@ return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0; } + bool instrEntryBBEnabled() const override { + return (FormatVersion & VARIANT_MASK_INSTR_ENTRY) != 0; + } + Error populateSymtab(InstrProfSymtab &Symtab) override { return Symtab.create(HashTable->keys()); } @@ -462,6 +476,10 @@ return Index->hasCSIRLevelProfile(); } + bool instrEntryBBEnabled() const override { + return Index->instrEntryBBEnabled(); + } + /// Return true if the given buffer is in an indexed instrprof format. static bool hasFormat(const MemoryBuffer &DataBuffer); Index: llvm/include/llvm/ProfileData/InstrProfWriter.h =================================================================== --- llvm/include/llvm/ProfileData/InstrProfWriter.h +++ llvm/include/llvm/ProfileData/InstrProfWriter.h @@ -40,11 +40,12 @@ bool Sparse; StringMap FunctionData; ProfKind ProfileKind = PF_Unknown; + bool InstrEntryBBEnabled; // Use raw pointer here for the incomplete type object. InstrProfRecordWriterTrait *InfoObj; public: - InstrProfWriter(bool Sparse = false); + InstrProfWriter(bool Sparse = false, bool InstrEntryBBEnabled = false); ~InstrProfWriter(); /// Add function counts for the given function. If there are already counts @@ -97,6 +98,7 @@ return Error::success(); } + void setInstrEntryBBEnabled(bool Enabled) { InstrEntryBBEnabled = Enabled; } // Internal interface for testing purpose only. void setValueProfDataEndianness(support::endianness Endianness); void setOutputSparse(bool Sparse); Index: llvm/lib/ProfileData/InstrProf.cpp =================================================================== --- llvm/lib/ProfileData/InstrProf.cpp +++ llvm/lib/ProfileData/InstrProf.cpp @@ -1136,12 +1136,15 @@ // Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime // aware this is an ir_level profile so it can set the version flag. -void createIRLevelProfileFlagVar(Module &M, bool IsCS) { +void createIRLevelProfileFlagVar(Module &M, bool IsCS, + bool InstrEntryBBEnabled) { const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR)); Type *IntTy64 = Type::getInt64Ty(M.getContext()); uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF); if (IsCS) ProfileVersion |= VARIANT_MASK_CSIR_PROF; + if (InstrEntryBBEnabled) + ProfileVersion |= VARIANT_MASK_INSTR_ENTRY; auto IRLevelVersionVariable = new GlobalVariable( M, IntTy64, true, GlobalValue::WeakAnyLinkage, Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName); Index: llvm/lib/ProfileData/InstrProfReader.cpp =================================================================== --- llvm/lib/ProfileData/InstrProfReader.cpp +++ llvm/lib/ProfileData/InstrProfReader.cpp @@ -154,23 +154,29 @@ Error TextInstrProfReader::readHeader() { Symtab.reset(new InstrProfSymtab()); bool IsIRInstr = false; - if (!Line->startswith(":")) { - IsIRLevelProfile = false; - return success(); + bool IsEntryFirst = false; + bool IsCS = false; + + while (Line->startswith(":")) { + StringRef Str = Line->substr(1); + if (Str.equals_lower("ir")) + IsIRInstr = true; + else if (Str.equals_lower("fe")) + IsIRInstr = false; + else if (Str.equals_lower("csir")) { + IsIRInstr = true; + IsCS = true; + } else if (Str.equals_lower("entry_first")) + IsEntryFirst = true; + else if (Str.equals_lower("not_entry_first")) + IsEntryFirst = false; + else + return error(instrprof_error::bad_header); + ++Line; } - StringRef Str = (Line)->substr(1); - if (Str.equals_lower("ir")) - IsIRInstr = true; - else if (Str.equals_lower("fe")) - IsIRInstr = false; - else if (Str.equals_lower("csir")) { - IsIRInstr = true; - HasCSIRLevelProfile = true; - } else - return error(instrprof_error::bad_header); - - ++Line; IsIRLevelProfile = IsIRInstr; + InstrEntryBBEnabled = IsEntryFirst; + HasCSIRLevelProfile = IsCS; return success(); } Index: llvm/lib/ProfileData/InstrProfWriter.cpp =================================================================== --- llvm/lib/ProfileData/InstrProfWriter.cpp +++ llvm/lib/ProfileData/InstrProfWriter.cpp @@ -165,8 +165,9 @@ } // end namespace llvm -InstrProfWriter::InstrProfWriter(bool Sparse) - : Sparse(Sparse), InfoObj(new InstrProfRecordWriterTrait()) {} +InstrProfWriter::InstrProfWriter(bool Sparse, bool InstrEntryBBEnabled) + : Sparse(Sparse), InstrEntryBBEnabled(InstrEntryBBEnabled), + InfoObj(new InstrProfRecordWriterTrait()) {} InstrProfWriter::~InstrProfWriter() { delete InfoObj; } @@ -308,6 +309,9 @@ Header.Version |= VARIANT_MASK_IR_PROF; Header.Version |= VARIANT_MASK_CSIR_PROF; } + if (InstrEntryBBEnabled) + Header.Version |= VARIANT_MASK_INSTR_ENTRY; + Header.Unused = 0; Header.HashType = static_cast(IndexedInstrProf::HashType); Header.HashOffset = 0; @@ -441,6 +445,8 @@ OS << "# IR level Instrumentation Flag\n:ir\n"; else if (ProfileKind == PF_IRLevelWithCS) OS << "# CSIR level Instrumentation Flag\n:csir\n"; + if (InstrEntryBBEnabled) + OS << "# Always instrument the function entry block\n:entry_first\n"; InstrProfSymtab Symtab; using FuncPair = detail::DenseMapPair; Index: llvm/lib/Transforms/Instrumentation/CFGMST.h =================================================================== --- llvm/lib/Transforms/Instrumentation/CFGMST.h +++ llvm/lib/Transforms/Instrumentation/CFGMST.h @@ -20,7 +20,6 @@ #include "llvm/Analysis/BranchProbabilityInfo.h" #include "llvm/Analysis/CFG.h" #include "llvm/Support/BranchProbability.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -30,9 +29,6 @@ #define DEBUG_TYPE "cfgmst" using namespace llvm; -static cl::opt PGOInstrumentEntry( - "pgo-instrument-entry", cl::init(false), cl::Hidden, - cl::desc("Force to instrument function entry basicblock.")); namespace llvm { @@ -107,7 +103,7 @@ const BasicBlock *Entry = &(F.getEntryBlock()); uint64_t EntryWeight = (BFI != nullptr ? BFI->getEntryFreq() : 2); // If we want to instrument the entry count, lower the weight to 0. - if (PGOInstrumentEntry) + if (InstrumentFuncEntry) EntryWeight = 0; Edge *EntryIncoming = nullptr, *EntryOutgoing = nullptr, *ExitOutgoing = nullptr, *ExitIncoming = nullptr; @@ -282,14 +278,19 @@ BranchProbabilityInfo *BPI; BlockFrequencyInfo *BFI; + // If function entry will be always instrumented. + bool InstrumentFuncEntry; + public: - CFGMST(Function &Func, BranchProbabilityInfo *BPI_ = nullptr, + CFGMST(Function &Func, bool InstrumentFuncEntry_, + BranchProbabilityInfo *BPI_ = nullptr, BlockFrequencyInfo *BFI_ = nullptr) - : F(Func), BPI(BPI_), BFI(BFI_) { + : F(Func), BPI(BPI_), BFI(BFI_), + InstrumentFuncEntry(InstrumentFuncEntry_) { buildEdges(); sortEdgesByWeight(); computeMinimumSpanningTree(); - if (PGOInstrumentEntry && (AllEdges.size() > 1)) + if (AllEdges.size() > 1 && InstrumentFuncEntry) std::iter_swap(std::move(AllEdges.begin()), std::move(AllEdges.begin() + AllEdges.size() - 1)); } Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -249,6 +249,10 @@ "optimization remarks: -{Rpass|" "pass-remarks}=pgo-instrumentation")); +static cl::opt PGOInstrumentEntry( + "pgo-instrument-entry", cl::init(false), cl::Hidden, + cl::desc("Force to instrument function entry basicblock.")); + // Command line option to turn on CFG dot dump after profile annotation. // Defined in Analysis/BlockFrequencyInfo.cpp: -pgo-view-counts extern cl::opt PGOViewCounts; @@ -425,7 +429,7 @@ private: bool runOnModule(Module &M) override { createProfileFileNameVar(M, InstrProfileOutput); - createIRLevelProfileFlagVar(M, true); + createIRLevelProfileFlagVar(M, /* IsCS */ true, PGOInstrumentEntry); return false; } std::string InstrProfileOutput; @@ -528,6 +532,9 @@ // Is this is context-sensitive instrumentation. bool IsCS; + // If we instrument function entry BB by default. + bool InstrumentFuncEntry; + // A map that stores the Comdat group in function F. std::unordered_multimap &ComdatMembers; @@ -572,9 +579,11 @@ Function &Func, TargetLibraryInfo &TLI, std::unordered_multimap &ComdatMembers, bool CreateGlobalVar = false, BranchProbabilityInfo *BPI = nullptr, - BlockFrequencyInfo *BFI = nullptr, bool IsCS = false) + BlockFrequencyInfo *BFI = nullptr, bool IsCS = false, + bool InstrumentFuncEntry = true) : F(Func), IsCS(IsCS), ComdatMembers(ComdatMembers), VPC(Func, TLI), - ValueSites(IPVK_Last + 1), SIVisitor(Func), MST(F, BPI, BFI) { + ValueSites(IPVK_Last + 1), SIVisitor(Func), + MST(F, InstrumentFuncEntry, BPI, BFI) { // This should be done before CFG hash computation. SIVisitor.countSelects(Func); ValueSites[IPVK_MemOPSize] = VPC.get(IPVK_MemOPSize); @@ -845,8 +854,8 @@ // later in getInstrBB() to avoid invalidating it. SplitIndirectBrCriticalEdges(F, BPI, BFI); - FuncPGOInstrumentation FuncInfo(F, TLI, ComdatMembers, true, - BPI, BFI, IsCS); + FuncPGOInstrumentation FuncInfo( + F, TLI, ComdatMembers, true, BPI, BFI, IsCS, PGOInstrumentEntry); std::vector InstrumentBBs; FuncInfo.getInstrumentBBs(InstrumentBBs); unsigned NumCounters = @@ -1004,9 +1013,10 @@ PGOUseFunc(Function &Func, Module *Modu, TargetLibraryInfo &TLI, std::unordered_multimap &ComdatMembers, BranchProbabilityInfo *BPI, BlockFrequencyInfo *BFIin, - ProfileSummaryInfo *PSI, bool IsCS) + ProfileSummaryInfo *PSI, bool IsCS, bool InstrumentFuncEntry) : F(Func), M(Modu), BFI(BFIin), PSI(PSI), - FuncInfo(Func, TLI, ComdatMembers, false, BPI, BFIin, IsCS), + FuncInfo(Func, TLI, ComdatMembers, false, BPI, BFIin, IsCS, + InstrumentFuncEntry), FreqAttr(FFA_Normal), IsCS(IsCS) {} // Read counts for the instrumented BB from profile. @@ -1514,7 +1524,7 @@ // For the context-sensitve instrumentation, we should have a separated pass // (before LTO/ThinLTO linking) to create these variables. if (!IsCS) - createIRLevelProfileFlagVar(M, /* IsCS */ false); + createIRLevelProfileFlagVar(M, /* IsCS */ false, PGOInstrumentEntry); std::unordered_multimap ComdatMembers; collectComdatMembers(M, ComdatMembers); @@ -1532,7 +1542,7 @@ PreservedAnalyses PGOInstrumentationGenCreateVar::run(Module &M, ModuleAnalysisManager &AM) { createProfileFileNameVar(M, CSInstrName); - createIRLevelProfileFlagVar(M, /* IsCS */ true); + createIRLevelProfileFlagVar(M, /* IsCS */ true, PGOInstrumentEntry); return PreservedAnalyses::all(); } @@ -1619,6 +1629,12 @@ collectComdatMembers(M, ComdatMembers); std::vector HotFunctions; std::vector ColdFunctions; + + // If the profile marked as always instrument the entry BB, do the + // same. Note this can be overwritten by the internal option in CFGMST.h + bool InstrumentFuncEntry = PGOReader->instrEntryBBEnabled(); + if (PGOInstrumentEntry.getNumOccurrences() > 0) + InstrumentFuncEntry = PGOInstrumentEntry; for (auto &F : M) { if (F.isDeclaration()) continue; @@ -1628,7 +1644,8 @@ // Split indirectbr critical edges here before computing the MST rather than // later in getInstrBB() to avoid invalidating it. SplitIndirectBrCriticalEdges(F, BPI, BFI); - PGOUseFunc Func(F, &M, TLI, ComdatMembers, BPI, BFI, PSI, IsCS); + PGOUseFunc Func(F, &M, TLI, ComdatMembers, BPI, BFI, PSI, IsCS, + InstrumentFuncEntry); bool AllZeros = false; if (!Func.readCounters(PGOReader.get(), AllZeros)) continue; Index: llvm/test/Transforms/PGOProfile/Inputs/branch2_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/branch2_entry.proftext @@ -0,0 +1,9 @@ +# :ir is the flag to indicate this is IR level profile. +:ir +:entry_first +test_br_2 +29667547796 +2 +2 +1 + Index: llvm/test/Transforms/PGOProfile/Inputs/criticaledge_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/criticaledge_entry.proftext @@ -0,0 +1,20 @@ +# :ir is the flag to indicate this is IR level profile. +:ir +:entry_first +test_criticalEdge +82323253069 +8 +7 +2 +1 +2 +0 +1 +2 +1 + +:bar +12884901887 +1 +7 + Index: llvm/test/Transforms/PGOProfile/Inputs/func_entry.proftext =================================================================== --- llvm/test/Transforms/PGOProfile/Inputs/func_entry.proftext +++ llvm/test/Transforms/PGOProfile/Inputs/func_entry.proftext @@ -1,5 +1,6 @@ # IR level Instrumentation Flag :ir +:entry_first hot # Func Hash: 12884901887 Index: llvm/test/Transforms/PGOProfile/Inputs/indirectbr_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/indirectbr_entry.proftext @@ -0,0 +1,13 @@ +# IR level Instrumentation Flag +:ir +:entry_first +foo +# Func Hash: +47485104005 +# Num Counters: +4 +# Counter Values: +202 +20 +5 +63 Index: llvm/test/Transforms/PGOProfile/Inputs/irreducible_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/irreducible_entry.proftext @@ -0,0 +1,30 @@ +:ir +:entry_first +_Z11irreducibleii +# Func Hash: +64451410787 +# Num Counters: +6 +# Counter Values: +1 +1000 +950 +100 +373 +0 + +_Z11irreduciblePh +# Func Hash: +104649601521 +# Num Counters: +9 +# Counter Values: +1 +100 +300 +99 +300 +201 +1 +0 +0 Index: llvm/test/Transforms/PGOProfile/Inputs/landingpad_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/landingpad_entry.proftext @@ -0,0 +1,17 @@ +# :ir is the flag to indicate this is IR level profile. +:ir +:entry_first +foo +59130013419 +4 +5 +1 +2 +0 + +bar +24868915205 +2 +3 +2 + Index: llvm/test/Transforms/PGOProfile/Inputs/loop1_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/loop1_entry.proftext @@ -0,0 +1,9 @@ +# :ir is the flag to indicate this is IR level profile. +:ir +:entry_first +test_simple_for +34137660316 +2 +4 +96 + Index: llvm/test/Transforms/PGOProfile/Inputs/loop2_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/loop2_entry.proftext @@ -0,0 +1,10 @@ +# :ir is the flag to indicate this is IR level profile. +:ir +:entry_first +test_nested_for +53929068288 +3 +6 +33 +10 + Index: llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch_entry.proftext @@ -0,0 +1,39 @@ +# IR level Instrumentation Flag +:ir +:entry_first +bar +# Func Hash: +29667547796 +# Num Counters: +2 +# Counter Values: +2000000 +1600332 + +baz +# Func Hash: +12884901887 +# Num Counters: +1 +# Counter Values: +399668 + +foo +# Func Hash: +29212902728 +# Num Counters: +2 +# Counter Values: +40803991 +1600332 + +main +# Func Hash: +41605652536 +# Num Counters: +3 +# Counter Values: +2000000 +2000 +1 + Index: llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch-correct_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch-correct_entry.proftext @@ -0,0 +1,17 @@ +# IR level Instrumentation Flag +:ir +:entry_first +main +# Func Hash: +74054140268 +# Num Counters: +7 +# Counter Values: +1 +0 +0 +20000 +0 +0 +0 + Index: llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch_entry.proftext @@ -0,0 +1,17 @@ +# IR level Instrumentation Flag +:ir +:entry_first +main +# Func Hash: +74054140268 +# Num Counters: +7 +# Counter Values: +11889 +3973 +3970 +0 +8111 +1 +0 + Index: llvm/test/Transforms/PGOProfile/Inputs/select1.proftext =================================================================== --- llvm/test/Transforms/PGOProfile/Inputs/select1.proftext +++ llvm/test/Transforms/PGOProfile/Inputs/select1.proftext @@ -1,8 +1,9 @@ :ir +:entry_first test_br_2 72057623705475732 3 -4 +5 1 1 Index: llvm/test/Transforms/PGOProfile/Inputs/select2.proftext =================================================================== --- llvm/test/Transforms/PGOProfile/Inputs/select2.proftext +++ llvm/test/Transforms/PGOProfile/Inputs/select2.proftext @@ -1,11 +1,12 @@ # IR level Instrumentation Flag :ir +:entry_first foo # Func Hash: 72057628175588252 # Num Counters: 3 # Counter Values: -800 3 +800 300 Index: llvm/test/Transforms/PGOProfile/Inputs/switch_entry.proftext =================================================================== --- /dev/null +++ llvm/test/Transforms/PGOProfile/Inputs/switch_entry.proftext @@ -0,0 +1,11 @@ +# :ir is the flag to indicate this is IR level profile. +:ir +:entry_first +test_switch +46200943743 +4 +10 +5 +2 +3 + Index: llvm/test/Transforms/PGOProfile/branch2.ll =================================================================== --- llvm/test/Transforms/PGOProfile/branch2.ll +++ llvm/test/Transforms/PGOProfile/branch2.ll @@ -1,8 +1,14 @@ -; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN -; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY ; RUN: llvm-profdata merge %S/Inputs/branch2.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE + +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: llvm-profdata merge %S/Inputs/branch2_entry.proftext -o %t.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE 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" @@ -13,7 +19,8 @@ define i32 @test_br_2(i32 %i) { entry: ; GEN: entry: -; GEN-NOT: llvm.instrprof.increment +; NOTENTRY-NOT: llvm.instrprof.increment +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 29667547796, i32 2, i32 0) %cmp = icmp sgt i32 %i, 0 br i1 %cmp, label %if.then, label %if.else ; USE: br i1 %cmp, label %if.then, label %if.else @@ -22,7 +29,8 @@ if.then: ; GEN: if.then: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 29667547796, i32 2, i32 0) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 29667547796, i32 2, i32 0) +; ENTRY-NOT: llvm.instrprof.increment %add = add nsw i32 %i, 2 br label %if.end Index: llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll =================================================================== --- llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll +++ llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll @@ -2,8 +2,10 @@ ; compilation for loops that exit to a catchswitch block. In this case, counters ; do not get promoted out of the loop body. -; RUN: opt < %s -pgo-instr-gen -instrprof -do-counter-promotion=true -S | FileCheck %s -; RUN: opt < %s -passes=pgo-instr-gen,instrprof -do-counter-promotion=true -S | FileCheck %s +; RUN: opt < %s -pgo-instr-gen -instrprof -pgo-instrument-entry=false -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,NOTENTRY +; RUN: opt < %s -passes=pgo-instr-gen,instrprof -pgo-instrument-entry=false -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,NOTENTRY +; RUN: opt < %s -pgo-instr-gen -instrprof -pgo-instrument-entry=true -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,ENTRY +; RUN: opt < %s -passes=pgo-instr-gen,instrprof -pgo-instrument-entry=true -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,ENTRY ; Source used to create test: ; @@ -36,9 +38,11 @@ for.body: ; preds = %for.cond ; CHECK: for.body: -; CHECK: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0) +; NOTENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0) +; TENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) ; CHECK: %1 = add i64 %pgocount1, 1 -; CHECK: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0) +; NOTENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0) +; ENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) %idxprom = zext i32 %i.0 to i64 %arrayidx = getelementptr inbounds [200 x i8], [200 x i8]* @"?buffer@@3PADA", i64 0, i64 %idxprom %0 = load i8, i8* %arrayidx, align 1 @@ -51,9 +55,11 @@ for.inc: ; preds = %if.end ; CHECK: for.inc: -; CHECK: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) +; NOTENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) +; ENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 2) ; CHECK: %3 = add i64 %pgocount2, 1 -; CHECK: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) +; NOTENTRY: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) +; ENTRY: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 2) %inc = add nuw nsw i32 %i.0, 1 br label %for.cond Index: llvm/test/Transforms/PGOProfile/criticaledge.ll =================================================================== --- llvm/test/Transforms/PGOProfile/criticaledge.ll +++ llvm/test/Transforms/PGOProfile/criticaledge.ll @@ -1,8 +1,14 @@ -; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN -; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefix=GEN ; RUN: llvm-profdata merge %S/Inputs/criticaledge.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefix=GEN +; RUN: llvm-profdata merge %S/Inputs/criticaledge_entry.proftext -o %t2.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE 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" @@ -14,7 +20,8 @@ define i32 @test_criticalEdge(i32 %i, i32 %j) { entry: ; CHECK: entry: -; GEN-NOT: call void @llvm.instrprof.increment +; NOTENTRY-NOT: call void @llvm.instrprof.increment +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 0) switch i32 %i, label %sw.default [ i32 1, label %sw.bb i32 2, label %sw.bb1 @@ -28,11 +35,13 @@ ; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]] ; CHECK: entry.sw.bb2_crit_edge1: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 1) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 1) +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 2) ; CHECK: br label %sw.bb2 ; CHECK: entry.sw.bb2_crit_edge: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 0) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 0) +; TENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 1) ; CHECK: br label %sw.bb2 sw.bb: @@ -57,7 +66,8 @@ if.then: ; GEN: if.then: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 2) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 2) +; ENTRY-NOT: call void @llvm.instrprof.increment %call4 = call i32 @bar(i32 4) br label %return Index: llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll =================================================================== --- llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll +++ llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll @@ -1,8 +1,8 @@ ; Test the profile summary for context sensitive PGO (CSPGO) ; RUN: llvm-profdata merge %S/Inputs/cspgo.proftext -o %t.profdata -; RUN: opt < %s -O2 -disable-preinline -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S | FileCheck %s --check-prefix=PGOSUMMARY -; RUN: opt < %s -O2 -disable-preinline -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S -cspgo-kind=cspgo-instr-use-pipeline| FileCheck %s --check-prefix=CSPGOSUMMARY +; RUN: opt < %s -O2 -disable-preinline -pgo-instrument-entry=false -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S | FileCheck %s --check-prefix=PGOSUMMARY +; RUN: opt < %s -O2 -disable-preinline -pgo-instrument-entry=false -pgo-kind=pgo-instr-use-pipeline -profile-file=%t.profdata -S -cspgo-kind=cspgo-instr-use-pipeline| FileCheck %s --check-prefix=CSPGOSUMMARY 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" Index: llvm/test/Transforms/PGOProfile/indirectbr.ll =================================================================== --- llvm/test/Transforms/PGOProfile/indirectbr.ll +++ llvm/test/Transforms/PGOProfile/indirectbr.ll @@ -1,8 +1,13 @@ ; RUN: llvm-profdata merge %S/Inputs/indirectbr.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE ; New PM -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | opt -S -analyze -branch-prob | FileCheck %s --check-prefix=BRANCHPROB +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | opt -S -analyze -branch-prob | FileCheck %s --check-prefix=BRANCHPROB +; RUN: llvm-profdata merge %S/Inputs/indirectbr_entry.proftext -o %t2.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE +; New PM +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | opt -S -analyze -branch-prob | FileCheck %s --check-prefix=BRANCHPROB 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" Index: llvm/test/Transforms/PGOProfile/irreducible.ll =================================================================== --- llvm/test/Transforms/PGOProfile/irreducible.ll +++ llvm/test/Transforms/PGOProfile/irreducible.ll @@ -1,6 +1,9 @@ ; RUN: llvm-profdata merge %S/Inputs/irreducible.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: llvm-profdata merge %S/Inputs/irreducible_entry.proftext -o %t2.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE ; GEN: $__llvm_profile_raw_version = comdat any Index: llvm/test/Transforms/PGOProfile/landingpad.ll =================================================================== --- llvm/test/Transforms/PGOProfile/landingpad.ll +++ llvm/test/Transforms/PGOProfile/landingpad.ll @@ -1,8 +1,14 @@ -; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN -; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY ; RUN: llvm-profdata merge %S/Inputs/landingpad.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: llvm-profdata merge %S/Inputs/landingpad_entry.proftext -o %t2.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE 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" @@ -46,7 +52,8 @@ define i32 @foo(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { entry: ; GEN: entry: -; GEN-NOT: call void @llvm.instrprof.increment +; NOTENTRY-NOT: call void @llvm.instrprof.increment +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 0) %rem = srem i32 %i, 2 %tobool = icmp ne i32 %rem, 0 br i1 %tobool, label %if.then, label %if.end @@ -102,7 +109,8 @@ if.end: ; GEN: if.end: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 0) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 0) +; ENTRY-NOT: call void @llvm.instrprof.increment %tmp8 = load i32, i32* @val, align 4 %add = add nsw i32 %tmp8, %i store i32 %add, i32* @val, align 4 Index: llvm/test/Transforms/PGOProfile/loop1.ll =================================================================== --- llvm/test/Transforms/PGOProfile/loop1.ll +++ llvm/test/Transforms/PGOProfile/loop1.ll @@ -1,8 +1,14 @@ -; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN -; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY ; RUN: llvm-profdata merge %S/Inputs/loop1.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: llvm-profdata merge %S/Inputs/loop1_entry.proftext -o %t.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE + 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" @@ -13,7 +19,8 @@ define i32 @test_simple_for(i32 %n) { entry: ; GEN: entry: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_simple_for, i32 0, i32 0), i64 34137660316, i32 2, i32 1) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_simple_for, i32 0, i32 0), i64 34137660316, i32 2, i32 1) +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_simple_for, i32 0, i32 0), i64 34137660316, i32 2, i32 0) br label %for.cond for.cond: @@ -35,7 +42,8 @@ for.inc: ; GEN: for.inc: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_simple_for, i32 0, i32 0), i64 34137660316, i32 2, i32 0) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_simple_for, i32 0, i32 0), i64 34137660316, i32 2, i32 0) +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_simple_for, i32 0, i32 0), i64 34137660316, i32 2, i32 1) %inc1 = add nsw i32 %i, 1 br label %for.cond Index: llvm/test/Transforms/PGOProfile/loop2.ll =================================================================== --- llvm/test/Transforms/PGOProfile/loop2.ll +++ llvm/test/Transforms/PGOProfile/loop2.ll @@ -1,8 +1,13 @@ -; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN -; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY ; RUN: llvm-profdata merge %S/Inputs/loop2.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: llvm-profdata merge %S/Inputs/loop2_entry.proftext -o %t.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE 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" @@ -13,7 +18,8 @@ define i32 @test_nested_for(i32 %r, i32 %s) { entry: ; GEN: entry: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 2) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 2) +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 0) br label %for.cond.outer for.cond.outer: @@ -49,7 +55,8 @@ for.inc.inner: ; GEN: for.inc.inner: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 0) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 0) +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 1) %inc.1 = add nsw i32 %j.0, 1 br label %for.cond.inner @@ -59,7 +66,8 @@ for.inc.outer: ; GEN: for.inc.outer: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 1) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 1) +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__profn_test_nested_for, i32 0, i32 0), i64 53929068288, i32 3, i32 2) %inc.2 = add nsw i32 %i.0, 1 br label %for.cond.outer Index: llvm/test/Transforms/PGOProfile/misexpect-branch-stripped.ll =================================================================== --- llvm/test/Transforms/PGOProfile/misexpect-branch-stripped.ll +++ llvm/test/Transforms/PGOProfile/misexpect-branch-stripped.ll @@ -1,20 +1,28 @@ - ; RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata - -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED ; New PM -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: llvm-profdata merge %S/Inputs/misexpect-branch_entry.proftext -o %t2.profdata +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; New PM +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED ; WARNING-DAG: warning: :0:0: 19.98% ; WARNING-NOT: remark: :0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions. Index: llvm/test/Transforms/PGOProfile/misexpect-branch.ll =================================================================== --- llvm/test/Transforms/PGOProfile/misexpect-branch.ll +++ llvm/test/Transforms/PGOProfile/misexpect-branch.ll @@ -1,19 +1,28 @@ - ; RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata - -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED ; New PM -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: llvm-profdata merge %S/Inputs/misexpect-branch_entry.proftext -o %t2.profdata +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED + +; New PM +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED ; WARNING-DAG: warning: misexpect-branch.c:22:0: 19.98% ; WARNING-NOT: remark: misexpect-branch.c:22:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 19.98% (399668 / 2000000) of profiled executions. Index: llvm/test/Transforms/PGOProfile/misexpect-switch-default.ll =================================================================== --- llvm/test/Transforms/PGOProfile/misexpect-switch-default.ll +++ llvm/test/Transforms/PGOProfile/misexpect-switch-default.ll @@ -1,16 +1,15 @@ - ; RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -lower-expect -pgo-instrument-entry=false -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -lower-expect -pgo-instrument-entry=false -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -lower-expect -pgo-instrument-entry=false -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -lower-expect -pgo-instrument-entry=false -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED ; New PM -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED ; WARNING-DAG: warning: :0:0: 0.00% ; WARNING-NOT: remark: :0:0: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 27943) of profiled executions. @@ -32,7 +31,6 @@ ; CHECK-DAG: !{!"misexpect", i64 0, i64 2000, i64 1} - ; ModuleID = 'misexpect-switch.c' source_filename = "misexpect-switch.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: llvm/test/Transforms/PGOProfile/misexpect-switch.ll =================================================================== --- llvm/test/Transforms/PGOProfile/misexpect-switch.ll +++ llvm/test/Transforms/PGOProfile/misexpect-switch.ll @@ -1,21 +1,36 @@ - ; RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata ; RUN: llvm-profdata merge %S/Inputs/misexpect-switch-correct.proftext -o %t.c.profdata -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED ; New PM -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED + +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.c.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=CORRECT +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=false -pgo-test-profile-file=%t.c.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=CORRECT -; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-test-profile-file=%t.c.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=CORRECT -; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-test-profile-file=%t.c.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=CORRECT +; RUN: llvm-profdata merge %S/Inputs/misexpect-switch_entry.proftext -o %t2.profdata +; RUN: llvm-profdata merge %S/Inputs/misexpect-switch-correct_entry.proftext -o %t2.c.profdata +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pgo-warn-misexpect 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED + +; New PM +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pgo-warn-misexpect -S 2>&1 | FileCheck %s --check-prefix=WARNING +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=REMARK +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=BOTH +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S 2>&1 | FileCheck %s --check-prefix=DISABLED + +; RUN: opt < %s -lower-expect -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.c.profdata -S -pgo-warn-misexpect -pass-remarks=misexpect 2>&1 | FileCheck %s --check-prefix=CORRECT +; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" -pgo-instrument-entry=true -pgo-test-profile-file=%t2.c.profdata -pgo-warn-misexpect -pass-remarks=misexpect -S 2>&1 | FileCheck %s --check-prefix=CORRECT ; WARNING-DAG: warning: misexpect-switch.c:26:5: 0.00% ; WARNING-NOT: remark: misexpect-switch.c:26:5: Potential performance regression from use of the llvm.expect intrinsic: Annotation was correct on 0.00% (0 / 8112) of profiled executions. @@ -35,8 +50,6 @@ ; CORRECT-NOT: remark: {{.*}} ; CHECK-DAG: !{!"misexpect", i64 0, i64 2000, i64 1} - - ; ModuleID = 'misexpect-switch.c' source_filename = "misexpect-switch.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: llvm/test/Transforms/PGOProfile/switch.ll =================================================================== --- llvm/test/Transforms/PGOProfile/switch.ll +++ llvm/test/Transforms/PGOProfile/switch.ll @@ -1,8 +1,13 @@ -; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN -; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY ; RUN: llvm-profdata merge %S/Inputs/switch.proftext -o %t.profdata -; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE -; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY +; RUN: llvm-profdata merge %S/Inputs/switch_entry.proftext -o %t.profdata +; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE +; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE 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" @@ -13,7 +18,8 @@ define void @test_switch(i32 %i) { entry: ; GEN: entry: -; GEN-NOT: call void @llvm.instrprof.increment +; NOTENTRY-NOT: call void @llvm.instrprof.increment +; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn_test_switch, i32 0, i32 0), i64 46200943743, i32 4, i32 0) switch i32 %i, label %sw.default [ i32 1, label %sw.bb i32 2, label %sw.bb1 @@ -30,7 +36,8 @@ sw.bb1: ; GEN: sw.bb1: -; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn_test_switch, i32 0, i32 0), i64 46200943743, i32 4, i32 0) +; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn_test_switch, i32 0, i32 0), i64 46200943743, i32 4, i32 0) +; ENTRY-NOT: call void @llvm.instrprof.increment br label %sw.epilog sw.bb2: Index: llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll =================================================================== --- llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll +++ llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll @@ -3,7 +3,7 @@ ; RUN: opt -module-summary %s -o %t1.bc ; RUN: opt -module-summary %S/Inputs/thinlto_cspgo_bar_use.ll -o %t2.bc ; RUN: llvm-profdata merge %S/Inputs/thinlto_cs.proftext -o %t3.profdata -; RUN: llvm-lto2 run -lto-cspgo-profile-file=%t3.profdata -save-temps -o %t %t1.bc %t2.bc \ +; RUN: llvm-lto2 run -lto-cspgo-profile-file=%t3.profdata -pgo-instrument-entry=false -save-temps -o %t %t1.bc %t2.bc \ ; RUN: -r=%t1.bc,foo,pl \ ; RUN: -r=%t1.bc,bar,l \ ; RUN: -r=%t1.bc,main,plx \ Index: llvm/tools/llvm-profdata/llvm-profdata.cpp =================================================================== --- llvm/tools/llvm-profdata/llvm-profdata.cpp +++ llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -251,6 +251,7 @@ Filename); return; } + WC->Writer.setInstrEntryBBEnabled(Reader->instrEntryBBEnabled()); for (auto &I : *Reader) { if (Remapper) @@ -977,8 +978,11 @@ if (TextFormat) return 0; std::unique_ptr PS(Builder.getSummary()); - OS << "Instrumentation level: " - << (Reader->isIRLevelProfile() ? "IR" : "Front-end") << "\n"; + bool IsIR = Reader->isIRLevelProfile(); + OS << "Instrumentation level: " << (IsIR ? "IR" : "Front-end"); + if (IsIR) + OS << " entry_first = " << Reader->instrEntryBBEnabled(); + OS << "\n"; if (ShowAllFunctions || !ShowFunction.empty()) OS << "Functions shown: " << ShownFunctions << "\n"; OS << "Total functions: " << PS->getNumFunctions() << "\n";