[llvm] r311254 - [ThinLTO] Fix ThinLTO crash

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 19 11:04:26 PDT 2017


Author: tejohnson
Date: Sat Aug 19 11:04:25 2017
New Revision: 311254

URL: http://llvm.org/viewvc/llvm-project?rev=311254&view=rev
Log:
[ThinLTO] Fix ThinLTO crash

Summary:
Follow up to fix in r311023, which fixed the case where the combined
index is written to disk. The same samplePGO logic exists for the
in-memory index when computing imports, so we need to filter out
GlobalVariable summaries there too.

Reviewers: davidxl

Subscribers: inglorion, llvm-commits

Differential Revision: https://reviews.llvm.org/D36919

Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
    llvm/trunk/test/Transforms/FunctionImport/Inputs/funcimport_var2.ll
    llvm/trunk/test/Transforms/FunctionImport/funcimport_var.ll

Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=311254&r1=311253&r2=311254&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Sat Aug 19 11:04:25 2017
@@ -129,6 +129,21 @@ selectCallee(const ModuleSummaryIndex &I
       CalleeSummaryList,
       [&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) {
         auto *GVSummary = SummaryPtr.get();
+        // For SamplePGO, in computeImportForFunction the OriginalId
+        // may have been used to locate the callee summary list (See
+        // comment there).
+        // The mapping from OriginalId to GUID may return a GUID
+        // that corresponds to a static variable. Filter it out here.
+        // This can happen when
+        // 1) There is a call to a library function which is not defined
+        // in the index.
+        // 2) There is a static variable with the  OriginalGUID identical
+        // to the GUID of the library function in 1);
+        // When this happens, the logic for SamplePGO kicks in and
+        // the static variable in 2) will be found, which needs to be
+        // filtered out.
+        if (GVSummary->getSummaryKind() == GlobalValueSummary::GlobalVarKind)
+          return false;
         if (GlobalValue::isInterposableLinkage(GVSummary->linkage()))
           // There is no point in importing these, we can't inline them
           return false;

Modified: llvm/trunk/test/Transforms/FunctionImport/Inputs/funcimport_var2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionImport/Inputs/funcimport_var2.ll?rev=311254&r1=311253&r2=311254&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionImport/Inputs/funcimport_var2.ll (original)
+++ llvm/trunk/test/Transforms/FunctionImport/Inputs/funcimport_var2.ll Sat Aug 19 11:04:25 2017
@@ -1,3 +1,6 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
 @link = internal global i32 0, align 4
 
 ; Function Attrs: norecurse nounwind readnone uwtable

Modified: llvm/trunk/test/Transforms/FunctionImport/funcimport_var.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionImport/funcimport_var.ll?rev=311254&r1=311253&r2=311254&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionImport/funcimport_var.ll (original)
+++ llvm/trunk/test/Transforms/FunctionImport/funcimport_var.ll Sat Aug 19 11:04:25 2017
@@ -4,6 +4,18 @@
 ; RUN: opt -module-summary %p/Inputs/funcimport_var2.ll -o %t2.bc
 ; RUN: llvm-lto -thinlto -thinlto-action=thinlink -o %t3 %t.bc %t2.bc
 ; RUN: llvm-lto -thinlto -thinlto-action=import -thinlto-index=%t3 %t.bc %t2.bc
+; RUN: llvm-lto -thinlto -thinlto-action=run %t.bc %t2.bc
+; RUN: llvm-nm %t.bc.thinlto.o | FileCheck %s
+; RUN: llvm-lto2 run %t.bc %t2.bc -o %t.out \
+; RUN:   -r %t.bc,_Z4LinkPKcS0_,plx \
+; RUN:   -r %t.bc,link,l \
+; RUN:   -r %t2.bc,get_link,plx
+; RUN: llvm-nm %t.out.0 | FileCheck %s
+; CHECK: U link
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
 define i32 @_Z4LinkPKcS0_(i8*, i8*) local_unnamed_addr  {
   %3 = tail call i32 @link(i8* %0, i8* %1) #2
   ret i32 %3




More information about the llvm-commits mailing list