[llvm] r290610 - [ThinLTO] Fix "||" vs "|" mixup.

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 27 09:45:10 PST 2016


Author: tejohnson
Date: Tue Dec 27 11:45:09 2016
New Revision: 290610

URL: http://llvm.org/viewvc/llvm-project?rev=290610&view=rev
Log:
[ThinLTO] Fix "||" vs "|" mixup.

The effect of the bug was that we would incorrectly create summaries
for global and weak values defined in module asm (since we were
essentially testing for bit 1 which is SF_Undefined, and the
RecordStreamer ignores local undefined references). This would have
resulted in conservatively disabling importing of anything referencing
globals and weaks defined in module asm. Added these cases to the test
which now fails without this bug fix.

Fixes PR31459.

Modified:
    llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
    llvm/trunk/test/ThinLTO/X86/Inputs/module_asm2.ll
    llvm/trunk/test/ThinLTO/X86/module_asm2.ll

Modified: llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp?rev=290610&r1=290609&r2=290610&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp Tue Dec 27 11:45:09 2016
@@ -284,7 +284,7 @@ ModuleSummaryIndex llvm::buildModuleSumm
         Triple(M.getTargetTriple()), M.getModuleInlineAsm(),
         [&M, &Index](StringRef Name, object::BasicSymbolRef::Flags Flags) {
           // Symbols not marked as Weak or Global are local definitions.
-          if (Flags & (object::BasicSymbolRef::SF_Weak ||
+          if (Flags & (object::BasicSymbolRef::SF_Weak |
                        object::BasicSymbolRef::SF_Global))
             return;
           GlobalValue *GV = M.getNamedValue(Name);

Modified: llvm/trunk/test/ThinLTO/X86/Inputs/module_asm2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/module_asm2.ll?rev=290610&r1=290609&r2=290610&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/Inputs/module_asm2.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/Inputs/module_asm2.ll Tue Dec 27 11:45:09 2016
@@ -5,8 +5,12 @@ define i32 @main({ i64, { i64, i8* }* }
   %1 = call i32 @func1() #1
   %2 = call i32 @func2() #1
   %3 = call i32 @func3() #1
+  %4 = call i32 @callglobalfunc() #1
+  %5 = call i32 @callweakfunc() #1
   ret i32 %1
 }
 declare i32 @func1() #1
 declare i32 @func2() #1
 declare i32 @func3() #1
+declare i32 @callglobalfunc() #1
+declare i32 @callweakfunc() #1

Modified: llvm/trunk/test/ThinLTO/X86/module_asm2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/module_asm2.ll?rev=290610&r1=290609&r2=290610&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/module_asm2.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/module_asm2.ll Tue Dec 27 11:45:09 2016
@@ -4,47 +4,61 @@
 ; RUN: opt -module-summary %s -o %t1.bc
 ; RUN: opt -module-summary %p/Inputs/module_asm2.ll -o %t2.bc
 
-; RUN: llvm-lto -thinlto-action=run -exported-symbol=main -exported-symbol=func1 -exported-symbol=func2 -exported-symbol=func3 %t1.bc %t2.bc
-; RUN: llvm-nm %t1.bc.thinlto.o | FileCheck  %s --check-prefix=NM0
-; RUN: llvm-nm %t2.bc.thinlto.o | FileCheck  %s --check-prefix=NM1
+; RUN: llvm-lto -thinlto-action=run -exported-symbol=main -exported-symbol=func1 -exported-symbol=func2 -exported-symbol=func3 -exported-symbol=callglobalfunc -exported-symbol=callweakfunc %t1.bc %t2.bc
+; RUN:  llvm-nm %t1.bc.thinlto.o | FileCheck  %s --check-prefix=NM0
+; RUN:  llvm-nm %t2.bc.thinlto.o | FileCheck  %s --check-prefix=NM1
 
 ; RUN: llvm-lto2 %t1.bc %t2.bc -o %t.o -save-temps \
 ; RUN:     -r=%t1.bc,foo,plx \
+; RUN:     -r=%t1.bc,globalfunc,plx \
+; RUN:     -r=%t1.bc,globalfunc,plx \
+; RUN:     -r=%t1.bc,weakfunc,plx \
+; RUN:     -r=%t1.bc,weakfunc,plx \
 ; RUN:     -r=%t1.bc,b,pl \
 ; RUN:     -r=%t1.bc,x,pl \
 ; RUN:     -r=%t1.bc,func1,pl \
 ; RUN:     -r=%t1.bc,func2,pl \
 ; RUN:     -r=%t1.bc,func3,pl \
+; RUN:     -r=%t1.bc,callglobalfunc,plx \
+; RUN:     -r=%t1.bc,callweakfunc,plx \
 ; RUN:     -r=%t2.bc,main,plx \
 ; RUN:     -r=%t2.bc,func1,l \
 ; RUN:     -r=%t2.bc,func2,l \
-; RUN:     -r=%t2.bc,func3,l
+; RUN:     -r=%t2.bc,func3,l \
+; RUN:     -r=%t2.bc,callglobalfunc,l \
+; RUN:     -r=%t2.bc,callweakfunc,l
 ; RUN: llvm-nm %t.o.0 | FileCheck  %s --check-prefix=NM0
 ; RUN: llvm-nm %t.o.1 | FileCheck  %s --check-prefix=NM1
 
 ; Check that local values b and x, which are referenced on
 ; llvm.used and llvm.compiler.used, respectively, are not promoted.
 ; Similarly, foo which is defined in module level asm should not be
-; promoted. We have to check in the importing module, however, as we
-; don't currently generate a summary for values defined in module asm,
-; so they couldn't get promoted even if we exported a reference.
+; promoted.
 ; NM0-DAG: d b
 ; NM0-DAG: d x
 ; NM0-DAG: t foo
 ; NM0-DAG: T func1
 ; NM0-DAG: T func2
 ; NM0-DAG: T func3
+; NM0-DAG: T callglobalfunc
+; NM0-DAG: T callweakfunc
+; NM0-DAG: T globalfunc
+; NM0-DAG: W weakfunc
 
 ; Ensure that foo, b and x are likewise not exported (imported as refs
 ; into the other module), since they can't be promoted. Additionally,
 ; referencing functions func2 and func3 should not have been
-; imported.
+; imported. However, we should have been able to import callglobalfunc
+; and callweakfunc (leaving undefined symbols globalfunc and weakfunc)
+; since globalfunc and weakfunc were defined but not local in module asm.
 ; NM1-NOT: foo
 ; NM1-NOT: b
 ; NM1-NOT: x
 ; NM1-DAG: U func1
 ; NM1-DAG: U func2
 ; NM1-DAG: U func3
+; NM1-DAG: U globalfunc
+; NM1-DAG: U weakfunc
 ; NM1-DAG: T main
 ; NM1-NOT: foo
 ; NM1-NOT: b
@@ -67,8 +81,26 @@ module asm "\09movl    x, %edx"
 module asm "\09ret "
 module asm "\09.size\09foo, .-foo"
 module asm ""
+module asm "\09.globl\09globalfunc"
+module asm "\09.type\09globalfunc, at function"
+module asm "globalfunc:"
+module asm "\09movl    b, %eax"
+module asm "\09movl    x, %edx"
+module asm "\09ret "
+module asm "\09.size\09globalfunc, .-globalfunc"
+module asm ""
+module asm "\09.weak\09weakfunc"
+module asm "\09.type\09weakfunc, at function"
+module asm "weakfunc:"
+module asm "\09movl    b, %eax"
+module asm "\09movl    x, %edx"
+module asm "\09ret "
+module asm "\09.size\09weakfunc, .-weakfunc"
+module asm ""
 
 declare i16 @foo() #0
+declare i16 @globalfunc() #0
+declare i16 @weakfunc() #0
 
 define i32 @func1() #1 {
   call i16 @foo()
@@ -84,3 +116,13 @@ define i32 @func3() #1 {
   %1 = load i32, i32* @x, align 4
   ret i32 %1
 }
+
+define i32 @callglobalfunc() #1 {
+  call i16 @globalfunc()
+  ret i32 1
+}
+
+define i32 @callweakfunc() #1 {
+  call i16 @weakfunc()
+  ret i32 1
+}




More information about the llvm-commits mailing list