diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp --- a/llvm/lib/IR/ModuleSummaryIndex.cpp +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -31,6 +31,12 @@ cl::Hidden, cl::desc("Propagate attributes in index")); +// FIXME: Enable again when thin link compile time regressions understood and +// addressed +static cl::opt ImportConstantsWithRefs( + "import-constants-with-refs", cl::init(false), cl::Hidden, + cl::desc("Import constant global variables with references")); + FunctionSummary FunctionSummary::ExternalNode = FunctionSummary::makeDummyFunctionSummary({}); @@ -221,8 +227,8 @@ // c) Link error (external declaration with internal definition). // However we do not promote objects referenced by writeonly GV // initializer by means of converting it to 'zeroinitializer' - return !GVS->isConstant() && !isReadOnly(GVS) && !isWriteOnly(GVS) && - GVS->refs().size(); + return !(ImportConstantsWithRefs && GVS->isConstant()) && + !isReadOnly(GVS) && !isWriteOnly(GVS) && GVS->refs().size(); }; auto *GVS = cast(S->getBaseObject()); diff --git a/llvm/test/ThinLTO/X86/import-constant.ll b/llvm/test/ThinLTO/X86/import-constant.ll --- a/llvm/test/ThinLTO/X86/import-constant.ll +++ b/llvm/test/ThinLTO/X86/import-constant.ll @@ -4,6 +4,7 @@ ; RUN: opt -thinlto-bc %s -o %t1.bc ; RUN: opt -thinlto-bc %p/Inputs/import-constant.ll -o %t2.bc ; RUN: llvm-lto2 run -save-temps %t1.bc %t2.bc -o %t-out \ +; RUN: -import-constants-with-refs \ ; RUN: -r=%t1.bc,main,plx \ ; RUN: -r=%t1.bc,_Z6getObjv,l \ ; RUN: -r=%t2.bc,_Z6getObjv,pl \ diff --git a/llvm/test/ThinLTO/X86/referenced_by_constant.ll b/llvm/test/ThinLTO/X86/referenced_by_constant.ll --- a/llvm/test/ThinLTO/X86/referenced_by_constant.ll +++ b/llvm/test/ThinLTO/X86/referenced_by_constant.ll @@ -7,14 +7,14 @@ ; referenced constant objects. There is stll a room for improvement: we ; can make a local copy of someglobal and someglobal2 because they are both ; 'unnamed_addr' constants. This should eventually be done as well. -; RUN: llvm-lto -thinlto-action=import %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORT +; RUN: llvm-lto -thinlto-action=import -import-constants-with-refs %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORT ; IMPORT: @someglobal.llvm.0 = available_externally hidden unnamed_addr constant i8* bitcast (void ()* @referencedbyglobal to i8*) ; IMPORT: @someglobal2.llvm.0 = available_externally hidden unnamed_addr constant i8* bitcast (void ()* @localreferencedbyglobal.llvm.0 to i8*) ; IMPORT: define available_externally void @bar() ; Check the export side: we currently only export bar(), which causes ; @someglobal and @someglobal2 to be promoted (see above). -; RUN: llvm-lto -thinlto-action=promote %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=EXPORT +; RUN: llvm-lto -thinlto-action=promote -import-constants-with-refs %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=EXPORT ; EXPORT: @someglobal.llvm.0 = hidden unnamed_addr constant ; EXPORT: @someglobal2.llvm.0 = hidden unnamed_addr constant ; EXPORT: define void @referencedbyglobal()