Index: lib/Transforms/IPO/SampleProfile.cpp =================================================================== --- lib/Transforms/IPO/SampleProfile.cpp +++ lib/Transforms/IPO/SampleProfile.cpp @@ -1315,7 +1315,8 @@ clearFunctionData(); retval |= runOnFunction(F); } - M.setProfileSummary(Reader->getSummary().getMD(M.getContext())); + if (M.getProfileSummary() == nullptr) + M.setProfileSummary(Reader->getSummary().getMD(M.getContext())); return retval; } Index: test/Transforms/SampleProfile/summary.ll =================================================================== --- test/Transforms/SampleProfile/summary.ll +++ test/Transforms/SampleProfile/summary.ll @@ -1,5 +1,6 @@ ; Test that we annotate entire program's summary to IR. ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | FileCheck %s +; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | opt -sample-profile -sample-profile-file=%S/Inputs/summary.prof -S | FileCheck %s define i32 @bar() #0 !dbg !1 { entry: