From 820cc01d1e65f7be7c3c27bcdcb6b8c13f4ec2e6 Mon Sep 17 00:00:00 2001 From: Eugene Leviant Date: Fri, 5 Jul 2019 12:00:10 +0000 Subject: [ThinLTO] Attempt to recommit r365040 after caching fix It's possible that some function can load and store the same variable using the same constant expression: store %Derived* @foo, %Derived** bitcast (%Base** @bar to %Derived**) %42 = load %Derived*, %Derived** bitcast (%Base** @bar to %Derived**) The bitcast expression was mistakenly cached while processing loads, and never examined later when processing store. This caused @bar to be mistakenly treated as read-only variable. See load-store-caching.ll. llvm-svn: 365188 --- llvm/lib/LTO/LTO.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'llvm/lib/LTO') diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 4ed13701aa9..64506890956 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -192,8 +192,10 @@ void llvm::computeLTOCacheKey( AddUnsigned(VI.isDSOLocal()); AddUsedCfiGlobal(VI.getGUID()); } - if (auto *GVS = dyn_cast(GS)) - AddUnsigned(GVS->isReadOnly()); + if (auto *GVS = dyn_cast(GS)) { + AddUnsigned(GVS->maybeReadOnly()); + AddUnsigned(GVS->maybeWriteOnly()); + } if (auto *FS = dyn_cast(GS)) { for (auto &TT : FS->type_tests()) UsedTypeIds.insert(TT); @@ -371,9 +373,9 @@ void llvm::thinLTOResolvePrevailingInIndex( GUIDPreservedSymbols); } -static bool isWeakWriteableObject(GlobalValueSummary *GVS) { +static bool isWeakObjectWithRWAccess(GlobalValueSummary *GVS) { if (auto *VarSummary = dyn_cast(GVS->getBaseObject())) - return !VarSummary->isReadOnly() && + return !VarSummary->maybeReadOnly() && !VarSummary->maybeWriteOnly() && (VarSummary->linkage() == GlobalValue::WeakODRLinkage || VarSummary->linkage() == GlobalValue::LinkOnceODRLinkage); return false; @@ -394,11 +396,12 @@ static void thinLTOInternalizeAndPromoteGUID( // We can't internalize available_externally globals because this // can break function pointer equality. S->linkage() != GlobalValue::AvailableExternallyLinkage && - // Functions and read-only variables with linkonce_odr and weak_odr - // linkage can be internalized. We can't internalize linkonce_odr - // and weak_odr variables which are modified somewhere in the - // program because reads and writes will become inconsistent. - !isWeakWriteableObject(S.get())) + // Functions and read-only variables with linkonce_odr and + // weak_odr linkage can be internalized. We can't internalize + // linkonce_odr and weak_odr variables which are both modified + // and read somewhere in the program because reads and writes + // will become inconsistent. + !isWeakObjectWithRWAccess(S.get())) S->setLinkage(GlobalValue::InternalLinkage); } } -- cgit v1.2.3